History

keys: Fix dependency loop between construction record and auth key

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.

David Howells committed 7 years ago

Commit 822ad641 parent bb2ba2d8 files · +100 −92Browse files

Showing the changes to include/linux (1 of 8 files). Show all

Unified · Split

include/linux/key-type.h+6−16
@@ -20,15 +20,6 @@ · 19 unmodified lines
20struct kernel_pkey_query;20struct kernel_pkey_query;
21struct kernel_pkey_params;21struct kernel_pkey_params;
22 22
23/*
24 * key under-construction record
25 * - passed to the request_key actor if supplied
26 */
27struct key_construction {
28 struct key *key; /* key being constructed */
29 struct key *authkey;/* authorisation for key being constructed */
30};
31
32/*23/*
33 * Pre-parsed payload, used by key add, update and instantiate.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 time64_t expiry; /* Expiry time of key */41 time64_t expiry; /* Expiry time of key */
51} __randomize_layout;42} __randomize_layout;
52 43
53typedef int (*request_key_actor_t)(struct key_construction *key,44typedef int (*request_key_actor_t)(struct key *auth_key, void *aux);
54 const char *op, void *aux);
55 45
56/*46/*
57 * Preparsed matching criterion.47 * Preparsed matching criterion.
@@ -181,20 +171,20 @@ extern int key_instantiate_and_link(struct key *key, · 123 unmodified lines
181 const void *data,171 const void *data,
182 size_t datalen,172 size_t datalen,
183 struct key *keyring,173 struct key *keyring,
184 struct key *instkey);174 struct key *authkey);
185extern int key_reject_and_link(struct key *key,175extern int key_reject_and_link(struct key *key,
186 unsigned timeout,176 unsigned timeout,
187 unsigned error,177 unsigned error,
188 struct key *keyring,178 struct key *keyring,
189 struct key *instkey);179 struct key *authkey);
190extern void complete_request_key(struct key_construction *cons, int error);180extern void complete_request_key(struct key *authkey, int error);
191 181
192static inline int key_negate_and_link(struct key *key,182static inline int key_negate_and_link(struct key *key,
193 unsigned timeout,183 unsigned timeout,
194 struct key *keyring,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
200extern int generic_key_instantiate(struct key *key, struct key_preparsed_payload *prep);190extern int generic_key_instantiate(struct key *key, struct key_preparsed_payload *prep);

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t