Skip to contentSkip to conversation

KEYS: remove unnecessary get/put of explicit dest_keyring

PATCH In review Eric Biggers 2 participants 5 messages Nov 20, 2017 – Nov 24, 2017

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 KEYS: remove unnecessary get/put of explicit dest_keyring

From: Eric Biggers <[email protected]>

In request_key_and_link(), in the case where the dest_keyring was explicitly specified, there is no need to get another reference to dest_keyring before calling key_link(), then drop it afterwards. This is because by definition, we already have a reference to dest_keyring.

This change is useful because we'll be making construct_get_dest_keyring() able to return an error code, and we don't want to have to handle that error here for no reason.

---
 security/keys/request_key.c | 2 --
 1 file changed, 2 deletions(-)
security/keys/request_key.c +0 -2
index e8036cd0ad54..c6880af8b411 100644
@@ -546,9 +546,7 @@ struct key *request_key_and_link(struct key_type *type,
 	if (!IS_ERR(key_ref)) {
 		key = key_ref_to_ptr(key_ref);
 		if (dest_keyring) {
-			construct_get_dest_keyring(&dest_keyring);
 			ret = key_link(dest_keyring, key);
-			key_put(dest_keyring);
 			if (ret < 0) {
 				key_put(key);
 				key = ERR_PTR(ret);
Signature · 1 line
2.15.0.448.gf294e3d99a-goog
maintainer
#1 lore raw

security/keys/request_key.c struct key *request_key_and_link(struct key_type *type, · line 549

Quoted 1 line · Eric Biggers
security/keys/request_key.c +0 -1
-			construct_get_dest_keyring(&dest_keyring);

This will break. construct_get_dest_keyring() does other things than just getting a ref on whatever dest_keyring points to.

David

#2 lore raw
Quoted 7 lines · David Howells

security/keys/request_key.c struct key *request_key_and_link(struct key_type *type, · line 549

Quoted 1 line · Eric Biggers
security/keys/request_key.c +0 -1
-			construct_get_dest_keyring(&dest_keyring);

This will break. construct_get_dest_keyring() does other things than just getting a ref on whatever dest_keyring points to.

Not if dest_keyring is non-NULL (i.e. explicitly specified), which it is in this case.

Eric

maintainer
#3 lore raw
Quoted 8 lines · Eric Biggers
Quoted 5 lines

security/keys/request_key.c struct key *request_key_and_link(struct key_type *type, · line 549

Quoted 1 line
security/keys/request_key.c +0 -1
-			construct_get_dest_keyring(&dest_keyring);

This will break. construct_get_dest_keyring() does other things than just getting a ref on whatever dest_keyring points to.

Not if dest_keyring is non-NULL (i.e. explicitly specified), which it is in this case.

Actually, you're right.

David

maintainer
#4 lore raw
In reply to Eric Biggers

security/keys/request_key.c struct key *request_key_and_link(struct key_type *type, · line 549

Quoted 2 lines · Eric Biggers
security/keys/request_key.c +0 -1
 		if (dest_keyring) {
-			construct_get_dest_keyring(&dest_keyring);

Actually, I think I have the order of these lines inverted. construct_get_dest_keyring() can actually return without setting dest_keyring to anything. This didn't used to be the case, but now that the user-session keyring is made lazily, there's no guaranteed fallback.

David