[PATCH v4 3/3] keys, dns: Allow key types (eg. DNS) to be reclaimed immediately on expiry
Simon Horman
horms at kernel.org
Sat Dec 23 08:36:12 PST 2023
+ Edward Adam Davis
On Thu, Dec 21, 2023 at 01:45:30PM +0000, David Howells wrote:
> If a key has an expiration time, then when that time passes, the key is
> left around for a certain amount of time before being collected (5 mins by
> default) so that EKEYEXPIRED can be returned instead of ENOKEY. This is a
> problem for DNS keys because we want to redo the DNS lookup immediately at
> that point.
>
> Fix this by allowing key types to be marked such that keys of that type
> don't have this extra period, but are reclaimed as soon as they expire and
> turn this on for dns_resolver-type keys. To make this easier to handle,
> key->expiry is changed to be permanent if TIME64_MAX rather than 0.
>
> Furthermore, give such new-style negative DNS results a 1s default expiry
> if no other expiry time is set rather than allowing it to stick around
> indefinitely. This shouldn't be zero as ls will follow a failing stat call
> immediately with a second with AT_SYMLINK_NOFOLLOW added.
>
> Fixes: 1a4240f4764a ("DNS: Separate out CIFS DNS Resolver code")
> Signed-off-by: David Howells <dhowells at redhat.com>
> Tested-by: Markus Suvanto <markus.suvanto at gmail.com>
...
> diff --git a/net/dns_resolver/dns_key.c b/net/dns_resolver/dns_key.c
> index 01e54b46ae0b..2a6d363763a2 100644
> --- a/net/dns_resolver/dns_key.c
> +++ b/net/dns_resolver/dns_key.c
> @@ -91,6 +91,7 @@ const struct cred *dns_resolver_cache;
> static int
> dns_resolver_preparse(struct key_preparsed_payload *prep)
> {
> + const struct dns_server_list_v1_header *v1;
> const struct dns_payload_header *bin;
> struct user_key_payload *upayload;
> unsigned long derrno;
> @@ -122,6 +123,13 @@ dns_resolver_preparse(struct key_preparsed_payload *prep)
> return -EINVAL;
> }
>
> + v1 = (const struct dns_server_list_v1_header *)bin;
> + if ((v1->status != DNS_LOOKUP_GOOD &&
> + v1->status != DNS_LOOKUP_GOOD_WITH_BAD)) {
> + if (prep->expiry == TIME64_MAX)
> + prep->expiry = ktime_get_real_seconds() + 1;
> + }
> +
> result_len = datalen;
> goto store_result;
> }
Hi David,
As has been pointed out by Edward Adam Davis, this may result
in a buffer overrun. Just above this hunk the following length
check occurs:
if (datalen <= sizeof(*bin))
return -EINVAL;
But the new code above reads beyond the end of sizeof(*bin).
Link: https://lore.kernel.org/netdev/tencent_7D663C8936BA96F837124A4474AF76ED6709@qq.com/
...
More information about the linux-afs
mailing list