Skip to contentSkip to conversation

keys: Fix overwrite of key expiration on instantiation

PATCH In review Silvio Gissi 2 participants 3 messages Mar 15, 2024 – Mar 19, 2024

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

PATCH 1/1 keys: Fix overwrite of key expiration on instantiation

The expiry time of a key is unconditionally overwritten during instantiation, defaulting to turn it permanent. This causes a problem for DNS resolution as the expiration set by user-space is overwritten to TIME64_MAX, disabling further DNS updates. Fix this by restoring the condition that key_set_expiry is only called when the pre-parser sets a specific expiry.

Fixes 39299bdd2546 ("keys, dns: Allow key types (eg. DNS) to be reclaimed immediately on expiry")
cc David Howells <[email protected]>
cc Hazem Mohamed Abuelfotoh <[email protected]>
---
 security/keys/key.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
security/keys/key.c +2 -1
index 560790038329..0aa5f01d16ff 100644
@@ -463,7 +463,8 @@ static int __key_instantiate_and_link(struct key *key,
 			if (authkey)
 				key_invalidate(authkey);
 
-			key_set_expiry(key, prep->expiry);
+			if (prep->expiry != TIME64_MAX)
+				key_set_expiry(key, prep->expiry);
 		}
 	}
 
Signature · 1 line
2.34.1
maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 25 lines · Silvio Gissi

The expiry time of a key is unconditionally overwritten during instantiation, defaulting to turn it permanent. This causes a problem for DNS resolution as the expiration set by user-space is overwritten to TIME64_MAX, disabling further DNS updates. Fix this by restoring the condition that key_set_expiry is only called when the pre-parser sets a specific expiry.

Fixes 39299bdd2546 ("keys, dns: Allow key types (eg. DNS) to be reclaimed immediately on expiry")
cc David Howells <[email protected]>
cc Hazem Mohamed Abuelfotoh <[email protected]>
---
 security/keys/key.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
security/keys/key.c +0 -0
index 560790038329..0aa5f01d16ff 100644

security/keys/key.c static int __key_instantiate_and_link(struct key *key, · line 470

Quoted 9 lines
security/keys/key.c +2 -1
@@ -463,7 +463,8 @@ static int __key_instantiate_and_link(struct key *key,
 			if (authkey)
 				key_invalidate(authkey);
 
-			key_set_expiry(key, prep->expiry);
+			if (prep->expiry != TIME64_MAX)
+				key_set_expiry(key, prep->expiry);
 		}
 	}
 

I checked the original commit and reflected to the fix:

David, I can pick this one too as I'm anyway sending PR for rc2?

[1] https://lore.kernel.org/keyrings/[email protected]/

BR, Jarkko

maintainer
#2 lore raw
Quoted 38 lines · Jarkko Sakkinen
Quoted 25 lines · Silvio Gissi

The expiry time of a key is unconditionally overwritten during instantiation, defaulting to turn it permanent. This causes a problem for DNS resolution as the expiration set by user-space is overwritten to TIME64_MAX, disabling further DNS updates. Fix this by restoring the condition that key_set_expiry is only called when the pre-parser sets a specific expiry.

Fixes 39299bdd2546 ("keys, dns: Allow key types (eg. DNS) to be reclaimed immediately on expiry")
cc David Howells <[email protected]>
cc Hazem Mohamed Abuelfotoh <[email protected]>
---
 security/keys/key.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
security/keys/key.c +0 -0
index 560790038329..0aa5f01d16ff 100644

security/keys/key.c static int __key_instantiate_and_link(struct key *key, · line 470

Quoted 9 lines
security/keys/key.c +2 -1
@@ -463,7 +463,8 @@ static int __key_instantiate_and_link(struct key *key,
 			if (authkey)
 				key_invalidate(authkey);
 
-			key_set_expiry(key, prep->expiry);
+			if (prep->expiry != TIME64_MAX)
+				key_set_expiry(key, prep->expiry);
 		}
 	}
 

I checked the original commit and reflected to the fix:

Quoted 5 lines

David, I can pick this one too as I'm anyway sending PR for rc2?

[1] https://lore.kernel.org/keyrings/[email protected]/

I've applied this to my tree. Can drop on request but otherwise including to rc2 PR.

BR, Jarkko