diff options
author | Zoran Markovic <zmarkovic@sierrawireless.com> | 2018-10-17 19:25:44 -0400 |
---|---|---|
committer | Casey Schaufler <casey.schaufler@intel.com> | 2018-12-03 14:57:55 -0500 |
commit | 5b841bfab695e3b8ae793172a9ff7990f99cc3e2 (patch) | |
tree | 5cb5dd112e5f414a1008adef5c5aa061441851af /security | |
parent | 26b76320a8a550472bbb8f42257df83fcb8d8df6 (diff) |
smack: fix access permissions for keyring
Function smack_key_permission() only issues smack requests for the
following operations:
- KEY_NEED_READ (issues MAY_READ)
- KEY_NEED_WRITE (issues MAY_WRITE)
- KEY_NEED_LINK (issues MAY_WRITE)
- KEY_NEED_SETATTR (issues MAY_WRITE)
A blank smack request is issued in all other cases, resulting in
smack access being granted if there is any rule defined between
subject and object, or denied with -EACCES otherwise.
Request MAY_READ access for KEY_NEED_SEARCH and KEY_NEED_VIEW.
Fix the logic in the unlikely case when both MAY_READ and
MAY_WRITE are needed. Validate access permission field for valid
contents.
Signed-off-by: Zoran Markovic <zmarkovic@sierrawireless.com>
Signed-off-by: Casey Schaufler <casey@schaufler-ca.com>
Cc: Casey Schaufler <casey@schaufler-ca.com>
Cc: James Morris <jmorris@namei.org>
Cc: "Serge E. Hallyn" <serge@hallyn.com>
Diffstat (limited to 'security')
-rw-r--r-- | security/smack/smack_lsm.c | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/security/smack/smack_lsm.c b/security/smack/smack_lsm.c index 81fb4c1631e9..cd720c06b78c 100644 --- a/security/smack/smack_lsm.c +++ b/security/smack/smack_lsm.c | |||
@@ -4333,6 +4333,12 @@ static int smack_key_permission(key_ref_t key_ref, | |||
4333 | int request = 0; | 4333 | int request = 0; |
4334 | int rc; | 4334 | int rc; |
4335 | 4335 | ||
4336 | /* | ||
4337 | * Validate requested permissions | ||
4338 | */ | ||
4339 | if (perm & ~KEY_NEED_ALL) | ||
4340 | return -EINVAL; | ||
4341 | |||
4336 | keyp = key_ref_to_ptr(key_ref); | 4342 | keyp = key_ref_to_ptr(key_ref); |
4337 | if (keyp == NULL) | 4343 | if (keyp == NULL) |
4338 | return -EINVAL; | 4344 | return -EINVAL; |
@@ -4356,10 +4362,10 @@ static int smack_key_permission(key_ref_t key_ref, | |||
4356 | ad.a.u.key_struct.key = keyp->serial; | 4362 | ad.a.u.key_struct.key = keyp->serial; |
4357 | ad.a.u.key_struct.key_desc = keyp->description; | 4363 | ad.a.u.key_struct.key_desc = keyp->description; |
4358 | #endif | 4364 | #endif |
4359 | if (perm & KEY_NEED_READ) | 4365 | if (perm & (KEY_NEED_READ | KEY_NEED_SEARCH | KEY_NEED_VIEW)) |
4360 | request = MAY_READ; | 4366 | request |= MAY_READ; |
4361 | if (perm & (KEY_NEED_WRITE | KEY_NEED_LINK | KEY_NEED_SETATTR)) | 4367 | if (perm & (KEY_NEED_WRITE | KEY_NEED_LINK | KEY_NEED_SETATTR)) |
4362 | request = MAY_WRITE; | 4368 | request |= MAY_WRITE; |
4363 | rc = smk_access(tkp, keyp->security, request, &ad); | 4369 | rc = smk_access(tkp, keyp->security, request, &ad); |
4364 | rc = smk_bu_note("key access", tkp, keyp->security, request, rc); | 4370 | rc = smk_bu_note("key access", tkp, keyp->security, request, rc); |
4365 | return rc; | 4371 | return rc; |