[RFC PATCH 8/8] KEYS: Verify the key identity in __keyctl_unlink
Jarkko Sakkinen
jarkko at kernel.org
Mon Oct 19 14:25:08 UTC 2026
Let's define the following preconditions:
- Two keys: A and B.
- R is a keyring.
- Both have the same type/description/domain.
Then:
1. KEYCTL_LINK(A, R) => {A}
1. KEYCTL_LINK(B, R) => {B}
2. KEYCTL_UNLINK(A, R) => {}
Instead, verify key tidentity before unlinking, and return -ENOENT on
mismatch.
Cc: stable at vger.kernel.org
Fixes: b2a4df200d57 ("KEYS: Expand the capacity of a keyring")
Assisted-by: LLM
Signed-off-by: Jarkko Sakkinen <jarkko at kernel.org>
---
security/keys/keyring.c | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/security/keys/keyring.c b/security/keys/keyring.c
index 7143f3079d20..b025331488c5 100644
--- a/security/keys/keyring.c
+++ b/security/keys/keyring.c
@@ -1501,9 +1501,15 @@ static int __key_unlink_begin(struct key *keyring, struct key *key,
struct assoc_array_edit **_edit)
{
struct assoc_array_edit *edit;
+ const void *object;
BUG_ON(*_edit != NULL);
+ object = assoc_array_find(&keyring->keys, &keyring_assoc_array_ops,
+ &key->index_key);
+ if (!object || keyring_ptr_to_key(object) != key)
+ return -ENOENT;
+
edit = assoc_array_delete(&keyring->keys, &keyring_assoc_array_ops,
&key->index_key);
if (IS_ERR(edit))
--
2.47.3
More information about the Linux-security-module-archive
mailing list