aboutsummaryrefslogtreecommitdiffstats
path: root/security/keys/keyring.c
diff options
context:
space:
mode:
authorDavid Howells <dhowells@redhat.com>2012-05-11 05:56:56 -0400
committerDavid Howells <dhowells@redhat.com>2012-05-11 05:56:56 -0400
commitfd75815f727f157a05f4c96b5294a4617c0557da (patch)
treeb2e76abf176d37b5d810b0c813b8c0219754b88c /security/keys/keyring.c
parent31d5a79d7f3d436da176a78ebc12d53c06da402e (diff)
KEYS: Add invalidation support
Add support for invalidating a key - which renders it immediately invisible to further searches and causes the garbage collector to immediately wake up, remove it from keyrings and then destroy it when it's no longer referenced. It's better not to do this with keyctl_revoke() as that marks the key to start returning -EKEYREVOKED to searches when what is actually desired is to have the key refetched. To invalidate a key the caller must be granted SEARCH permission by the key. This may be too strict. It may be better to also permit invalidation if the caller has any of READ, WRITE or SETATTR permission. The primary use for this is to evict keys that are cached in special keyrings, such as the DNS resolver or an ID mapper. Signed-off-by: David Howells <dhowells@redhat.com>
Diffstat (limited to 'security/keys/keyring.c')
-rw-r--r--security/keys/keyring.c25
1 files changed, 11 insertions, 14 deletions
diff --git a/security/keys/keyring.c b/security/keys/keyring.c
index 89d02cfb00c..7445875f681 100644
--- a/security/keys/keyring.c
+++ b/security/keys/keyring.c
@@ -382,13 +382,17 @@ key_ref_t keyring_search_aux(key_ref_t keyring_ref,
382 /* otherwise, the top keyring must not be revoked, expired, or 382 /* otherwise, the top keyring must not be revoked, expired, or
383 * negatively instantiated if we are to search it */ 383 * negatively instantiated if we are to search it */
384 key_ref = ERR_PTR(-EAGAIN); 384 key_ref = ERR_PTR(-EAGAIN);
385 if (kflags & ((1 << KEY_FLAG_REVOKED) | (1 << KEY_FLAG_NEGATIVE)) || 385 if (kflags & ((1 << KEY_FLAG_INVALIDATED) |
386 (1 << KEY_FLAG_REVOKED) |
387 (1 << KEY_FLAG_NEGATIVE)) ||
386 (keyring->expiry && now.tv_sec >= keyring->expiry)) 388 (keyring->expiry && now.tv_sec >= keyring->expiry))
387 goto error_2; 389 goto error_2;
388 390
389 /* start processing a new keyring */ 391 /* start processing a new keyring */
390descend: 392descend:
391 if (test_bit(KEY_FLAG_REVOKED, &keyring->flags)) 393 kflags = keyring->flags;
394 if (kflags & ((1 << KEY_FLAG_INVALIDATED) |
395 (1 << KEY_FLAG_REVOKED)))
392 goto not_this_keyring; 396 goto not_this_keyring;
393 397
394 keylist = rcu_dereference(keyring->payload.subscriptions); 398 keylist = rcu_dereference(keyring->payload.subscriptions);
@@ -406,9 +410,10 @@ descend:
406 if (key->type != type) 410 if (key->type != type)
407 continue; 411 continue;
408 412
409 /* skip revoked keys and expired keys */ 413 /* skip invalidated, revoked and expired keys */
410 if (!no_state_check) { 414 if (!no_state_check) {
411 if (kflags & (1 << KEY_FLAG_REVOKED)) 415 if (kflags & ((1 << KEY_FLAG_INVALIDATED) |
416 (1 << KEY_FLAG_REVOKED)))
412 continue; 417 continue;
413 418
414 if (key->expiry && now.tv_sec >= key->expiry) 419 if (key->expiry && now.tv_sec >= key->expiry)
@@ -559,7 +564,8 @@ key_ref_t __keyring_search_one(key_ref_t keyring_ref,
559 key->type->match(key, description)) && 564 key->type->match(key, description)) &&
560 key_permission(make_key_ref(key, possessed), 565 key_permission(make_key_ref(key, possessed),
561 perm) == 0 && 566 perm) == 0 &&
562 !test_bit(KEY_FLAG_REVOKED, &key->flags) 567 !(key->flags & ((1 << KEY_FLAG_INVALIDATED) |
568 (1 << KEY_FLAG_REVOKED)))
563 ) 569 )
564 goto found; 570 goto found;
565 } 571 }
@@ -1177,15 +1183,6 @@ static void keyring_revoke(struct key *keyring)
1177} 1183}
1178 1184
1179/* 1185/*
1180 * Determine whether a key is dead.
1181 */
1182static bool key_is_dead(struct key *key, time_t limit)
1183{
1184 return test_bit(KEY_FLAG_DEAD, &key->flags) ||
1185 (key->expiry > 0 && key->expiry <= limit);
1186}
1187
1188/*
1189 * Collect garbage from the contents of a keyring, replacing the old list with 1186 * Collect garbage from the contents of a keyring, replacing the old list with
1190 * a new one with the pointers all shuffled down. 1187 * a new one with the pointers all shuffled down.
1191 * 1188 *