David Howells | 973c9f4 | 2011-01-20 16:38:33 +0000 | [diff] [blame] | 1 | /* Request key authorisation token key definition. |
David Howells | 3e30148 | 2005-06-23 22:00:56 -0700 | [diff] [blame] | 2 | * |
| 3 | * Copyright (C) 2005 Red Hat, Inc. All Rights Reserved. |
| 4 | * Written by David Howells (dhowells@redhat.com) |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or |
| 7 | * modify it under the terms of the GNU General Public License |
| 8 | * as published by the Free Software Foundation; either version |
| 9 | * 2 of the License, or (at your option) any later version. |
David Howells | f1a9bad | 2005-10-07 15:04:52 +0100 | [diff] [blame] | 10 | * |
Kees Cook | 3db38ed | 2017-05-13 04:51:52 -0700 | [diff] [blame] | 11 | * See Documentation/security/keys/request-key.rst |
David Howells | 3e30148 | 2005-06-23 22:00:56 -0700 | [diff] [blame] | 12 | */ |
| 13 | |
David Howells | 3e30148 | 2005-06-23 22:00:56 -0700 | [diff] [blame] | 14 | #include <linux/sched.h> |
| 15 | #include <linux/err.h> |
| 16 | #include <linux/seq_file.h> |
Robert P. J. Day | fdb89bc | 2008-04-29 01:01:32 -0700 | [diff] [blame] | 17 | #include <linux/slab.h> |
Linus Torvalds | 7c0f6ba | 2016-12-24 11:46:01 -0800 | [diff] [blame] | 18 | #include <linux/uaccess.h> |
David Howells | 3e30148 | 2005-06-23 22:00:56 -0700 | [diff] [blame] | 19 | #include "internal.h" |
David Howells | 822ad64 | 2019-02-14 16:20:25 +0000 | [diff] [blame] | 20 | #include <keys/request_key_auth-type.h> |
David Howells | 3e30148 | 2005-06-23 22:00:56 -0700 | [diff] [blame] | 21 | |
David Howells | f1dcde9 | 2014-07-18 18:56:36 +0100 | [diff] [blame] | 22 | static int request_key_auth_preparse(struct key_preparsed_payload *); |
| 23 | static void request_key_auth_free_preparse(struct key_preparsed_payload *); |
David Howells | cf7f601 | 2012-09-13 13:06:29 +0100 | [diff] [blame] | 24 | static int request_key_auth_instantiate(struct key *, |
| 25 | struct key_preparsed_payload *); |
David Howells | 3e30148 | 2005-06-23 22:00:56 -0700 | [diff] [blame] | 26 | static void request_key_auth_describe(const struct key *, struct seq_file *); |
David Howells | 04c567d | 2006-06-22 14:47:18 -0700 | [diff] [blame] | 27 | static void request_key_auth_revoke(struct key *); |
David Howells | 3e30148 | 2005-06-23 22:00:56 -0700 | [diff] [blame] | 28 | static void request_key_auth_destroy(struct key *); |
David Howells | b5f545c | 2006-01-08 01:02:47 -0800 | [diff] [blame] | 29 | static long request_key_auth_read(const struct key *, char __user *, size_t); |
David Howells | 3e30148 | 2005-06-23 22:00:56 -0700 | [diff] [blame] | 30 | |
| 31 | /* |
David Howells | 973c9f4 | 2011-01-20 16:38:33 +0000 | [diff] [blame] | 32 | * The request-key authorisation key type definition. |
David Howells | 3e30148 | 2005-06-23 22:00:56 -0700 | [diff] [blame] | 33 | */ |
| 34 | struct key_type key_type_request_key_auth = { |
| 35 | .name = ".request_key_auth", |
| 36 | .def_datalen = sizeof(struct request_key_auth), |
David Howells | f1dcde9 | 2014-07-18 18:56:36 +0100 | [diff] [blame] | 37 | .preparse = request_key_auth_preparse, |
| 38 | .free_preparse = request_key_auth_free_preparse, |
David Howells | 3e30148 | 2005-06-23 22:00:56 -0700 | [diff] [blame] | 39 | .instantiate = request_key_auth_instantiate, |
| 40 | .describe = request_key_auth_describe, |
David Howells | 04c567d | 2006-06-22 14:47:18 -0700 | [diff] [blame] | 41 | .revoke = request_key_auth_revoke, |
David Howells | 3e30148 | 2005-06-23 22:00:56 -0700 | [diff] [blame] | 42 | .destroy = request_key_auth_destroy, |
David Howells | b5f545c | 2006-01-08 01:02:47 -0800 | [diff] [blame] | 43 | .read = request_key_auth_read, |
David Howells | 3e30148 | 2005-06-23 22:00:56 -0700 | [diff] [blame] | 44 | }; |
| 45 | |
David Howells | 8da79b6 | 2014-09-16 17:07:07 +0100 | [diff] [blame] | 46 | static int request_key_auth_preparse(struct key_preparsed_payload *prep) |
David Howells | f1dcde9 | 2014-07-18 18:56:36 +0100 | [diff] [blame] | 47 | { |
| 48 | return 0; |
| 49 | } |
| 50 | |
David Howells | 8da79b6 | 2014-09-16 17:07:07 +0100 | [diff] [blame] | 51 | static void request_key_auth_free_preparse(struct key_preparsed_payload *prep) |
David Howells | f1dcde9 | 2014-07-18 18:56:36 +0100 | [diff] [blame] | 52 | { |
| 53 | } |
| 54 | |
David Howells | 3e30148 | 2005-06-23 22:00:56 -0700 | [diff] [blame] | 55 | /* |
David Howells | 973c9f4 | 2011-01-20 16:38:33 +0000 | [diff] [blame] | 56 | * Instantiate a request-key authorisation key. |
David Howells | 3e30148 | 2005-06-23 22:00:56 -0700 | [diff] [blame] | 57 | */ |
| 58 | static int request_key_auth_instantiate(struct key *key, |
David Howells | cf7f601 | 2012-09-13 13:06:29 +0100 | [diff] [blame] | 59 | struct key_preparsed_payload *prep) |
David Howells | 3e30148 | 2005-06-23 22:00:56 -0700 | [diff] [blame] | 60 | { |
David Howells | e59428f | 2019-06-19 16:10:15 +0100 | [diff] [blame] | 61 | rcu_assign_keypointer(key, (struct request_key_auth *)prep->data); |
David Howells | b5f545c | 2006-01-08 01:02:47 -0800 | [diff] [blame] | 62 | return 0; |
David Howells | a8b17ed | 2011-01-20 16:38:27 +0000 | [diff] [blame] | 63 | } |
David Howells | 3e30148 | 2005-06-23 22:00:56 -0700 | [diff] [blame] | 64 | |
David Howells | 3e30148 | 2005-06-23 22:00:56 -0700 | [diff] [blame] | 65 | /* |
David Howells | 973c9f4 | 2011-01-20 16:38:33 +0000 | [diff] [blame] | 66 | * Describe an authorisation token. |
David Howells | 3e30148 | 2005-06-23 22:00:56 -0700 | [diff] [blame] | 67 | */ |
| 68 | static void request_key_auth_describe(const struct key *key, |
| 69 | struct seq_file *m) |
| 70 | { |
David Howells | e59428f | 2019-06-19 16:10:15 +0100 | [diff] [blame] | 71 | struct request_key_auth *rka = dereference_key_rcu(key); |
David Howells | 3e30148 | 2005-06-23 22:00:56 -0700 | [diff] [blame] | 72 | |
| 73 | seq_puts(m, "key:"); |
| 74 | seq_puts(m, key->description); |
David Howells | 363b02d | 2017-10-04 16:43:25 +0100 | [diff] [blame] | 75 | if (key_is_positive(key)) |
David Howells | 78b7280 | 2011-03-11 17:57:23 +0000 | [diff] [blame] | 76 | seq_printf(m, " pid:%d ci:%zu", rka->pid, rka->callout_len); |
David Howells | a8b17ed | 2011-01-20 16:38:27 +0000 | [diff] [blame] | 77 | } |
David Howells | 3e30148 | 2005-06-23 22:00:56 -0700 | [diff] [blame] | 78 | |
David Howells | 3e30148 | 2005-06-23 22:00:56 -0700 | [diff] [blame] | 79 | /* |
David Howells | 973c9f4 | 2011-01-20 16:38:33 +0000 | [diff] [blame] | 80 | * Read the callout_info data (retrieves the callout information). |
David Howells | b5f545c | 2006-01-08 01:02:47 -0800 | [diff] [blame] | 81 | * - the key's semaphore is read-locked |
| 82 | */ |
| 83 | static long request_key_auth_read(const struct key *key, |
| 84 | char __user *buffer, size_t buflen) |
| 85 | { |
David Howells | e59428f | 2019-06-19 16:10:15 +0100 | [diff] [blame] | 86 | struct request_key_auth *rka = dereference_key_locked(key); |
David Howells | b5f545c | 2006-01-08 01:02:47 -0800 | [diff] [blame] | 87 | size_t datalen; |
| 88 | long ret; |
| 89 | |
David Howells | 4a38e12 | 2008-04-29 01:01:24 -0700 | [diff] [blame] | 90 | datalen = rka->callout_len; |
David Howells | b5f545c | 2006-01-08 01:02:47 -0800 | [diff] [blame] | 91 | ret = datalen; |
| 92 | |
| 93 | /* we can return the data as is */ |
| 94 | if (buffer && buflen > 0) { |
| 95 | if (buflen > datalen) |
| 96 | buflen = datalen; |
| 97 | |
| 98 | if (copy_to_user(buffer, rka->callout_info, buflen) != 0) |
| 99 | ret = -EFAULT; |
| 100 | } |
| 101 | |
| 102 | return ret; |
David Howells | a8b17ed | 2011-01-20 16:38:27 +0000 | [diff] [blame] | 103 | } |
David Howells | b5f545c | 2006-01-08 01:02:47 -0800 | [diff] [blame] | 104 | |
Eric Biggers | 44d8143 | 2017-09-21 13:57:40 -0700 | [diff] [blame] | 105 | static void free_request_key_auth(struct request_key_auth *rka) |
| 106 | { |
| 107 | if (!rka) |
| 108 | return; |
| 109 | key_put(rka->target_key); |
| 110 | key_put(rka->dest_keyring); |
| 111 | if (rka->cred) |
| 112 | put_cred(rka->cred); |
| 113 | kfree(rka->callout_info); |
| 114 | kfree(rka); |
| 115 | } |
| 116 | |
David Howells | 04c567d | 2006-06-22 14:47:18 -0700 | [diff] [blame] | 117 | /* |
David Howells | e59428f | 2019-06-19 16:10:15 +0100 | [diff] [blame] | 118 | * Dispose of the request_key_auth record under RCU conditions |
| 119 | */ |
| 120 | static void request_key_auth_rcu_disposal(struct rcu_head *rcu) |
| 121 | { |
| 122 | struct request_key_auth *rka = |
| 123 | container_of(rcu, struct request_key_auth, rcu); |
| 124 | |
| 125 | free_request_key_auth(rka); |
| 126 | } |
| 127 | |
| 128 | /* |
| 129 | * Handle revocation of an authorisation token key. |
| 130 | * |
| 131 | * Called with the key sem write-locked. |
| 132 | */ |
| 133 | static void request_key_auth_revoke(struct key *key) |
| 134 | { |
| 135 | struct request_key_auth *rka = dereference_key_locked(key); |
| 136 | |
| 137 | kenter("{%d}", key->serial); |
| 138 | rcu_assign_keypointer(key, NULL); |
| 139 | call_rcu(&rka->rcu, request_key_auth_rcu_disposal); |
| 140 | } |
| 141 | |
| 142 | /* |
David Howells | 973c9f4 | 2011-01-20 16:38:33 +0000 | [diff] [blame] | 143 | * Destroy an instantiation authorisation token key. |
David Howells | 3e30148 | 2005-06-23 22:00:56 -0700 | [diff] [blame] | 144 | */ |
| 145 | static void request_key_auth_destroy(struct key *key) |
| 146 | { |
David Howells | e59428f | 2019-06-19 16:10:15 +0100 | [diff] [blame] | 147 | struct request_key_auth *rka = rcu_access_pointer(key->payload.rcu_data0); |
David Howells | 3e30148 | 2005-06-23 22:00:56 -0700 | [diff] [blame] | 148 | |
| 149 | kenter("{%d}", key->serial); |
David Howells | e59428f | 2019-06-19 16:10:15 +0100 | [diff] [blame] | 150 | if (rka) { |
| 151 | rcu_assign_keypointer(key, NULL); |
| 152 | call_rcu(&rka->rcu, request_key_auth_rcu_disposal); |
| 153 | } |
David Howells | a8b17ed | 2011-01-20 16:38:27 +0000 | [diff] [blame] | 154 | } |
David Howells | 3e30148 | 2005-06-23 22:00:56 -0700 | [diff] [blame] | 155 | |
David Howells | 3e30148 | 2005-06-23 22:00:56 -0700 | [diff] [blame] | 156 | /* |
David Howells | 973c9f4 | 2011-01-20 16:38:33 +0000 | [diff] [blame] | 157 | * Create an authorisation token for /sbin/request-key or whoever to gain |
| 158 | * access to the caller's security data. |
David Howells | 3e30148 | 2005-06-23 22:00:56 -0700 | [diff] [blame] | 159 | */ |
David Howells | 822ad64 | 2019-02-14 16:20:25 +0000 | [diff] [blame] | 160 | struct key *request_key_auth_new(struct key *target, const char *op, |
| 161 | const void *callout_info, size_t callout_len, |
| 162 | struct key *dest_keyring) |
David Howells | 3e30148 | 2005-06-23 22:00:56 -0700 | [diff] [blame] | 163 | { |
David Howells | b5f545c | 2006-01-08 01:02:47 -0800 | [diff] [blame] | 164 | struct request_key_auth *rka, *irka; |
David Howells | 7936d16 | 2019-05-22 14:09:29 +0100 | [diff] [blame] | 165 | const struct cred *cred = current_cred(); |
David Howells | b5f545c | 2006-01-08 01:02:47 -0800 | [diff] [blame] | 166 | struct key *authkey = NULL; |
David Howells | 3e30148 | 2005-06-23 22:00:56 -0700 | [diff] [blame] | 167 | char desc[20]; |
Eric Biggers | 44d8143 | 2017-09-21 13:57:40 -0700 | [diff] [blame] | 168 | int ret = -ENOMEM; |
David Howells | 3e30148 | 2005-06-23 22:00:56 -0700 | [diff] [blame] | 169 | |
| 170 | kenter("%d,", target->serial); |
| 171 | |
David Howells | b5f545c | 2006-01-08 01:02:47 -0800 | [diff] [blame] | 172 | /* allocate a auth record */ |
Eric Biggers | 44d8143 | 2017-09-21 13:57:40 -0700 | [diff] [blame] | 173 | rka = kzalloc(sizeof(*rka), GFP_KERNEL); |
| 174 | if (!rka) |
| 175 | goto error; |
Eric Biggers | e007ce9 | 2017-09-21 13:57:42 -0700 | [diff] [blame] | 176 | rka->callout_info = kmemdup(callout_info, callout_len, GFP_KERNEL); |
Eric Biggers | 44d8143 | 2017-09-21 13:57:40 -0700 | [diff] [blame] | 177 | if (!rka->callout_info) |
| 178 | goto error_free_rka; |
Eric Biggers | e007ce9 | 2017-09-21 13:57:42 -0700 | [diff] [blame] | 179 | rka->callout_len = callout_len; |
David Howells | 822ad64 | 2019-02-14 16:20:25 +0000 | [diff] [blame] | 180 | strlcpy(rka->op, op, sizeof(rka->op)); |
David Howells | 3e30148 | 2005-06-23 22:00:56 -0700 | [diff] [blame] | 181 | |
David Howells | b5f545c | 2006-01-08 01:02:47 -0800 | [diff] [blame] | 182 | /* see if the calling process is already servicing the key request of |
| 183 | * another process */ |
David Howells | d84f4f9 | 2008-11-14 10:39:23 +1100 | [diff] [blame] | 184 | if (cred->request_key_auth) { |
David Howells | b5f545c | 2006-01-08 01:02:47 -0800 | [diff] [blame] | 185 | /* it is - use that instantiation context here too */ |
David Howells | d84f4f9 | 2008-11-14 10:39:23 +1100 | [diff] [blame] | 186 | down_read(&cred->request_key_auth->sem); |
David Howells | 04c567d | 2006-06-22 14:47:18 -0700 | [diff] [blame] | 187 | |
| 188 | /* if the auth key has been revoked, then the key we're |
| 189 | * servicing is already instantiated */ |
Eric Biggers | 44d8143 | 2017-09-21 13:57:40 -0700 | [diff] [blame] | 190 | if (test_bit(KEY_FLAG_REVOKED, |
| 191 | &cred->request_key_auth->flags)) { |
| 192 | up_read(&cred->request_key_auth->sem); |
| 193 | ret = -EKEYREVOKED; |
| 194 | goto error_free_rka; |
| 195 | } |
David Howells | 04c567d | 2006-06-22 14:47:18 -0700 | [diff] [blame] | 196 | |
David Howells | 146aa8b | 2015-10-21 14:04:48 +0100 | [diff] [blame] | 197 | irka = cred->request_key_auth->payload.data[0]; |
David Howells | d84f4f9 | 2008-11-14 10:39:23 +1100 | [diff] [blame] | 198 | rka->cred = get_cred(irka->cred); |
David Howells | b5f545c | 2006-01-08 01:02:47 -0800 | [diff] [blame] | 199 | rka->pid = irka->pid; |
David Howells | 04c567d | 2006-06-22 14:47:18 -0700 | [diff] [blame] | 200 | |
David Howells | d84f4f9 | 2008-11-14 10:39:23 +1100 | [diff] [blame] | 201 | up_read(&cred->request_key_auth->sem); |
David Howells | b5f545c | 2006-01-08 01:02:47 -0800 | [diff] [blame] | 202 | } |
| 203 | else { |
| 204 | /* it isn't - use this process as the context */ |
David Howells | d84f4f9 | 2008-11-14 10:39:23 +1100 | [diff] [blame] | 205 | rka->cred = get_cred(cred); |
David Howells | b5f545c | 2006-01-08 01:02:47 -0800 | [diff] [blame] | 206 | rka->pid = current->pid; |
| 207 | } |
| 208 | |
| 209 | rka->target_key = key_get(target); |
David Howells | 8bbf4976 | 2008-11-14 10:39:14 +1100 | [diff] [blame] | 210 | rka->dest_keyring = key_get(dest_keyring); |
David Howells | b5f545c | 2006-01-08 01:02:47 -0800 | [diff] [blame] | 211 | |
David Howells | 3e30148 | 2005-06-23 22:00:56 -0700 | [diff] [blame] | 212 | /* allocate the auth key */ |
| 213 | sprintf(desc, "%x", target->serial); |
| 214 | |
David Howells | b5f545c | 2006-01-08 01:02:47 -0800 | [diff] [blame] | 215 | authkey = key_alloc(&key_type_request_key_auth, desc, |
David Howells | d84f4f9 | 2008-11-14 10:39:23 +1100 | [diff] [blame] | 216 | cred->fsuid, cred->fsgid, cred, |
David Howells | f7f1394 | 2019-05-20 21:51:43 +0100 | [diff] [blame] | 217 | KEY_POS_VIEW | KEY_POS_READ | KEY_POS_SEARCH | KEY_POS_LINK | |
David Howells | 5ac7eac | 2016-04-06 16:14:24 +0100 | [diff] [blame] | 218 | KEY_USR_VIEW, KEY_ALLOC_NOT_IN_QUOTA, NULL); |
David Howells | b5f545c | 2006-01-08 01:02:47 -0800 | [diff] [blame] | 219 | if (IS_ERR(authkey)) { |
| 220 | ret = PTR_ERR(authkey); |
Eric Biggers | 44d8143 | 2017-09-21 13:57:40 -0700 | [diff] [blame] | 221 | goto error_free_rka; |
David Howells | 3e30148 | 2005-06-23 22:00:56 -0700 | [diff] [blame] | 222 | } |
| 223 | |
David Howells | d84f4f9 | 2008-11-14 10:39:23 +1100 | [diff] [blame] | 224 | /* construct the auth key */ |
David Howells | b5f545c | 2006-01-08 01:02:47 -0800 | [diff] [blame] | 225 | ret = key_instantiate_and_link(authkey, rka, 0, NULL, NULL); |
| 226 | if (ret < 0) |
Eric Biggers | 44d8143 | 2017-09-21 13:57:40 -0700 | [diff] [blame] | 227 | goto error_put_authkey; |
David Howells | 3e30148 | 2005-06-23 22:00:56 -0700 | [diff] [blame] | 228 | |
Elena Reshetova | fff2929 | 2017-03-31 15:20:48 +0300 | [diff] [blame] | 229 | kleave(" = {%d,%d}", authkey->serial, refcount_read(&authkey->usage)); |
David Howells | b5f545c | 2006-01-08 01:02:47 -0800 | [diff] [blame] | 230 | return authkey; |
| 231 | |
Eric Biggers | 44d8143 | 2017-09-21 13:57:40 -0700 | [diff] [blame] | 232 | error_put_authkey: |
David Howells | b5f545c | 2006-01-08 01:02:47 -0800 | [diff] [blame] | 233 | key_put(authkey); |
Eric Biggers | 44d8143 | 2017-09-21 13:57:40 -0700 | [diff] [blame] | 234 | error_free_rka: |
| 235 | free_request_key_auth(rka); |
| 236 | error: |
David Howells | b5f545c | 2006-01-08 01:02:47 -0800 | [diff] [blame] | 237 | kleave("= %d", ret); |
| 238 | return ERR_PTR(ret); |
David Howells | a8b17ed | 2011-01-20 16:38:27 +0000 | [diff] [blame] | 239 | } |
David Howells | 3e30148 | 2005-06-23 22:00:56 -0700 | [diff] [blame] | 240 | |
David Howells | 3e30148 | 2005-06-23 22:00:56 -0700 | [diff] [blame] | 241 | /* |
David Howells | 973c9f4 | 2011-01-20 16:38:33 +0000 | [diff] [blame] | 242 | * Search the current process's keyrings for the authorisation key for |
| 243 | * instantiation of a key. |
David Howells | 3e30148 | 2005-06-23 22:00:56 -0700 | [diff] [blame] | 244 | */ |
| 245 | struct key *key_get_instantiation_authkey(key_serial_t target_id) |
| 246 | { |
David Howells | d0a059c | 2013-09-24 10:35:16 +0100 | [diff] [blame] | 247 | char description[16]; |
David Howells | 4bdf0bc | 2013-09-24 10:35:15 +0100 | [diff] [blame] | 248 | struct keyring_search_context ctx = { |
| 249 | .index_key.type = &key_type_request_key_auth, |
David Howells | d0a059c | 2013-09-24 10:35:16 +0100 | [diff] [blame] | 250 | .index_key.description = description, |
David Howells | 4bdf0bc | 2013-09-24 10:35:15 +0100 | [diff] [blame] | 251 | .cred = current_cred(), |
David Howells | c06cfb0 | 2014-09-16 17:36:06 +0100 | [diff] [blame] | 252 | .match_data.cmp = key_default_cmp, |
David Howells | 4629195 | 2014-09-16 17:36:02 +0100 | [diff] [blame] | 253 | .match_data.raw_data = description, |
| 254 | .match_data.lookup_type = KEYRING_SEARCH_LOOKUP_DIRECT, |
David Howells | dcf49db | 2019-06-26 21:02:32 +0100 | [diff] [blame^] | 255 | .flags = (KEYRING_SEARCH_DO_STATE_CHECK | |
| 256 | KEYRING_SEARCH_RECURSE), |
David Howells | 4bdf0bc | 2013-09-24 10:35:15 +0100 | [diff] [blame] | 257 | }; |
David Howells | b5f545c | 2006-01-08 01:02:47 -0800 | [diff] [blame] | 258 | struct key *authkey; |
| 259 | key_ref_t authkey_ref; |
David Howells | 3e30148 | 2005-06-23 22:00:56 -0700 | [diff] [blame] | 260 | |
Eric Biggers | ede0fa98 | 2019-02-22 15:36:18 +0000 | [diff] [blame] | 261 | ctx.index_key.desc_len = sprintf(description, "%x", target_id); |
David Howells | d0a059c | 2013-09-24 10:35:16 +0100 | [diff] [blame] | 262 | |
David Howells | e59428f | 2019-06-19 16:10:15 +0100 | [diff] [blame] | 263 | rcu_read_lock(); |
| 264 | authkey_ref = search_process_keyrings_rcu(&ctx); |
| 265 | rcu_read_unlock(); |
David Howells | 3e30148 | 2005-06-23 22:00:56 -0700 | [diff] [blame] | 266 | |
David Howells | b5f545c | 2006-01-08 01:02:47 -0800 | [diff] [blame] | 267 | if (IS_ERR(authkey_ref)) { |
David Howells | e231c2e | 2008-02-07 00:15:26 -0800 | [diff] [blame] | 268 | authkey = ERR_CAST(authkey_ref); |
David Howells | 4d67431 | 2011-06-13 22:33:52 +0100 | [diff] [blame] | 269 | if (authkey == ERR_PTR(-EAGAIN)) |
| 270 | authkey = ERR_PTR(-ENOKEY); |
David Howells | b5f545c | 2006-01-08 01:02:47 -0800 | [diff] [blame] | 271 | goto error; |
| 272 | } |
David Howells | 3e30148 | 2005-06-23 22:00:56 -0700 | [diff] [blame] | 273 | |
David Howells | b5f545c | 2006-01-08 01:02:47 -0800 | [diff] [blame] | 274 | authkey = key_ref_to_ptr(authkey_ref); |
| 275 | if (test_bit(KEY_FLAG_REVOKED, &authkey->flags)) { |
| 276 | key_put(authkey); |
| 277 | authkey = ERR_PTR(-EKEYREVOKED); |
| 278 | } |
David Howells | 3e30148 | 2005-06-23 22:00:56 -0700 | [diff] [blame] | 279 | |
David Howells | b5f545c | 2006-01-08 01:02:47 -0800 | [diff] [blame] | 280 | error: |
| 281 | return authkey; |
David Howells | a8b17ed | 2011-01-20 16:38:27 +0000 | [diff] [blame] | 282 | } |