Keys: Add possessor permissions to keys
Subsystems (3)
A message that is not in the archive (sent off-list or not yet received): [email protected]
David Howells
maintainerPATCH 1/1 Keys: Add possessor permissions to keys
The attached patch adds extra permission grants to keys for the possessor of a key in addition to the owner, group and other permissions bits. This makes SUID binaries easier to support without going as far as labelling keys and key targets using the LSM facilities.
This patch adds a second "pointer type" to key structures (struct key_ref *) that can have the bottom bit of the address set to indicate the possession of a key. This is propagated through searches from the keyring to the discovered key. It has been made a separate type so that the compiler can spot attempts to dereference a potentially incorrect pointer.
The "possession" attribute can't be attached to a key structure directly as it's not an intrinsic property of a key.
Pointers to keys have been replaced with struct key_ref *'s wherever possession information needs to be passed through.
This does assume that the bottom bit of the pointer will always be zero on return from kmem_cache_alloc().
---
warthog>diffstat -p1 keys-possess-2614rc1mm1.diff
Documentation/keys.txt | 64 ++++++++++---- include/linux/key-ui.h | 28 ++++-- include/linux/key.h | 59 +++++++++---- security/keys/internal.h | 28 +++--- security/keys/key.c | 82 ++++++++++-------- security/keys/keyctl.c | 172 +++++++++++++++++++-------------------- security/keys/keyring.c | 84 ++++++++++--------- security/keys/proc.c | 2 security/keys/process_keys.c | 101 +++++++++++++++------- security/keys/request_key.c | 36 ++++++-- security/keys/request_key_auth.c | 2 11 files changed, 401 insertions(+), 257 deletions(-)
Documentation/keys.txt +48 -16
@@ -195,8 +195,8 @@ KEY ACCESS PERMISSIONS ====================== Keys have an owner user ID, a group access ID, and a permissions mask. The mask -has up to eight bits each for user, group and other access. Only five of each -set of eight bits are defined. These permissions granted are: +has up to eight bits each for possessor, user, group and other access. Only +five of each set of eight bits are defined. These permissions granted are: (*) View
@@ -241,16 +241,16 @@ about the status of the key service: type, description and permissions. The payload of the key is not available this way: - SERIAL FLAGS USAGE EXPY PERM UID GID TYPE DESCRIPTION: SUMMARY - 00000001 I----- 39 perm 1f0000 0 0 keyring _uid_ses.0: 1/4 - 00000002 I----- 2 perm 1f0000 0 0 keyring _uid.0: empty - 00000007 I----- 1 perm 1f0000 0 0 keyring _pid.1: empty - 0000018d I----- 1 perm 1f0000 0 0 keyring _pid.412: empty - 000004d2 I--Q-- 1 perm 1f0000 32 -1 keyring _uid.32: 1/4 - 000004d3 I--Q-- 3 perm 1f0000 32 -1 keyring _uid_ses.32: empty - 00000892 I--QU- 1 perm 1f0000 0 0 user metal:copper: 0 - 00000893 I--Q-N 1 35s 1f0000 0 0 user metal:silver: 0 - 00000894 I--Q-- 1 10h 1f0000 0 0 user metal:gold: 0 + SERIAL FLAGS USAGE EXPY PERM UID GID TYPE DESCRIPTION: SUMMARY + 00000001 I----- 39 perm 1f1f0000 0 0 keyring _uid_ses.0: 1/4 + 00000002 I----- 2 perm 1f1f0000 0 0 keyring _uid.0: empty + 00000007 I----- 1 perm 1f1f0000 0 0 keyring _pid.1: empty + 0000018d I----- 1 perm 1f1f0000 0 0 keyring _pid.412: empty + 000004d2 I--Q-- 1 perm 1f1f0000 32 -1 keyring _uid.32: 1/4 + 000004d3 I--Q-- 3 perm 1f1f0000 32 -1 keyring _uid_ses.32: empty + 00000892 I--QU- 1 perm 1f000000 0 0 user metal:copper: 0 + 00000893 I--Q-N 1 35s 1f1f0000 0 0 user metal:silver: 0 + 00000894 I--Q-- 1 10h 001f0000 0 0 user metal:gold: 0 The flags are:
@@ -637,6 +637,34 @@ call, and the key released upon close. H two different users opening the same file is left to the filesystem author to solve. +Note that there are two different types of pointers to keys that may be +encountered: + + (*) struct key * + + This simply points to the key structure itself. Key structures will be at + least four-byte aligned. + + (*) struct key_ref * + + This is equivalent to a struct key *, but the least significant bit is set + if the caller "possesses" the key. By "possession" it is meant that the + calling processes has a searchable link to the key from one of its + keyrings. Their are three functions for dealing with these: + + struct key_ref *key_mkref(const struct key *key, + unsigned long possession); + + struct key *key_deref(const struct key_ref *key_ref); + + unsigned long is_key_possessed(const struct key_ref *key_ref); + + The first function constructs a key reference from a key pointer and + possession information (which must be 0 or 1 and no other value). + + The second function retrieves the key pointer and the third retrieves the + possession flag). + When accessing a key's payload contents, certain precautions must be taken to prevent access vs modification races. See the section "Notes on accessing payload contents" for more information.
@@ -689,14 +717,18 @@ payload contents" for more information. (*) If a keyring was found in the search, this can be further searched by: - struct key *keyring_search(struct key *keyring, - const struct key_type *type, - const char *description) + struct key_ref *keyring_search(struct key_ref *keyring, + const struct key_type *type, + const char *description) This searches the keyring tree specified for a matching key. Error ENOKEY is returned upon failure. If successful, the returned key will need to be released. + The possession attribute from the keyring reference pointer is used to + control access through the permissions mask and is propagated to the + returned key reference pointer if successful. + (*) To check the validity of a key, this function can be called:
@@ -732,7 +764,7 @@ More complex payload contents must be al key->payload.data. One of the following ways must be selected to access the data: - (1) Unmodifyable key type. + (1) Unmodifiable key type. If the key type does not have a modify method, then the key's payload can be accessed without any form of locking, provided that it's known to be
include/linux/key.h +44 -15
95 lines not on this page · raw message
include/linux/key-ui.h +19 -9
@@ -42,11 +42,14 @@ struct keyring_list {/* * check to see whether permission is granted to use a key in the desired way */ -static inline int key_permission (const struct key *key,key_perm_t perm) +static inline int key_permission (const struct key_ref *key_ref,key_perm_t perm) { +struct key *key =key_deref (key_ref);key_perm_t kperm; -if (key->uid == current->fsuid) +if (is_key_possessed (key_ref)) + kperm = key->perm >>24 ; +else if (key->uid == current->fsuid) kperm = key->perm >>16 ; else if (key->gid != -1 && key->perm & KEY_GRP_ALL &&
@@ -65,11 +68,14 @@ static inline int key_permission(const s* check to see whether permission is granted to use a key in at least one of * the desired ways */ -static inline int key_any_permission (const struct key *key,key_perm_t perm) +static inline int key_any_permission (const struct key_ref *key_ref,key_perm_t perm) { +struct key *key =key_deref (key_ref);key_perm_t kperm; -if (key->uid == current->fsuid) +if (is_key_possessed (key_ref)) + kperm = key->perm >>24 ; +else if (key->uid == current->fsuid) kperm = key->perm >>16 ; else if (key->gid != -1 && key->perm & KEY_GRP_ALL &&
@@ -94,13 +100,17 @@ static inline int key_task_groups_searchreturn ret; } -static inline int key_task_permission (const struct key *key, +static inline int key_task_permission (const struct key_ref *key_ref,struct task_struct *context,key_perm_t perm) { +struct key *key =key_deref (key_ref);key_perm_t kperm; -if (key->uid == context->fsuid) { +if (is_key_possessed (key_ref)) { + kperm = key->perm >>24 ; + } +else if (key->uid == context->fsuid) { kperm = key->perm >>16 ; } else if (key->gid != -1 &&
@@ -121,9 +131,9 @@ static inline int key_task_permission(co } -extern struct key *lookup_user_key (struct task_struct *context, -key_serial_t id,int create,int partial, -key_perm_t perm); +extern struct key_ref *lookup_user_key (struct task_struct *context, +key_serial_t id,int create,int partial, +key_perm_t perm);extern long join_session_keyring (const char *name);
security/keys/internal.h +14 -14
@@ -71,26 +71,26 @@ extern void keyring_publish_name(structextern int __key_link (struct key *keyring,struct key *key); -extern struct key *__keyring_search_one (struct key *keyring, -const struct key_type *type, -const char *description, -key_perm_t perm); +extern struct key_ref *__keyring_search_one (struct key_ref *keyring, +const struct key_type *type, +const char *description, +key_perm_t perm);extern struct key *keyring_search_instkey (struct key *keyring,key_serial_t target_id);typedef int (*key_match_func_t )(const struct key *,const void *); -extern struct key *keyring_search_aux (struct key *keyring, -struct task_struct *tsk, -struct key_type *type, -const void *description, -key_match_func_t match); - -extern struct key *search_process_keyrings (struct key_type *type, -const void *description, -key_match_func_t match, -struct task_struct *tsk); +extern struct key_ref *keyring_search_aux (struct key_ref *keyring, +struct task_struct *tsk, +struct key_type *type, +const void *description, +key_match_func_t match); + +extern struct key_ref *search_process_keyrings (struct key_type *type, +const void *description, +key_match_func_t match, +struct task_struct *tsk);extern struct key *find_keyring_by_name (const char *name,key_serial_t bound);
security/keys/key.c +46 -36
168 lines not on this page · raw message
security/keys/keyctl.c +85 -87
402 lines not on this page · raw message
security/keys/keyring.c +48 -36
192 lines not on this page · raw message
security/keys/proc.c +1 -1
@@ -167,7 +167,7 @@ static int proc_keys_show(struct seq_fil#define showflag (KEY ,LETTER ,FLAG ) \ (test_bit(FLAG, &(KEY)->flags) ? LETTER : '-') - seq_printf(m, "%08x %c%c%c%c%c%c %5d %4s %06x %5d %5d %-9.9s ", + seq_printf(m, "%08x %c%c%c%c%c%c %5d %4s %08x %5d %5d %-9.9s ", key->serial, showflag(key, 'I', KEY_FLAG_INSTANTIATED), showflag(key, 'R', KEY_FLAG_REVOKED),
security/keys/process_keys.c +67 -34
262 lines not on this page · raw message
security/keys/request_key_auth.c +1 -1
@@ -126,7 +126,7 @@ struct key *request_key_auth_new(struct rkakey =key_alloc (&key_type_request_key_auth, desc, current->fsuid, current->fsgid, -KEY_USR_VIEW ,1 ); +KEY_POS_VIEW |KEY_USR_VIEW ,1 );if (IS_ERR (rkakey)) {key_put (keyring);kleave ("= %ld" ,PTR_ERR (rkakey));
security/keys/request_key.c +28 -8
@@ -129,7 +129,7 @@ static struct key *__request_key_constru/* create a key and add it to the queue */ key =key_alloc (type, description, - current->fsuid, current->fsgid,KEY_USR_ALL ,0 ); + current->fsuid, current->fsgid,KEY_POS_ALL ,0 );if (IS_ERR (key)) goto alloc_failed;
@@ -364,15 +364,25 @@ struct key *request_key_and_link(struct struct key *dest_keyring) {struct key_user *user; +struct key_ref *key_ref;struct key *key;kenter ("%s,%s,%s,%p" , type->name, description, callout_info, dest_keyring);/* search all the process keyrings for a key */ - key =search_process_keyrings (type, description, type->match, current); + key_ref =search_process_keyrings (type, description, type->match, + current); -if (PTR_ERR (key) == -EAGAIN ) { +kdebug ("search 1: %p" , key_ref); + +if (!IS_ERR (key_ref)) { + key =key_deref (key_ref); + } +else if (PTR_ERR (key_ref) != -EAGAIN ) { + key =ERR_PTR (PTR_ERR (key_ref)); + } +else {/* the search failed, but the keyrings were searchable, so we * should consult userspace if we can */ key =ERR_PTR (-ENOKEY );
@@ -384,7 +394,7 @@ struct key *request_key_and_link(structif (!user) goto nomem; - do { +for (;;) {if (signal_pending (current)) goto interrupted;
@@ -397,10 +407,20 @@ struct key *request_key_and_link(struct/* someone else made the key we want, so we need to * search again as it might now be available to us */ - key =search_process_keyrings (type, description, - type->match, current); - - }while (PTR_ERR (key) == -EAGAIN ); + key_ref =search_process_keyrings (type, description, + type->match, + current); + +kdebug ("search 2: %p" , key_ref); + +if (PTR_ERR (key_ref) != -EAGAIN ) { +if (IS_ERR (key_ref)) + key =key_deref (key_ref); +else + key =ERR_PTR (PTR_ERR (key_ref)); +break ; + } + }key_user_put (user);
Quoted 5 lines · David Howells
The attached patch adds extra permission grants to keys for the possessor of a key in addition to the owner, group and other permissions bits. This makes SUID binaries easier to support without going as far as labelling keys and key targets using the LSM facilities.
Ok, maybe I'm just strange, but when I see code like
if (is_key_possessed(keyref)) {I'm inevitably mentally going "Linda Blair! It is spewing pea-soup and rotating its head!"
Maybe not the best of naming practices..
Linus
David Howells
maintainerQuoted 8 lines · Linus Torvalds
Ok, maybe I'm just strange, but when I see code like
if (is_key_possessed(keyref)) {I'm inevitably mentally going "Linda Blair! It is spewing pea-soup and rotating its head!"
Maybe not the best of naming practices..
Or maybe not the best of mental or film watching practices? :-)
How about if I call it is_key_retained() instead?
Of course, I now prefer the name is_key_possessed() if only to frighten other kernel developers...
David
Quoted 7 lines · David Howells
The attached patch adds extra permission grants to keys for the possessor of a key in addition to the owner, group and other permissions bits. This makes SUID binaries easier to support without going as far as labelling keys and key targets using the LSM facilities.
Quoted 5 lines
This patch adds a second "pointer type" to key structures (struct
key_ref*) that can have the bottom bit of the address set to indicate the possession of a key. This is propagated through searches from the keyring to the discovered key. It has been made a separate type so that the compiler can spot attempts to dereference a potentially incorrect pointer.
The above bit needs to be captured in a code comment. Because:
include/linux/key.h extern void keyring_replace_payload(stru · line 273
Quoted 8 lines
...
/*
+ * key reference with possession flag handling
+ */include/linux/key.h +4
-0+static inline struct key_ref *key_mkref (const struct key *key,unsigned long possession) +{ +return (struct key_ref *) ((unsigned long ) key | possession); +}
Is hair-raising and makes people want to come after you with a stick ;)
(And an 80-col xterm)
ugh, I see. struct key_ref' doesn't actually exist anywhere. The code only ever deals with pointers to this non-existent structure and they are munged struct key *'s.
Did this _have_ to happen?
include/linux/key-ui.h static inline int key_task_groups_search · line 113
Quoted 2 lines
include/linux/key-ui.h +2
-0+ } +else if (key->uid == context->fsuid) {
Documentation/CodingStyle?
security/keys/keyctl.c okay: · line 517
Quoted 7 lines
security/keys/keyctl.c +6
-0+"%s;%d;%d;%08x;%s" , +key_deref (key)->type->name, +key_deref (key)->uid, +key_deref (key)->gid, +key_deref (key)->perm, +key_deref (key)->description ?key_deref (key)->description :"" );
This doesn't actually make things clear.
security/keys/request_key.c struct key *request_key_and_link(struct · line 423
Quoted 8 lines
security/keys/request_key.c +8
-0+if (PTR_ERR (key_ref) != -EAGAIN ) { +if (IS_ERR (key_ref)) + key =key_deref (key_ref); +else + key =ERR_PTR (PTR_ERR (key_ref)); +break ; + } + }
That's getting a bit intimate with how IS_ERR and PTR_ERR are implemented but I guess we're unlikely to change that.
This all seems quite inappropriate to -rc2?
on den 21.09.2005 Klokka 10:15 (-0700) skreiv Andrew Morton:
Quoted 11 lines
security/keys/request_key.c struct key *request_key_and_link(struct · line 423
Quoted 8 lines
security/keys/request_key.c +8
-0+if (PTR_ERR (key_ref) != -EAGAIN ) { +if (IS_ERR (key_ref)) + key =key_deref (key_ref); +else + key =ERR_PTR (PTR_ERR (key_ref)); +break ; + } + }That's getting a bit intimate with how
IS_ERRandPTR_ERRare implemented but I guess we're unlikely to change that.
Shouldn't that test for IS_ERR(key_ref) be inverted?
Cheers,
Trond
David Howells
maintainerQuoted 2 lines · Trond Myklebust
Shouldn't that test for
IS_ERR(key_ref)be inverted?
Yes, and it should come first.
David
David Howells
maintainerQuoted 1 line · Andrew Morton
The above bit needs to be captured in a code comment. Because:
Okay.
Quoted 1 line
Is hair-raising and makes people want to come after you with a stick ;)
If people get upset by this sort of thing, they shouldn't be doing kernel development.
Quoted 5 lines
ugh, I see.
struct key_ref' doesn't actually exist anywhere. The code only ever deals with pointers to this non-existent structure and they are mungedstruct key *'s.Did this _have_ to happen?
I want to make sure that the key-pointer-with-attribute is not dereferenced accidentally (the attribute displaces the pointer by 1).
I can see several ways of doing what I wanted to do:
(1) I could pass extra arguments around to carry the attribute, but that's starting to get unwieldy for functions that take pointers to three keys.
(2) Define a reference structure, such as this:
struct key_ref {
struct key *key;
int possess;
};
Or this (with the attribute folded into the pointer):
struct key_ref {
struct key *possessed_key;
};
This could be passed directly as argument and return values:
struct key_ref keyring_search(struct key_ref keyring,
struct key_type *type,
const char *description);
Which would give the compiler lots of joy, or it could be done like this:
int keyring_search(struct key_ref *keyring,
struct key_type *type,
const char *description);
struct key_ref *_key);
Which would require extra stack space or kmalloc memory and memory loads.(3) Key handles (which I've been asked for before).
This involves detaching the permissions and suchlike from the key into a "handle" which can then be cloned. A temporary handle could then be used to hold the possession attribute and the other permissions at the time of the access.
The downside of this is that it's quite a big change. It also makes joining session keyrings way more "interesting". It does have some nice features though.
(4) Attach attribute to key pointer (which is what I've done).
This is slightly tricky in that it involves altering the pointer to carry extra information; but on the other hand, the information can be extracted or discarded with a single AND instruction.
I don't have to pass extra arguments around, though it may still use extra stack space for the extra automatic variables, depending on whether the compiler is clever enough to spot it can regenerate the real pointer by AND-ing again with the reference pointer.
Passing the attribute in the bottom bit of the pointer (option 4) seems to be the best method of doing it. I started implementing option 1 first, but that wasn't very pleasant.
Quoted 1 line
This doesn't actually make things clear.
Okay... I'll rethink that bit. "key" there should really be "key_ref" to make the point.
Quoted 11 lines
security/keys/request_key.c struct key *request_key_and_link(struct · line 423
Quoted 8 lines
security/keys/request_key.c +8
-0+if (PTR_ERR (key_ref) != -EAGAIN ) { +if (IS_ERR (key_ref)) + key =key_deref (key_ref); +else + key =ERR_PTR (PTR_ERR (key_ref)); +break ; + } + }That's getting a bit intimate with how
IS_ERRandPTR_ERRare implemented but I guess we're unlikely to change that.
You're referring to the ordering of the first two lines? I could, and probably should, reorder them. It's also wrong: there should be a ! before the IS_ERR.
I've changed this to:
if (!IS_ERR(key_ref)) {
key = key_deref(key_ref);
break;
}
if (PTR_ERR(key_ref) != -EAGAIN) {
key = ERR_PTR(PTR_ERR(key_ref));
break;
}Quoted 1 line
This all seems quite inappropriate to -rc2?
Which -rc2? If it's 2.6.14-rc2 you're referring to, then yes - that's already released.
David
Quoted 11 lines · David Howells
Quoted 1 line · Andrew Morton
The above bit needs to be captured in a code comment. Because:
Okay.
Quoted 1 line
Is hair-raising and makes people want to come after you with a stick ;)
If people get upset by this sort of thing, they shouldn't be doing kernel development.
hrmph. Of course it's a reasonable trick from a performance and convenience and resource consumption POV. But it's a new idiom and the threshold for new idioms is non-zero. We use it in struct page, but struct page is special.
It does need really obvious commenting. Pity the poor person who spends ten miniutes trying to find the definition of struct key_ref.
Quoted 13 lines
...
Quoted 11 lines
security/keys/request_key.c struct key *request_key_and_link(struct · line 423
Quoted 8 lines
security/keys/request_key.c +8
-0+if (PTR_ERR (key_ref) != -EAGAIN ) { +if (IS_ERR (key_ref)) + key =key_deref (key_ref); +else + key =ERR_PTR (PTR_ERR (key_ref)); +break ; + } + }That's getting a bit intimate with how
IS_ERRandPTR_ERRare implemented but I guess we're unlikely to change that.
Quoted 2 lines
You're referring to the ordering of the first two lines? I could, and probably should, reorder them.
Yup. Logically we shouldn't use PTR_ERR unless IS_ERR is known to be true. Yes, it works and yes, it'll surely continue to work. But.
Quoted 4 lines
It's also wrong: there should be a ! before the
IS_ERR.I've changed this to:
Quoted 9 lines
if (!IS_ERR(key_ref)) {
key = key_deref(key_ref);
break;
}
if (PTR_ERR(key_ref) != -EAGAIN) {
key = ERR_PTR(PTR_ERR(key_ref));
break;
}OK.
Quoted 4 lines
Quoted 1 line
This all seems quite inappropriate to -rc2?
Which -rc2? If it's 2.6.14-rc2 you're referring to, then yes - that's already released.
It doesn't fix any bugs (does it?). Hence according to the shiny new rules this work is 2.6.15 material.
Quoted 5 lines · Andrew Morton
hrmph. Of course it's a reasonable trick from a performance and convenience and resource consumption POV. But it's a new idiom and the threshold for new idioms is non-zero. We use it in struct page, but struct page is special.
Hmm.. I don't feel it is that new, but maybe that's because I've used that trick in other places. I think it's pretty common in a "type-safe C" way, and it should probably be encouraged. A unique pointer type for special usages, that you can't dereference even by mistake..
But adding a few comments might certainly be worth it. If only to teach others the trick.
Linus
David Howells
maintainerQuoted 9 lines · Linus Torvalds
Quoted 4 lines
hrmph. Of course it's a reasonable trick from a performance and convenience and resource consumption POV. But it's a new idiom and the threshold for new idioms is non-zero. We use it in struct page, but struct page is special.
Hmm.. I don't feel it is that new, but maybe that's because I've used that trick in other places. I think it's pretty common in a "type-safe C" way, and it should probably be encouraged. A unique pointer type for special usages, that you can't dereference even by mistake..
It's something that C isn't particularly good at. C++ is better at this as you can define a class and overload the -> operator and the unary * operator if you're feeling particularly evil or adventurous. But C it is...
Quoted 2 lines
But adding a few comments might certainly be worth it. If only to teach others the trick.
Maybe there should be some naming convention for quasi-pointers like this? I could typedef it, for instance, and hang comments appropriate to its nature of the typedef. Perhaps:
typedef struct __key_ref_with_possession_attribute *key_ref;
And then give its accessor functions capital letters to make them stand out, though that might give the false impression that they're actually preprocessor macros.
Or perhaps I should rename two of the functions:
key_mkref() -> construct_key_ref() key_deref() -> convert_key_ref_to_ptr() or extract_key_ptr()
Would that serve in lieu of commenting every time I use these things?
David
Quoted 5 lines · David Howells
(3) Key handles (which I've been asked for before).
This involves detaching the permissions and suchlike from the key into a "handle" which can then be cloned. A temporary handle could then be used to hold the possession attribute and the other permissions at the time of the access.
The downside of this is that it's quite a big change. It also makes joining session keyrings way more "interesting". It does have some nice features though.
Are there any plans to implement this functionality in the near future? It would complement the existing security model nicely by allowing a process to clone its key handle either explicitly (with a keyctl call) or implicitly (by passing it over a file handle to another process), and then later revoke the cloned handle and all handles cloned from it with a single call, much as one can SIGKILL an entire process group with a single kill(). It seems that a key handle would be little more than a special sort of file handle attached to a key. I'm curious what issues you've found with joining session keyrings. I haven't thought about that part specifically, but it seems that perhaps there should be a set of "default" permissions and attributes that are associated with a new lookup-by-key-id handle.
Cheers,
Kyle Moffett
--
There are two ways of constructing a software design. One way is to make it so simple that there are obviously no deficiencies. And the other way is to make it so complicated that there are no obvious deficiencies. The first method is far more difficult.
-- C.A.R. Hoare
David Howells
maintainerPATCH 1/1 Keys: Add possessor permissions to keys [try #2]
In reply to David HowellsThe attached patch adds extra permission grants to keys for the possessor of a key in addition to the owner, group and other permissions bits. This makes SUID binaries easier to support without going as far as labelling keys and key targets using the LSM facilities.
This patch adds a second "pointer type" to key structures (struct key_ref *) that can have the bottom bit of the address set to indicate the possession of a key. This is propagated through searches from the keyring to the discovered key. It has been made a separate type so that the compiler can spot attempts to dereference a potentially incorrect pointer.
The "possession" attribute can't be attached to a key structure directly as it's not an intrinsic property of a key.
Pointers to keys have been replaced with struct key_ref *'s wherever possession information needs to be passed through.
This does assume that the bottom bit of the pointer will always be zero on return from kmem_cache_alloc().
---
warthog>diffstat -p1 keys-possess-2614rc1mm1-2.diff
Documentation/keys.txt | 64 ++++++-- include/linux/key-ui.h | 28 ++- include/linux/key.h | 70 +++++++-- security/keys/internal.h | 28 +-- security/keys/key.c | 82 ++++++---- security/keys/keyctl.c | 299 +++++++++++++++++++-------------------- security/keys/keyring.c | 84 ++++++---- security/keys/proc.c | 2 security/keys/process_keys.c | 101 ++++++++----- security/keys/request_key.c | 36 +++- security/keys/request_key_auth.c | 2 11 files changed, 478 insertions(+), 318 deletions(-)
Documentation/keys.txt +48 -16
@@ -195,8 +195,8 @@ KEY ACCESS PERMISSIONS ====================== Keys have an owner user ID, a group access ID, and a permissions mask. The mask -has up to eight bits each for user, group and other access. Only five of each -set of eight bits are defined. These permissions granted are: +has up to eight bits each for possessor, user, group and other access. Only +five of each set of eight bits are defined. These permissions granted are: (*) View
@@ -241,16 +241,16 @@ about the status of the key service: type, description and permissions. The payload of the key is not available this way: - SERIAL FLAGS USAGE EXPY PERM UID GID TYPE DESCRIPTION: SUMMARY - 00000001 I----- 39 perm 1f0000 0 0 keyring _uid_ses.0: 1/4 - 00000002 I----- 2 perm 1f0000 0 0 keyring _uid.0: empty - 00000007 I----- 1 perm 1f0000 0 0 keyring _pid.1: empty - 0000018d I----- 1 perm 1f0000 0 0 keyring _pid.412: empty - 000004d2 I--Q-- 1 perm 1f0000 32 -1 keyring _uid.32: 1/4 - 000004d3 I--Q-- 3 perm 1f0000 32 -1 keyring _uid_ses.32: empty - 00000892 I--QU- 1 perm 1f0000 0 0 user metal:copper: 0 - 00000893 I--Q-N 1 35s 1f0000 0 0 user metal:silver: 0 - 00000894 I--Q-- 1 10h 1f0000 0 0 user metal:gold: 0 + SERIAL FLAGS USAGE EXPY PERM UID GID TYPE DESCRIPTION: SUMMARY + 00000001 I----- 39 perm 1f1f0000 0 0 keyring _uid_ses.0: 1/4 + 00000002 I----- 2 perm 1f1f0000 0 0 keyring _uid.0: empty + 00000007 I----- 1 perm 1f1f0000 0 0 keyring _pid.1: empty + 0000018d I----- 1 perm 1f1f0000 0 0 keyring _pid.412: empty + 000004d2 I--Q-- 1 perm 1f1f0000 32 -1 keyring _uid.32: 1/4 + 000004d3 I--Q-- 3 perm 1f1f0000 32 -1 keyring _uid_ses.32: empty + 00000892 I--QU- 1 perm 1f000000 0 0 user metal:copper: 0 + 00000893 I--Q-N 1 35s 1f1f0000 0 0 user metal:silver: 0 + 00000894 I--Q-- 1 10h 001f0000 0 0 user metal:gold: 0 The flags are:
@@ -637,6 +637,34 @@ call, and the key released upon close. H two different users opening the same file is left to the filesystem author to solve. +Note that there are two different types of pointers to keys that may be +encountered: + + (*) struct key * + + This simply points to the key structure itself. Key structures will be at + least four-byte aligned. + + (*) struct key_ref * + + This is equivalent to a struct key *, but the least significant bit is set + if the caller "possesses" the key. By "possession" it is meant that the + calling processes has a searchable link to the key from one of its + keyrings. Their are three functions for dealing with these: + + struct key_ref *key_mkref(const struct key *key, + unsigned long possession); + + struct key *key_deref(const struct key_ref *key_ref); + + unsigned long is_key_possessed(const struct key_ref *key_ref); + + The first function constructs a key reference from a key pointer and + possession information (which must be 0 or 1 and no other value). + + The second function retrieves the key pointer and the third retrieves the + possession flag). + When accessing a key's payload contents, certain precautions must be taken to prevent access vs modification races. See the section "Notes on accessing payload contents" for more information.
@@ -689,14 +717,18 @@ payload contents" for more information. (*) If a keyring was found in the search, this can be further searched by: - struct key *keyring_search(struct key *keyring, - const struct key_type *type, - const char *description) + struct key_ref *keyring_search(struct key_ref *keyring, + const struct key_type *type, + const char *description) This searches the keyring tree specified for a matching key. Error ENOKEY is returned upon failure. If successful, the returned key will need to be released. + The possession attribute from the keyring reference pointer is used to + control access through the permissions mask and is propagated to the + returned key reference pointer if successful. + (*) To check the validity of a key, this function can be called:
@@ -732,7 +764,7 @@ More complex payload contents must be al key->payload.data. One of the following ways must be selected to access the data: - (1) Unmodifyable key type. + (1) Unmodifiable key type. If the key type does not have a modify method, then the key's payload can be accessed without any form of locking, provided that it's known to be
include/linux/key.h +55 -15
106 lines not on this page · raw message
include/linux/key-ui.h +19 -9
@@ -42,11 +42,14 @@ struct keyring_list {/* * check to see whether permission is granted to use a key in the desired way */ -static inline int key_permission (const struct key *key,key_perm_t perm) +static inline int key_permission (const struct key_ref *key_ref,key_perm_t perm) { +struct key *key =key_deref (key_ref);key_perm_t kperm; -if (key->uid == current->fsuid) +if (is_key_possessed (key_ref)) + kperm = key->perm >>24 ; +else if (key->uid == current->fsuid) kperm = key->perm >>16 ; else if (key->gid != -1 && key->perm & KEY_GRP_ALL &&
@@ -65,11 +68,14 @@ static inline int key_permission(const s* check to see whether permission is granted to use a key in at least one of * the desired ways */ -static inline int key_any_permission (const struct key *key,key_perm_t perm) +static inline int key_any_permission (const struct key_ref *key_ref,key_perm_t perm) { +struct key *key =key_deref (key_ref);key_perm_t kperm; -if (key->uid == current->fsuid) +if (is_key_possessed (key_ref)) + kperm = key->perm >>24 ; +else if (key->uid == current->fsuid) kperm = key->perm >>16 ; else if (key->gid != -1 && key->perm & KEY_GRP_ALL &&
@@ -94,13 +100,17 @@ static inline int key_task_groups_searchreturn ret; } -static inline int key_task_permission (const struct key *key, +static inline int key_task_permission (const struct key_ref *key_ref,struct task_struct *context,key_perm_t perm) { +struct key *key =key_deref (key_ref);key_perm_t kperm; -if (key->uid == context->fsuid) { +if (is_key_possessed (key_ref)) { + kperm = key->perm >>24 ; + } +else if (key->uid == context->fsuid) { kperm = key->perm >>16 ; } else if (key->gid != -1 &&
@@ -121,9 +131,9 @@ static inline int key_task_permission(co } -extern struct key *lookup_user_key (struct task_struct *context, -key_serial_t id,int create,int partial, -key_perm_t perm); +extern struct key_ref *lookup_user_key (struct task_struct *context, +key_serial_t id,int create,int partial, +key_perm_t perm);extern long join_session_keyring (const char *name);
security/keys/internal.h +14 -14
@@ -71,26 +71,26 @@ extern void keyring_publish_name(structextern int __key_link (struct key *keyring,struct key *key); -extern struct key *__keyring_search_one (struct key *keyring, -const struct key_type *type, -const char *description, -key_perm_t perm); +extern struct key_ref *__keyring_search_one (struct key_ref *keyring, +const struct key_type *type, +const char *description, +key_perm_t perm);extern struct key *keyring_search_instkey (struct key *keyring,key_serial_t target_id);typedef int (*key_match_func_t )(const struct key *,const void *); -extern struct key *keyring_search_aux (struct key *keyring, -struct task_struct *tsk, -struct key_type *type, -const void *description, -key_match_func_t match); - -extern struct key *search_process_keyrings (struct key_type *type, -const void *description, -key_match_func_t match, -struct task_struct *tsk); +extern struct key_ref *keyring_search_aux (struct key_ref *keyring, +struct task_struct *tsk, +struct key_type *type, +const void *description, +key_match_func_t match); + +extern struct key_ref *search_process_keyrings (struct key_type *type, +const void *description, +key_match_func_t match, +struct task_struct *tsk);extern struct key *find_keyring_by_name (const char *name,key_serial_t bound);
security/keys/key.c +46 -36
168 lines not on this page · raw message
security/keys/keyctl.c +150 -149
593 lines not on this page · raw message
security/keys/keyring.c +48 -36
192 lines not on this page · raw message
security/keys/proc.c +1 -1
@@ -167,7 +167,7 @@ static int proc_keys_show(struct seq_fil#define showflag (KEY ,LETTER ,FLAG ) \ (test_bit(FLAG, &(KEY)->flags) ? LETTER : '-') - seq_printf(m, "%08x %c%c%c%c%c%c %5d %4s %06x %5d %5d %-9.9s ", + seq_printf(m, "%08x %c%c%c%c%c%c %5d %4s %08x %5d %5d %-9.9s ", key->serial, showflag(key, 'I', KEY_FLAG_INSTANTIATED), showflag(key, 'R', KEY_FLAG_REVOKED),
security/keys/process_keys.c +67 -34
262 lines not on this page · raw message
security/keys/request_key_auth.c +1 -1
@@ -126,7 +126,7 @@ struct key *request_key_auth_new(struct rkakey =key_alloc (&key_type_request_key_auth, desc, current->fsuid, current->fsgid, -KEY_USR_VIEW ,1 ); +KEY_POS_VIEW |KEY_USR_VIEW ,1 );if (IS_ERR (rkakey)) {key_put (keyring);kleave ("= %ld" ,PTR_ERR (rkakey));
security/keys/request_key.c +29 -7
@@ -129,7 +129,7 @@ static struct key *__request_key_constru/* create a key and add it to the queue */ key =key_alloc (type, description, - current->fsuid, current->fsgid,KEY_USR_ALL ,0 ); + current->fsuid, current->fsgid,KEY_POS_ALL ,0 );if (IS_ERR (key)) goto alloc_failed;
@@ -364,15 +364,25 @@ struct key *request_key_and_link(struct struct key *dest_keyring) {struct key_user *user; +struct key_ref *key_ref;struct key *key;kenter ("%s,%s,%s,%p" , type->name, description, callout_info, dest_keyring);/* search all the process keyrings for a key */ - key =search_process_keyrings (type, description, type->match, current); + key_ref =search_process_keyrings (type, description, type->match, + current); -if (PTR_ERR (key) == -EAGAIN ) { +kdebug ("search 1: %p" , key_ref); + +if (!IS_ERR (key_ref)) { + key =key_deref (key_ref); + } +else if (PTR_ERR (key_ref) != -EAGAIN ) { + key =ERR_PTR (PTR_ERR (key_ref)); + } +else {/* the search failed, but the keyrings were searchable, so we * should consult userspace if we can */ key =ERR_PTR (-ENOKEY );
@@ -384,7 +394,7 @@ struct key *request_key_and_link(structif (!user) goto nomem; - do { +for (;;) {if (signal_pending (current)) goto interrupted;
@@ -397,10 +407,22 @@ struct key *request_key_and_link(struct/* someone else made the key we want, so we need to * search again as it might now be available to us */ - key =search_process_keyrings (type, description, - type->match, current); + key_ref =search_process_keyrings (type, description, + type->match, + current); + +kdebug ("search 2: %p" , key_ref); - }while (PTR_ERR (key) == -EAGAIN ); +if (!IS_ERR (key_ref)) { + key =key_deref (key_ref); +break ; + } + +if (PTR_ERR (key_ref) != -EAGAIN ) { + key =ERR_PTR (PTR_ERR (key_ref)); +break ; + } + }key_user_put (user);
David Howells
maintainerPATCH 1/1 Keys: Add possessor permissions to keys [try #3]
The attached patch adds extra permission grants to keys for the possessor of a key in addition to the owner, group and other permissions bits. This makes SUID binaries easier to support without going as far as labelling keys and key targets using the LSM facilities.
This patch adds a second "pointer type" to key structures (struct key_ref *) that can have the bottom bit of the address set to indicate the possession of a key. This is propagated through searches from the keyring to the discovered key. It has been made a separate type so that the compiler can spot attempts to dereference a potentially incorrect pointer.
The "possession" attribute can't be attached to a key structure directly as it's not an intrinsic property of a key.
Pointers to keys have been replaced with struct key_ref *'s wherever possession information needs to be passed through.
This does assume that the bottom bit of the pointer will always be zero on return from kmem_cache_alloc().
The key reference type has been made into a typedef so that at least it can be located in the sources, even though it's basically a pointer to an undefined type. I've also renamed the accessor functions to be more useful, and all reference variables should now end in "_ref".
---
warthog>diffstat -p1 keys-possess-2614rc1mm1-3.diff
Documentation/keys.txt | 74 +++++++-- include/linux/key-ui.h | 28 ++- include/linux/key.h | 78 ++++++++-- security/keys/internal.h | 28 +-- security/keys/key.c | 81 +++++----- security/keys/keyctl.c | 299 +++++++++++++++++++-------------------- security/keys/keyring.c | 86 ++++++----- security/keys/proc.c | 2 security/keys/process_keys.c | 164 +++++++++++++-------- security/keys/request_key.c | 36 +++- security/keys/request_key_auth.c | 2 11 files changed, 528 insertions(+), 350 deletions(-)
Documentation/keys.txt +55 -19
@@ -195,8 +195,8 @@ KEY ACCESS PERMISSIONS ====================== Keys have an owner user ID, a group access ID, and a permissions mask. The mask -has up to eight bits each for user, group and other access. Only five of each -set of eight bits are defined. These permissions granted are: +has up to eight bits each for possessor, user, group and other access. Only +five of each set of eight bits are defined. These permissions granted are: (*) View
@@ -241,16 +241,16 @@ about the status of the key service: type, description and permissions. The payload of the key is not available this way: - SERIAL FLAGS USAGE EXPY PERM UID GID TYPE DESCRIPTION: SUMMARY - 00000001 I----- 39 perm 1f0000 0 0 keyring _uid_ses.0: 1/4 - 00000002 I----- 2 perm 1f0000 0 0 keyring _uid.0: empty - 00000007 I----- 1 perm 1f0000 0 0 keyring _pid.1: empty - 0000018d I----- 1 perm 1f0000 0 0 keyring _pid.412: empty - 000004d2 I--Q-- 1 perm 1f0000 32 -1 keyring _uid.32: 1/4 - 000004d3 I--Q-- 3 perm 1f0000 32 -1 keyring _uid_ses.32: empty - 00000892 I--QU- 1 perm 1f0000 0 0 user metal:copper: 0 - 00000893 I--Q-N 1 35s 1f0000 0 0 user metal:silver: 0 - 00000894 I--Q-- 1 10h 1f0000 0 0 user metal:gold: 0 + SERIAL FLAGS USAGE EXPY PERM UID GID TYPE DESCRIPTION: SUMMARY + 00000001 I----- 39 perm 1f1f0000 0 0 keyring _uid_ses.0: 1/4 + 00000002 I----- 2 perm 1f1f0000 0 0 keyring _uid.0: empty + 00000007 I----- 1 perm 1f1f0000 0 0 keyring _pid.1: empty + 0000018d I----- 1 perm 1f1f0000 0 0 keyring _pid.412: empty + 000004d2 I--Q-- 1 perm 1f1f0000 32 -1 keyring _uid.32: 1/4 + 000004d3 I--Q-- 3 perm 1f1f0000 32 -1 keyring _uid_ses.32: empty + 00000892 I--QU- 1 perm 1f000000 0 0 user metal:copper: 0 + 00000893 I--Q-N 1 35s 1f1f0000 0 0 user metal:silver: 0 + 00000894 I--Q-- 1 10h 001f0000 0 0 user metal:gold: 0 The flags are:
@@ -637,6 +637,34 @@ call, and the key released upon close. H two different users opening the same file is left to the filesystem author to solve. +Note that there are two different types of pointers to keys that may be +encountered: + + (*) struct key * + + This simply points to the key structure itself. Key structures will be at + least four-byte aligned. + + (*) key_ref_t + + This is equivalent to a struct key *, but the least significant bit is set + if the caller "possesses" the key. By "possession" it is meant that the + calling processes has a searchable link to the key from one of its + keyrings. There are three functions for dealing with these: + + key_ref_t make_key_ref(const struct key *key, + unsigned long possession); + + struct key *key_ref_to_ptr(const key_ref_t key_ref); + + unsigned long is_key_possessed(const key_ref_t key_ref); + + The first function constructs a key reference from a key pointer and + possession information (which must be 0 or 1 and not any other value). + + The second function retrieves the key pointer from a reference and the + third retrieves the possession flag. + When accessing a key's payload contents, certain precautions must be taken to prevent access vs modification races. See the section "Notes on accessing payload contents" for more information.
@@ -665,7 +693,11 @@ payload contents" for more information. void key_put(struct key *key); - This can be called from interrupt context. If CONFIG_KEYS is not set then + Or: + + void key_ref_put(key_ref_t key_ref); + + These can be called from interrupt context. If CONFIG_KEYS is not set then the argument will not be parsed.
@@ -689,13 +721,17 @@ payload contents" for more information. (*) If a keyring was found in the search, this can be further searched by: - struct key *keyring_search(struct key *keyring, - const struct key_type *type, - const char *description) + key_ref_t keyring_search(key_ref_t keyring_ref, + const struct key_type *type, + const char *description) This searches the keyring tree specified for a matching key. Error ENOKEY - is returned upon failure. If successful, the returned key will need to be - released. + is returned upon failure (use IS_ERR/PTR_ERR to determine). If successful, + the returned key will need to be released. + + The possession attribute from the keyring reference is used to control + access through the permissions mask and is propagated to the returned key + reference pointer if successful. (*) To check the validity of a key, this function can be called:
@@ -732,7 +768,7 @@ More complex payload contents must be al key->payload.data. One of the following ways must be selected to access the data: - (1) Unmodifyable key type. + (1) Unmodifiable key type. If the key type does not have a modify method, then the key's payload can be accessed without any form of locking, provided that it's known to be
include/linux/key.h +63 -15
115 lines not on this page · raw message
include/linux/key-ui.h +19 -9
@@ -42,11 +42,14 @@ struct keyring_list {/* * check to see whether permission is granted to use a key in the desired way */ -static inline int key_permission (const struct key *key,key_perm_t perm) +static inline int key_permission (const key_ref_t key_ref,key_perm_t perm) { +struct key *key =key_ref_to_ptr (key_ref);key_perm_t kperm; -if (key->uid == current->fsuid) +if (is_key_possessed (key_ref)) + kperm = key->perm >>24 ; +else if (key->uid == current->fsuid) kperm = key->perm >>16 ; else if (key->gid != -1 && key->perm & KEY_GRP_ALL &&
@@ -65,11 +68,14 @@ static inline int key_permission(const s* check to see whether permission is granted to use a key in at least one of * the desired ways */ -static inline int key_any_permission (const struct key *key,key_perm_t perm) +static inline int key_any_permission (const key_ref_t key_ref,key_perm_t perm) { +struct key *key =key_ref_to_ptr (key_ref);key_perm_t kperm; -if (key->uid == current->fsuid) +if (is_key_possessed (key_ref)) + kperm = key->perm >>24 ; +else if (key->uid == current->fsuid) kperm = key->perm >>16 ; else if (key->gid != -1 && key->perm & KEY_GRP_ALL &&
@@ -94,13 +100,17 @@ static inline int key_task_groups_searchreturn ret; } -static inline int key_task_permission (const struct key *key, +static inline int key_task_permission (const key_ref_t key_ref,struct task_struct *context,key_perm_t perm) { +struct key *key =key_ref_to_ptr (key_ref);key_perm_t kperm; -if (key->uid == context->fsuid) { +if (is_key_possessed (key_ref)) { + kperm = key->perm >>24 ; + } +else if (key->uid == context->fsuid) { kperm = key->perm >>16 ; } else if (key->gid != -1 &&
@@ -121,9 +131,9 @@ static inline int key_task_permission(co } -extern struct key *lookup_user_key (struct task_struct *context, -key_serial_t id,int create,int partial, -key_perm_t perm); +extern key_ref_t lookup_user_key (struct task_struct *context, +key_serial_t id,int create,int partial, +key_perm_t perm);extern long join_session_keyring (const char *name);
security/keys/internal.h +14 -14
@@ -71,26 +71,26 @@ extern void keyring_publish_name(structextern int __key_link (struct key *keyring,struct key *key); -extern struct key *__keyring_search_one (struct key *keyring, -const struct key_type *type, -const char *description, -key_perm_t perm); +extern key_ref_t __keyring_search_one (key_ref_t keyring_ref, +const struct key_type *type, +const char *description, +key_perm_t perm);extern struct key *keyring_search_instkey (struct key *keyring,key_serial_t target_id);typedef int (*key_match_func_t )(const struct key *,const void *); -extern struct key *keyring_search_aux (struct key *keyring, -struct task_struct *tsk, -struct key_type *type, -const void *description, -key_match_func_t match); - -extern struct key *search_process_keyrings (struct key_type *type, -const void *description, -key_match_func_t match, -struct task_struct *tsk); +extern key_ref_t keyring_search_aux (key_ref_t keyring_ref, +struct task_struct *tsk, +struct key_type *type, +const void *description, +key_match_func_t match); + +extern key_ref_t search_process_keyrings (struct key_type *type, +const void *description, +key_match_func_t match, +struct task_struct *tsk);extern struct key *find_keyring_by_name (const char *name,key_serial_t bound);
security/keys/key.c +45 -36
167 lines not on this page · raw message
security/keys/keyctl.c +150 -149
591 lines not on this page · raw message
security/keys/keyring.c +50 -36
194 lines not on this page · raw message
security/keys/proc.c +1 -1
@@ -167,7 +167,7 @@ static int proc_keys_show(struct seq_fil#define showflag (KEY ,LETTER ,FLAG ) \ (test_bit(FLAG, &(KEY)->flags) ? LETTER : '-') - seq_printf(m, "%08x %c%c%c%c%c%c %5d %4s %06x %5d %5d %-9.9s ", + seq_printf(m, "%08x %c%c%c%c%c%c %5d %4s %08x %5d %5d %-9.9s ", key->serial, showflag(key, 'I', KEY_FLAG_INSTANTIATED), showflag(key, 'R', KEY_FLAG_REVOKED),
security/keys/process_keys.c +101 -63
377 lines not on this page · raw message
security/keys/request_key_auth.c +1 -1
@@ -126,7 +126,7 @@ struct key *request_key_auth_new(struct rkakey =key_alloc (&key_type_request_key_auth, desc, current->fsuid, current->fsgid, -KEY_USR_VIEW ,1 ); +KEY_POS_VIEW |KEY_USR_VIEW ,1 );if (IS_ERR (rkakey)) {key_put (keyring);kleave ("= %ld" ,PTR_ERR (rkakey));
security/keys/request_key.c +29 -7
@@ -129,7 +129,7 @@ static struct key *__request_key_constru/* create a key and add it to the queue */ key =key_alloc (type, description, - current->fsuid, current->fsgid,KEY_USR_ALL ,0 ); + current->fsuid, current->fsgid,KEY_POS_ALL ,0 );if (IS_ERR (key)) goto alloc_failed;
@@ -365,14 +365,24 @@ struct key *request_key_and_link(struct {struct key_user *user;struct key *key; +key_ref_t key_ref;kenter ("%s,%s,%s,%p" , type->name, description, callout_info, dest_keyring);/* search all the process keyrings for a key */ - key =search_process_keyrings (type, description, type->match, current); + key_ref =search_process_keyrings (type, description, type->match, + current); -if (PTR_ERR (key) == -EAGAIN ) { +kdebug ("search 1: %p" , key_ref); + +if (!IS_ERR (key_ref)) { + key =key_ref_to_ptr (key_ref); + } +else if (PTR_ERR (key_ref) != -EAGAIN ) { + key =ERR_PTR (PTR_ERR (key_ref)); + } +else {/* the search failed, but the keyrings were searchable, so we * should consult userspace if we can */ key =ERR_PTR (-ENOKEY );
@@ -384,7 +394,7 @@ struct key *request_key_and_link(structif (!user) goto nomem; - do { +for (;;) {if (signal_pending (current)) goto interrupted;
@@ -397,10 +407,22 @@ struct key *request_key_and_link(struct/* someone else made the key we want, so we need to * search again as it might now be available to us */ - key =search_process_keyrings (type, description, - type->match, current); + key_ref =search_process_keyrings (type, description, + type->match, + current); + +kdebug ("search 2: %p" , key_ref); - }while (PTR_ERR (key) == -EAGAIN ); +if (!IS_ERR (key_ref)) { + key =key_ref_to_ptr (key_ref); +break ; + } + +if (PTR_ERR (key_ref) != -EAGAIN ) { + key =ERR_PTR (PTR_ERR (key_ref)); +break ; + } + }key_user_put (user);
James Morris
maintainerinclude/linux/key-ui.h static inline int key_task_groups_search · line 114
Quoted 5 lines · David Howells
include/linux/key-ui.h +4
-0+if (is_key_possessed (key_ref)) { + kperm = key->perm >>24 ; + } +else if (key->uid == context->fsuid) { kperm = key->perm >>16 ;
Can you use macros for these magic numbers?
- James
Signature · 2 lines
James Morris <[email protected]>