Skip to contentSkip to conversation

KEYS: Reject restricted dest_keyring in construct_alloc_key()

PATCH In review Jarkko Sakkinen 2 participants 5 messages Oct 31

Subsystems (4)
lore
Share & tools
lore

Jarkko Sakkinen

author maintainer
#0 lore raw

PATCH 1/1 KEYS: Reject restricted dest_keyring in construct_alloc_key()

construct_alloc_key() links keys into dest_keyring without checking restrict_link, allowing keys whose key->state reaches KEY_IS_POSITIVE to remain in a restricted keyring when instantiated without relinking into dest_keyring. Reject restricted destination keyrings with -EPERM after __key_link_lock() unless KEY_ALLOC_BYPASS_RESTRICTION is set.

Fixes 5ac7eace2d00 ("KEYS: Add a facility to restrict new links into a keyring")
---
 security/keys/request_key.c | 5 +++++
 1 file changed, 5 insertions(+)
security/keys/request_key.c +5 -0
index 22cd66a44da5..d4611dd7cb49 100644
@@ -404,6 +404,11 @@ static int construct_alloc_key(struct keyring_search_context *ctx,
 		ret = __key_link_lock(dest_keyring, &key->index_key);
 		if (ret < 0)
 			goto link_lock_failed;
+
+		if (dest_keyring->restrict_link && !(flags & KEY_ALLOC_BYPASS_RESTRICTION)) {
+			ret = -EPERM;
+			goto link_alloc_failed_unlocked;
+		}
 	}
 
 	/*

--
2.47.3

author maintainer
#1 lore raw

PATCH 1/1 KEYS: Reject restricted dest_keyring in construct_alloc_key()

construct_alloc_key() links keys into dest_keyring without checking restrict_link, allowing keys whose key->state reaches KEY_IS_POSITIVE to remain in a restricted keyring when instantiated without relinking into dest_keyring. Reject restricted destination keyrings with -EPERM after __key_link_lock() unless KEY_ALLOC_BYPASS_RESTRICTION is set.

Fixes 5ac7eace2d00 ("KEYS: Add a facility to restrict new links into a keyring")
---
 security/keys/request_key.c | 5 +++++
 1 file changed, 5 insertions(+)
security/keys/request_key.c +5 -0
index 22cd66a44da5..d4611dd7cb49 100644
@@ -404,6 +404,11 @@ static int construct_alloc_key(struct keyring_search_context *ctx,
 		ret = __key_link_lock(dest_keyring, &key->index_key);
 		if (ret < 0)
 			goto link_lock_failed;
+
+		if (dest_keyring->restrict_link && !(flags & KEY_ALLOC_BYPASS_RESTRICTION)) {
+			ret = -EPERM;
+			goto link_alloc_failed_unlocked;
+		}
 	}
 
 	/*

--
2.47.3

#3 lore raw
In reply to Jarkko Sakkinen
Sashiko has reviewed this patch and found no issues.
Quoted 11 lines

construct_alloc_key() links keys into dest_keyring without checking restrict_link, allowing keys whose key->state reaches KEY_IS_POSITIVE to remain in a restricted keyring when instantiated without relinking into dest_keyring. Reject restricted destination keyrings with -EPERM after __key_link_lock() unless KEY_ALLOC_BYPASS_RESTRICTION is set.

Fixes 5ac7eace2d00 ("KEYS: Add a facility to restrict new links into a keyring")

Sashiko has reviewed this patch and found no issues.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
#2 lore raw
In reply to Jarkko Sakkinen
Sashiko has reviewed this patch and found no issues.
Quoted 11 lines

construct_alloc_key() links keys into dest_keyring without checking restrict_link, allowing keys whose key->state reaches KEY_IS_POSITIVE to remain in a restricted keyring when instantiated without relinking into dest_keyring. Reject restricted destination keyrings with -EPERM after __key_link_lock() unless KEY_ALLOC_BYPASS_RESTRICTION is set.

Fixes 5ac7eace2d00 ("KEYS: Add a facility to restrict new links into a keyring")

Sashiko has reviewed this patch and found no issues.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
author maintainer
#4 lore raw
In reply to Jarkko Sakkinen
Quoted 11 lines · Jarkko Sakkinen

construct_alloc_key() links keys into dest_keyring without checking restrict_link, allowing keys whose key->state reaches KEY_IS_POSITIVE to remain in a restricted keyring when instantiated without relinking into dest_keyring. Reject restricted destination keyrings with -EPERM after __key_link_lock() unless KEY_ALLOC_BYPASS_RESTRICTION is set.

Fixes 5ac7eace2d00 ("KEYS: Add a facility to restrict new links into a keyring")

I don't understand why this came out twice. I must have forgot to add --dry-run when I trialed it. Sorry about that; was unintended.

Br, Jarkko