Skip to content

Commit

Permalink
KEYS: Load key expiry time atomically in keyring_search_iterator()
Browse files Browse the repository at this point in the history
Similar to the case for key_validate(), we should load the key ->expiry
once atomically in keyring_search_iterator(), since it can be changed
concurrently with the flags whenever the key semaphore isn't held.

Signed-off-by: Eric Biggers <[email protected]>
Signed-off-by: David Howells <[email protected]>
  • Loading branch information
ebiggers authored and dhowells committed Oct 18, 2017
1 parent 1823d47 commit 9d6c871
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion security/keys/keyring.c
Original file line number Diff line number Diff line change
Expand Up @@ -566,14 +566,16 @@ static int keyring_search_iterator(const void *object, void *iterator_data)

/* skip invalidated, revoked and expired keys */
if (ctx->flags & KEYRING_SEARCH_DO_STATE_CHECK) {
time_t expiry = READ_ONCE(key->expiry);

if (kflags & ((1 << KEY_FLAG_INVALIDATED) |
(1 << KEY_FLAG_REVOKED))) {
ctx->result = ERR_PTR(-EKEYREVOKED);
kleave(" = %d [invrev]", ctx->skipped_ret);
goto skipped;
}

if (key->expiry && ctx->now.tv_sec >= key->expiry) {
if (expiry && ctx->now.tv_sec >= expiry) {
if (!(ctx->flags & KEYRING_SEARCH_SKIP_EXPIRED))
ctx->result = ERR_PTR(-EKEYEXPIRED);
kleave(" = %d [expire]", ctx->skipped_ret);
Expand Down

0 comments on commit 9d6c871

Please sign in to comment.