Commit 054f6180 authored by David Howells's avatar David Howells

KEYS: Simplify KEYRING_SEARCH_{NO,DO}_STATE_CHECK flags

Simplify KEYRING_SEARCH_{NO,DO}_STATE_CHECK flags to be two variations of the
same flag.  They are effectively mutually exclusive and one or the other
should be provided, but not both.

Keyring cycle detection and key possession determination are the only things
that set NO_STATE_CHECK, except that neither flag really does anything there
because neither purpose makes use of the keyring_search_iterator() function,
but rather provides their own.

For cycle detection we definitely want to check inside of expired keyrings,
just so that we don't create a cycle we can't get rid of.  Revoked keyrings
are cleared at revocation time and can't then be reused, so shouldn't be a
problem either way.

For possession determination, we *might* want to validate each keyring before
searching it: do you possess a key that's hidden behind an expired or just
plain inaccessible keyring?  Currently, the answer is yes.  Note that you
cannot, however, possess a key behind a revoked keyring because they are
cleared on revocation.

keyring_search() sets DO_STATE_CHECK, which is correct.

request_key_and_link() currently doesn't specify whether to check the key
state or not - but it should set DO_STATE_CHECK.

key_get_instantiation_authkey() also currently doesn't specify whether to
check the key state or not - but it probably should also set DO_STATE_CHECK.
Signed-off-by: default avatarDavid Howells <dhowells@redhat.com>
Tested-by: default avatarChuck Lever <chuck.lever@oracle.com>
parent aa9d4437
...@@ -628,6 +628,10 @@ static bool search_nested_keyrings(struct key *keyring, ...@@ -628,6 +628,10 @@ static bool search_nested_keyrings(struct key *keyring,
ctx->index_key.type->name, ctx->index_key.type->name,
ctx->index_key.description); ctx->index_key.description);
#define STATE_CHECKS (KEYRING_SEARCH_NO_STATE_CHECK | KEYRING_SEARCH_DO_STATE_CHECK)
BUG_ON((ctx->flags & STATE_CHECKS) == 0 ||
(ctx->flags & STATE_CHECKS) == STATE_CHECKS);
if (ctx->index_key.description) if (ctx->index_key.description)
ctx->index_key.desc_len = strlen(ctx->index_key.description); ctx->index_key.desc_len = strlen(ctx->index_key.description);
...@@ -637,7 +641,6 @@ static bool search_nested_keyrings(struct key *keyring, ...@@ -637,7 +641,6 @@ static bool search_nested_keyrings(struct key *keyring,
if (ctx->match_data.lookup_type == KEYRING_SEARCH_LOOKUP_ITERATE || if (ctx->match_data.lookup_type == KEYRING_SEARCH_LOOKUP_ITERATE ||
keyring_compare_object(keyring, &ctx->index_key)) { keyring_compare_object(keyring, &ctx->index_key)) {
ctx->skipped_ret = 2; ctx->skipped_ret = 2;
ctx->flags |= KEYRING_SEARCH_DO_STATE_CHECK;
switch (ctx->iterator(keyring_key_to_ptr(keyring), ctx)) { switch (ctx->iterator(keyring_key_to_ptr(keyring), ctx)) {
case 1: case 1:
goto found; goto found;
...@@ -649,8 +652,6 @@ static bool search_nested_keyrings(struct key *keyring, ...@@ -649,8 +652,6 @@ static bool search_nested_keyrings(struct key *keyring,
} }
ctx->skipped_ret = 0; ctx->skipped_ret = 0;
if (ctx->flags & KEYRING_SEARCH_NO_STATE_CHECK)
ctx->flags &= ~KEYRING_SEARCH_DO_STATE_CHECK;
/* Start processing a new keyring */ /* Start processing a new keyring */
descend_to_keyring: descend_to_keyring:
......
...@@ -516,6 +516,7 @@ struct key *request_key_and_link(struct key_type *type, ...@@ -516,6 +516,7 @@ struct key *request_key_and_link(struct key_type *type,
.match_data.cmp = key_default_cmp, .match_data.cmp = key_default_cmp,
.match_data.raw_data = description, .match_data.raw_data = description,
.match_data.lookup_type = KEYRING_SEARCH_LOOKUP_DIRECT, .match_data.lookup_type = KEYRING_SEARCH_LOOKUP_DIRECT,
.flags = KEYRING_SEARCH_DO_STATE_CHECK,
}; };
struct key *key; struct key *key;
key_ref_t key_ref; key_ref_t key_ref;
......
...@@ -249,6 +249,7 @@ struct key *key_get_instantiation_authkey(key_serial_t target_id) ...@@ -249,6 +249,7 @@ struct key *key_get_instantiation_authkey(key_serial_t target_id)
.match_data.cmp = key_default_cmp, .match_data.cmp = key_default_cmp,
.match_data.raw_data = description, .match_data.raw_data = description,
.match_data.lookup_type = KEYRING_SEARCH_LOOKUP_DIRECT, .match_data.lookup_type = KEYRING_SEARCH_LOOKUP_DIRECT,
.flags = KEYRING_SEARCH_DO_STATE_CHECK,
}; };
struct key *authkey; struct key *authkey;
key_ref_t authkey_ref; key_ref_t authkey_ref;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment