Skip to content

Commit 61ea0c0

Browse files
committed
KEYS: Skip key state checks when checking for possession
Skip key state checks (invalidation, revocation and expiration) when checking for possession. Without this, keys that have been marked invalid, revoked keys and expired keys are not given a possession attribute - which means the possessor is not granted any possession permits and cannot do anything with them unless they also have one a user, group or other permit. This causes failures in the keyutils test suite's revocation and expiration tests now that commit 96b5c8f reduced the initial permissions granted to a key. The failures are due to accesses to revoked and expired keys being given EACCES instead of EKEYREVOKED or EKEYEXPIRED. Signed-off-by: David Howells <[email protected]>
1 parent 5a5f2ac commit 61ea0c0

File tree

4 files changed

+11
-6
lines changed

4 files changed

+11
-6
lines changed

security/keys/internal.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ extern key_ref_t search_my_process_keyrings(struct key_type *type,
124124
extern key_ref_t search_process_keyrings(struct key_type *type,
125125
const void *description,
126126
key_match_func_t match,
127+
bool no_state_check,
127128
const struct cred *cred);
128129

129130
extern struct key *find_keyring_by_name(const char *name, bool skip_perm_check);

security/keys/process_keys.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -440,6 +440,7 @@ key_ref_t search_my_process_keyrings(struct key_type *type,
440440
key_ref_t search_process_keyrings(struct key_type *type,
441441
const void *description,
442442
key_match_func_t match,
443+
bool no_state_check,
443444
const struct cred *cred)
444445
{
445446
struct request_key_auth *rka;
@@ -448,7 +449,7 @@ key_ref_t search_process_keyrings(struct key_type *type,
448449
might_sleep();
449450

450451
key_ref = search_my_process_keyrings(type, description, match,
451-
false, cred);
452+
no_state_check, cred);
452453
if (!IS_ERR(key_ref))
453454
goto found;
454455
err = key_ref;
@@ -468,7 +469,8 @@ key_ref_t search_process_keyrings(struct key_type *type,
468469
rka = cred->request_key_auth->payload.data;
469470

470471
key_ref = search_process_keyrings(type, description,
471-
match, rka->cred);
472+
match, no_state_check,
473+
rka->cred);
472474

473475
up_read(&cred->request_key_auth->sem);
474476

@@ -675,7 +677,7 @@ key_ref_t lookup_user_key(key_serial_t id, unsigned long lflags,
675677
/* check to see if we possess the key */
676678
skey_ref = search_process_keyrings(key->type, key,
677679
lookup_user_key_possessed,
678-
cred);
680+
true, cred);
679681

680682
if (!IS_ERR(skey_ref)) {
681683
key_put(key);

security/keys/request_key.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,8 @@ static int construct_alloc_key(struct key_type *type,
390390
* waited for locks */
391391
mutex_lock(&key_construction_mutex);
392392

393-
key_ref = search_process_keyrings(type, description, type->match, cred);
393+
key_ref = search_process_keyrings(type, description, type->match,
394+
false, cred);
394395
if (!IS_ERR(key_ref))
395396
goto key_already_present;
396397

@@ -539,7 +540,8 @@ struct key *request_key_and_link(struct key_type *type,
539540
dest_keyring, flags);
540541

541542
/* search all the process keyrings for a key */
542-
key_ref = search_process_keyrings(type, description, type->match, cred);
543+
key_ref = search_process_keyrings(type, description, type->match,
544+
false, cred);
543545

544546
if (!IS_ERR(key_ref)) {
545547
key = key_ref_to_ptr(key_ref);

security/keys/request_key_auth.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ struct key *key_get_instantiation_authkey(key_serial_t target_id)
247247
&key_type_request_key_auth,
248248
(void *) (unsigned long) target_id,
249249
key_get_instantiation_authkey_match,
250-
cred);
250+
false, cred);
251251

252252
if (IS_ERR(authkey_ref)) {
253253
authkey = ERR_CAST(authkey_ref);

0 commit comments

Comments
 (0)