diff options
author | David Howells <dhowells@redhat.com> | 2005-10-30 18:02:44 -0500 |
---|---|---|
committer | Linus Torvalds <torvalds@g5.osdl.org> | 2005-10-30 20:37:23 -0500 |
commit | 29db9190634067c5a328ee5fcc2890251b836b4b (patch) | |
tree | 07ec242789230824f1fa8bcbbe681fd5bf166fa8 /security/keys/keyring.c | |
parent | 2aa349f6e37ce030060c994d3aebbff4ab703565 (diff) |
[PATCH] Keys: Add LSM hooks for key management [try #3]
The attached patch adds LSM hooks for key management facilities. The notable
changes are:
(1) The key struct now supports a security pointer for the use of security
modules. This will permit key labelling and restrictions on which
programs may access a key.
(2) Security modules get a chance to note (or abort) the allocation of a key.
(3) The key permission checking can now be enhanced by the security modules;
the permissions check consults LSM if all other checks bear out.
(4) The key permissions checking functions now return an error code rather
than a boolean value.
(5) An extra permission has been added to govern the modification of
attributes (UID, GID, permissions).
Note that there isn't an LSM hook specifically for each keyctl() operation,
but rather the permissions hook allows control of individual operations based
on the permission request bits.
Key management access control through LSM is enabled by automatically if both
CONFIG_KEYS and CONFIG_SECURITY are enabled.
This should be applied on top of the patch ensubjected:
[PATCH] Keys: Possessor permissions should be additive
Signed-Off-By: David Howells <dhowells@redhat.com>
Signed-off-by: Chris Wright <chrisw@osdl.org>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Diffstat (limited to 'security/keys/keyring.c')
-rw-r--r-- | security/keys/keyring.c | 21 |
1 files changed, 13 insertions, 8 deletions
diff --git a/security/keys/keyring.c b/security/keys/keyring.c index 0639396dd441..e1cc4dd79012 100644 --- a/security/keys/keyring.c +++ b/security/keys/keyring.c | |||
@@ -13,6 +13,7 @@ | |||
13 | #include <linux/init.h> | 13 | #include <linux/init.h> |
14 | #include <linux/sched.h> | 14 | #include <linux/sched.h> |
15 | #include <linux/slab.h> | 15 | #include <linux/slab.h> |
16 | #include <linux/security.h> | ||
16 | #include <linux/seq_file.h> | 17 | #include <linux/seq_file.h> |
17 | #include <linux/err.h> | 18 | #include <linux/err.h> |
18 | #include <asm/uaccess.h> | 19 | #include <asm/uaccess.h> |
@@ -309,7 +310,9 @@ struct key *keyring_alloc(const char *description, uid_t uid, gid_t gid, | |||
309 | int ret; | 310 | int ret; |
310 | 311 | ||
311 | keyring = key_alloc(&key_type_keyring, description, | 312 | keyring = key_alloc(&key_type_keyring, description, |
312 | uid, gid, KEY_POS_ALL | KEY_USR_ALL, not_in_quota); | 313 | uid, gid, |
314 | (KEY_POS_ALL & ~KEY_POS_SETATTR) | KEY_USR_ALL, | ||
315 | not_in_quota); | ||
313 | 316 | ||
314 | if (!IS_ERR(keyring)) { | 317 | if (!IS_ERR(keyring)) { |
315 | ret = key_instantiate_and_link(keyring, NULL, 0, dest, NULL); | 318 | ret = key_instantiate_and_link(keyring, NULL, 0, dest, NULL); |
@@ -359,9 +362,11 @@ key_ref_t keyring_search_aux(key_ref_t keyring_ref, | |||
359 | key_check(keyring); | 362 | key_check(keyring); |
360 | 363 | ||
361 | /* top keyring must have search permission to begin the search */ | 364 | /* top keyring must have search permission to begin the search */ |
362 | key_ref = ERR_PTR(-EACCES); | 365 | err = key_task_permission(keyring_ref, context, KEY_SEARCH); |
363 | if (!key_task_permission(keyring_ref, context, KEY_SEARCH)) | 366 | if (err < 0) { |
367 | key_ref = ERR_PTR(err); | ||
364 | goto error; | 368 | goto error; |
369 | } | ||
365 | 370 | ||
366 | key_ref = ERR_PTR(-ENOTDIR); | 371 | key_ref = ERR_PTR(-ENOTDIR); |
367 | if (keyring->type != &key_type_keyring) | 372 | if (keyring->type != &key_type_keyring) |
@@ -402,8 +407,8 @@ descend: | |||
402 | continue; | 407 | continue; |
403 | 408 | ||
404 | /* key must have search permissions */ | 409 | /* key must have search permissions */ |
405 | if (!key_task_permission(make_key_ref(key, possessed), | 410 | if (key_task_permission(make_key_ref(key, possessed), |
406 | context, KEY_SEARCH)) | 411 | context, KEY_SEARCH) < 0) |
407 | continue; | 412 | continue; |
408 | 413 | ||
409 | /* we set a different error code if we find a negative key */ | 414 | /* we set a different error code if we find a negative key */ |
@@ -430,7 +435,7 @@ ascend: | |||
430 | continue; | 435 | continue; |
431 | 436 | ||
432 | if (!key_task_permission(make_key_ref(key, possessed), | 437 | if (!key_task_permission(make_key_ref(key, possessed), |
433 | context, KEY_SEARCH)) | 438 | context, KEY_SEARCH) < 0) |
434 | continue; | 439 | continue; |
435 | 440 | ||
436 | /* stack the current position */ | 441 | /* stack the current position */ |
@@ -521,7 +526,7 @@ key_ref_t __keyring_search_one(key_ref_t keyring_ref, | |||
521 | (!key->type->match || | 526 | (!key->type->match || |
522 | key->type->match(key, description)) && | 527 | key->type->match(key, description)) && |
523 | key_permission(make_key_ref(key, possessed), | 528 | key_permission(make_key_ref(key, possessed), |
524 | perm) && | 529 | perm) < 0 && |
525 | !test_bit(KEY_FLAG_REVOKED, &key->flags) | 530 | !test_bit(KEY_FLAG_REVOKED, &key->flags) |
526 | ) | 531 | ) |
527 | goto found; | 532 | goto found; |
@@ -617,7 +622,7 @@ struct key *find_keyring_by_name(const char *name, key_serial_t bound) | |||
617 | continue; | 622 | continue; |
618 | 623 | ||
619 | if (!key_permission(make_key_ref(keyring, 0), | 624 | if (!key_permission(make_key_ref(keyring, 0), |
620 | KEY_SEARCH)) | 625 | KEY_SEARCH) < 0) |
621 | continue; | 626 | continue; |
622 | 627 | ||
623 | /* found a potential candidate, but we still need to | 628 | /* found a potential candidate, but we still need to |