request_asymmetric_key() checks the key ID against the experimental IMA blacklist keyring before looking up the key. The key ID in the security.ima xattr is only an abbreviated (32-bit) form of the SKID, so the key must be looked up first to obtain its complete SKID.
Look the key up, then pass the key found to is_key_blacklisted(), which compares its complete SKID against the system blacklist. A blacklisted key, or any error from the check, rejects the key. Signed-off-by: Mimi Zohar <[email protected]> --- security/integrity/digsig_asymmetric.c | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/security/integrity/digsig_asymmetric.c b/security/integrity/digsig_asymmetric.c index b4c23a0ed68f..731f3b0009ab 100644 --- a/security/integrity/digsig_asymmetric.c +++ b/security/integrity/digsig_asymmetric.c @@ -23,23 +23,12 @@ static struct key *request_asymmetric_key(struct key *keyring, uint32_t keyid) { struct key *key; char name[12]; + int ret; sprintf(name, "id:%08x", keyid); pr_debug("key search: \"%s\"\n", name); - key = get_ima_blacklist_keyring(); - if (key) { - key_ref_t kref; - - kref = keyring_search(make_key_ref(key, 1), - &key_type_asymmetric, name, true); - if (!IS_ERR(kref)) { - pr_err("Key '%s' is in ima_blacklist_keyring\n", name); - return ERR_PTR(-EKEYREJECTED); - } - } - if (keyring) { /* search in specific keyring */ key_ref_t kref; @@ -74,6 +63,18 @@ static struct key *request_asymmetric_key(struct key *keyring, uint32_t keyid) } } + /* + * Check the key actually selected by the lookup against the system + * blacklist, so that a revoked key stops verifying even if it cannot be + * removed from the keyring. Fail closed on any error. + */ + ret = is_key_blacklisted(key); + if (ret) { + pr_err("Key '%s' is blacklisted\n", name); + key_put(key); + return ERR_PTR(ret); + } + pr_debug("%s() = 0 [%x]\n", __func__, key_serial(key)); return key; -- 2.56.0
