···309309310310extern void key_set_timeout(struct key *, unsigned);311311312312+/*313313+ * The permissions required on a key that we're looking up.314314+ */315315+#define KEY_NEED_VIEW 0x01 /* Require permission to view attributes */316316+#define KEY_NEED_READ 0x02 /* Require permission to read content */317317+#define KEY_NEED_WRITE 0x04 /* Require permission to update / modify */318318+#define KEY_NEED_SEARCH 0x08 /* Require permission to search (keyring) or find (key) */319319+#define KEY_NEED_LINK 0x10 /* Require permission to link */320320+#define KEY_NEED_SETATTR 0x20 /* Require permission to change attributes */321321+#define KEY_NEED_ALL 0x3f /* All the above permissions */322322+312323/**313324 * key_is_instantiated - Determine if a key has been positively instantiated314325 * @key: The key to check.
···176176/*177177 * Check to see whether permission is granted to use a key in the desired way.178178 */179179-static inline int key_permission(const key_ref_t key_ref, key_perm_t perm)179179+static inline int key_permission(const key_ref_t key_ref, unsigned perm)180180{181181 return key_task_permission(key_ref, current_cred(), perm);182182}183183-184184-/* required permissions */185185-#define KEY_VIEW 0x01 /* require permission to view attributes */186186-#define KEY_READ 0x02 /* require permission to read content */187187-#define KEY_WRITE 0x04 /* require permission to update / modify */188188-#define KEY_SEARCH 0x08 /* require permission to search (keyring) or find (key) */189189-#define KEY_LINK 0x10 /* require permission to link */190190-#define KEY_SETATTR 0x20 /* require permission to change attributes */191191-#define KEY_ALL 0x3f /* all the above permissions */192183193184/*194185 * Authorisation record for request_key().
+3-3
security/keys/key.c
···714714 int ret;715715716716 /* need write permission on the key to update it */717717- ret = key_permission(key_ref, KEY_WRITE);717717+ ret = key_permission(key_ref, KEY_NEED_WRITE);718718 if (ret < 0)719719 goto error;720720···838838839839 /* if we're going to allocate a new key, we're going to have840840 * to modify the keyring */841841- ret = key_permission(keyring_ref, KEY_WRITE);841841+ ret = key_permission(keyring_ref, KEY_NEED_WRITE);842842 if (ret < 0) {843843 key_ref = ERR_PTR(ret);844844 goto error_link_end;···928928 key_check(key);929929930930 /* the key must be writable */931931- ret = key_permission(key_ref, KEY_WRITE);931931+ ret = key_permission(key_ref, KEY_NEED_WRITE);932932 if (ret < 0)933933 goto error;934934
+22-22
security/keys/keyctl.c
···111111 }112112113113 /* find the target keyring (which must be writable) */114114- keyring_ref = lookup_user_key(ringid, KEY_LOOKUP_CREATE, KEY_WRITE);114114+ keyring_ref = lookup_user_key(ringid, KEY_LOOKUP_CREATE, KEY_NEED_WRITE);115115 if (IS_ERR(keyring_ref)) {116116 ret = PTR_ERR(keyring_ref);117117 goto error3;···195195 dest_ref = NULL;196196 if (destringid) {197197 dest_ref = lookup_user_key(destringid, KEY_LOOKUP_CREATE,198198- KEY_WRITE);198198+ KEY_NEED_WRITE);199199 if (IS_ERR(dest_ref)) {200200 ret = PTR_ERR(dest_ref);201201 goto error3;···253253 long ret;254254255255 lflags = create ? KEY_LOOKUP_CREATE : 0;256256- key_ref = lookup_user_key(id, lflags, KEY_SEARCH);256256+ key_ref = lookup_user_key(id, lflags, KEY_NEED_SEARCH);257257 if (IS_ERR(key_ref)) {258258 ret = PTR_ERR(key_ref);259259 goto error;···334334 }335335336336 /* find the target key (which must be writable) */337337- key_ref = lookup_user_key(id, 0, KEY_WRITE);337337+ key_ref = lookup_user_key(id, 0, KEY_NEED_WRITE);338338 if (IS_ERR(key_ref)) {339339 ret = PTR_ERR(key_ref);340340 goto error2;···365365 key_ref_t key_ref;366366 long ret;367367368368- key_ref = lookup_user_key(id, 0, KEY_WRITE);368368+ key_ref = lookup_user_key(id, 0, KEY_NEED_WRITE);369369 if (IS_ERR(key_ref)) {370370 ret = PTR_ERR(key_ref);371371 if (ret != -EACCES)372372 goto error;373373- key_ref = lookup_user_key(id, 0, KEY_SETATTR);373373+ key_ref = lookup_user_key(id, 0, KEY_NEED_SETATTR);374374 if (IS_ERR(key_ref)) {375375 ret = PTR_ERR(key_ref);376376 goto error;···401401402402 kenter("%d", id);403403404404- key_ref = lookup_user_key(id, 0, KEY_SEARCH);404404+ key_ref = lookup_user_key(id, 0, KEY_NEED_SEARCH);405405 if (IS_ERR(key_ref)) {406406 ret = PTR_ERR(key_ref);407407 goto error;···428428 key_ref_t keyring_ref;429429 long ret;430430431431- keyring_ref = lookup_user_key(ringid, KEY_LOOKUP_CREATE, KEY_WRITE);431431+ keyring_ref = lookup_user_key(ringid, KEY_LOOKUP_CREATE, KEY_NEED_WRITE);432432 if (IS_ERR(keyring_ref)) {433433 ret = PTR_ERR(keyring_ref);434434···470470 key_ref_t keyring_ref, key_ref;471471 long ret;472472473473- keyring_ref = lookup_user_key(ringid, KEY_LOOKUP_CREATE, KEY_WRITE);473473+ keyring_ref = lookup_user_key(ringid, KEY_LOOKUP_CREATE, KEY_NEED_WRITE);474474 if (IS_ERR(keyring_ref)) {475475 ret = PTR_ERR(keyring_ref);476476 goto error;477477 }478478479479- key_ref = lookup_user_key(id, KEY_LOOKUP_CREATE, KEY_LINK);479479+ key_ref = lookup_user_key(id, KEY_LOOKUP_CREATE, KEY_NEED_LINK);480480 if (IS_ERR(key_ref)) {481481 ret = PTR_ERR(key_ref);482482 goto error2;···505505 key_ref_t keyring_ref, key_ref;506506 long ret;507507508508- keyring_ref = lookup_user_key(ringid, 0, KEY_WRITE);508508+ keyring_ref = lookup_user_key(ringid, 0, KEY_NEED_WRITE);509509 if (IS_ERR(keyring_ref)) {510510 ret = PTR_ERR(keyring_ref);511511 goto error;···548548 char *tmpbuf;549549 long ret;550550551551- key_ref = lookup_user_key(keyid, KEY_LOOKUP_PARTIAL, KEY_VIEW);551551+ key_ref = lookup_user_key(keyid, KEY_LOOKUP_PARTIAL, KEY_NEED_VIEW);552552 if (IS_ERR(key_ref)) {553553 /* viewing a key under construction is permitted if we have the554554 * authorisation token handy */···639639 }640640641641 /* get the keyring at which to begin the search */642642- keyring_ref = lookup_user_key(ringid, 0, KEY_SEARCH);642642+ keyring_ref = lookup_user_key(ringid, 0, KEY_NEED_SEARCH);643643 if (IS_ERR(keyring_ref)) {644644 ret = PTR_ERR(keyring_ref);645645 goto error2;···649649 dest_ref = NULL;650650 if (destringid) {651651 dest_ref = lookup_user_key(destringid, KEY_LOOKUP_CREATE,652652- KEY_WRITE);652652+ KEY_NEED_WRITE);653653 if (IS_ERR(dest_ref)) {654654 ret = PTR_ERR(dest_ref);655655 goto error3;···676676677677 /* link the resulting key to the destination keyring if we can */678678 if (dest_ref) {679679- ret = key_permission(key_ref, KEY_LINK);679679+ ret = key_permission(key_ref, KEY_NEED_LINK);680680 if (ret < 0)681681 goto error6;682682···727727 key = key_ref_to_ptr(key_ref);728728729729 /* see if we can read it directly */730730- ret = key_permission(key_ref, KEY_READ);730730+ ret = key_permission(key_ref, KEY_NEED_READ);731731 if (ret == 0)732732 goto can_read_key;733733 if (ret != -EACCES)···799799 goto error;800800801801 key_ref = lookup_user_key(id, KEY_LOOKUP_CREATE | KEY_LOOKUP_PARTIAL,802802- KEY_SETATTR);802802+ KEY_NEED_SETATTR);803803 if (IS_ERR(key_ref)) {804804 ret = PTR_ERR(key_ref);805805 goto error;···905905 goto error;906906907907 key_ref = lookup_user_key(id, KEY_LOOKUP_CREATE | KEY_LOOKUP_PARTIAL,908908- KEY_SETATTR);908908+ KEY_NEED_SETATTR);909909 if (IS_ERR(key_ref)) {910910 ret = PTR_ERR(key_ref);911911 goto error;···947947948948 /* if a specific keyring is nominated by ID, then use that */949949 if (ringid > 0) {950950- dkref = lookup_user_key(ringid, KEY_LOOKUP_CREATE, KEY_WRITE);950950+ dkref = lookup_user_key(ringid, KEY_LOOKUP_CREATE, KEY_NEED_WRITE);951951 if (IS_ERR(dkref))952952 return PTR_ERR(dkref);953953 *_dest_keyring = key_ref_to_ptr(dkref);···13151315 long ret;1316131613171317 key_ref = lookup_user_key(id, KEY_LOOKUP_CREATE | KEY_LOOKUP_PARTIAL,13181318- KEY_SETATTR);13181318+ KEY_NEED_SETATTR);13191319 if (IS_ERR(key_ref)) {13201320 /* setting the timeout on a key under construction is permitted13211321 * if we have the authorisation token handy */···14181418 char *context;14191419 long ret;1420142014211421- key_ref = lookup_user_key(keyid, KEY_LOOKUP_PARTIAL, KEY_VIEW);14211421+ key_ref = lookup_user_key(keyid, KEY_LOOKUP_PARTIAL, KEY_NEED_VIEW);14221422 if (IS_ERR(key_ref)) {14231423 if (PTR_ERR(key_ref) != -EACCES)14241424 return PTR_ERR(key_ref);···14821482 struct cred *cred;14831483 int ret;1484148414851485- keyring_r = lookup_user_key(KEY_SPEC_SESSION_KEYRING, 0, KEY_LINK);14851485+ keyring_r = lookup_user_key(KEY_SPEC_SESSION_KEYRING, 0, KEY_NEED_LINK);14861486 if (IS_ERR(keyring_r))14871487 return PTR_ERR(keyring_r);14881488
+4-4
security/keys/keyring.c
···541541 /* key must have search permissions */542542 if (!(ctx->flags & KEYRING_SEARCH_NO_CHECK_PERM) &&543543 key_task_permission(make_key_ref(key, ctx->possessed),544544- ctx->cred, KEY_SEARCH) < 0) {544544+ ctx->cred, KEY_NEED_SEARCH) < 0) {545545 ctx->result = ERR_PTR(-EACCES);546546 kleave(" = %d [!perm]", ctx->skipped_ret);547547 goto skipped;···721721 /* Search a nested keyring */722722 if (!(ctx->flags & KEYRING_SEARCH_NO_CHECK_PERM) &&723723 key_task_permission(make_key_ref(key, ctx->possessed),724724- ctx->cred, KEY_SEARCH) < 0)724724+ ctx->cred, KEY_NEED_SEARCH) < 0)725725 continue;726726727727 /* stack the current position */···843843 return ERR_PTR(-ENOTDIR);844844845845 if (!(ctx->flags & KEYRING_SEARCH_NO_CHECK_PERM)) {846846- err = key_task_permission(keyring_ref, ctx->cred, KEY_SEARCH);846846+ err = key_task_permission(keyring_ref, ctx->cred, KEY_NEED_SEARCH);847847 if (err < 0)848848 return ERR_PTR(err);849849 }···973973974974 if (!skip_perm_check &&975975 key_permission(make_key_ref(keyring, 0),976976- KEY_SEARCH) < 0)976976+ KEY_NEED_SEARCH) < 0)977977 continue;978978979979 /* we've got a match but we might end up racing with