In the request_key() upcall mechanism there's a dependency loop by which if a key type driver overrides the ->request_key hook and the userspace side manages to lose the authorisation key, the auth key and the internal construction record (struct key_construction) can keep each other pinned. Fix this by the following changes: (1) Killing off the construction record and using the auth key instead. (2) Including the operation name in the auth key payload and making the payload available outside of security/keys/. (3) The ->request_key hook is given the authkey instead of the cons record and operation name. Changes (2) and (3) allow the auth key to naturally be cleaned up if the keyring it is in is destroyed or cleared or the auth key is unlinked.
Showing the changes to include/linux (1 of 8 files). Show all
Unified · Split
| @@ -20,15 +20,6 @@ · 19 unmodified lines | ||
| 20 | 20 | struct kernel_pkey_query; |
| 21 | 21 | struct kernel_pkey_params; |
| 22 | 22 | |
| 23 | −/* | |
| 24 | − * key under-construction record | |
| 25 | − * - passed to the request_key actor if supplied | |
| 26 | − */ | |
| 27 | −struct key_construction { | |
| 28 | − struct key *key; /* key being constructed */ | |
| 29 | − struct key *authkey;/* authorisation for key being constructed */ | |
| 30 | −}; | |
| 31 | − | |
| 32 | 23 | /* |
| 33 | 24 | * Pre-parsed payload, used by key add, update and instantiate. |
| 34 | 25 | * |
| @@ -50,8 +41,7 @@ struct key_preparsed_payload { · 15 unmodified lines | ||
| 50 | 41 | time64_t expiry; /* Expiry time of key */ |
| 51 | 42 | } __randomize_layout; |
| 52 | 43 | |
| 53 | −typedef int (*request_key_actor_t)(struct key_construction *key, | |
| 54 | − const char *op, void *aux); | |
| 44 | +typedef int (*request_key_actor_t)(struct key *auth_key, void *aux); | |
| 55 | 45 | |
| 56 | 46 | /* |
| 57 | 47 | * Preparsed matching criterion. |
| @@ -181,20 +171,20 @@ extern int key_instantiate_and_link(struct key *key, · 123 unmodified lines | ||
| 181 | 171 | const void *data, |
| 182 | 172 | size_t datalen, |
| 183 | 173 | struct key *keyring, |
| 184 | − struct key *instkey); | |
| 174 | + struct key *authkey); | |
| 185 | 175 | extern int key_reject_and_link(struct key *key, |
| 186 | 176 | unsigned timeout, |
| 187 | 177 | unsigned error, |
| 188 | 178 | struct key *keyring, |
| 189 | − struct key *instkey); | |
| 190 | −extern void complete_request_key(struct key_construction *cons, int error); | |
| 179 | + struct key *authkey); | |
| 180 | +extern void complete_request_key(struct key *authkey, int error); | |
| 191 | 181 | |
| 192 | 182 | static inline int key_negate_and_link(struct key *key, |
| 193 | 183 | unsigned timeout, |
| 194 | 184 | struct key *keyring, |
| 195 | − struct key *instkey) | |
| 185 | + struct key *authkey) | |
| 196 | 186 | { |
| 197 | − return key_reject_and_link(key, timeout, ENOKEY, keyring, instkey); | |
| 187 | + return key_reject_and_link(key, timeout, ENOKEY, keyring, authkey); | |
| 198 | 188 | } |
| 199 | 189 | |
| 200 | 190 | extern int generic_key_instantiate(struct key *key, struct key_preparsed_payload *prep); |