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