keys, dns: drop unused upayload->data NUL terminator
Subsystems (3)
PATCH v3 1/2 keys, dns: drop unused upayload->data NUL terminator
->data includes an extra NUL terminator despite never being used as a C string and only accessing ->datalen bytes. Remove the redundant NUL terminator and allocate one byte less in dns_resolver_preparse().
---
Changes in v3:
- Update commit message
- v2: https://lore.kernel.org/lkml/[email protected]/
Changes in v2:
- No changes in patch 1/2
- v1: https://lore.kernel.org/lkml/[email protected]/
--- net/dns_resolver/dns_key.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
net/dns_resolver/dns_key.c +1 -2
@@ -203,7 +203,7 @@ dns_resolver_preparse(struct key_preparsed_payload *prep)kdebug ("store result" ); prep->quotalen = result_len; - upayload =kmalloc_flex (*upayload, data, result_len +1 ); + upayload =kmalloc_flex (*upayload, data, result_len);if (!upayload) {kleave (" = -ENOMEM" );return -ENOMEM ;
@@ -211,7 +211,6 @@ dns_resolver_preparse(struct key_preparsed_payload *prep) upayload->datalen = result_len;memcpy (upayload->data, data, result_len); - upayload->data[result_len] ='\0' ; prep->payload.data[dns_key_data] = upayload;kleave (" = 0" );
PATCH v3 2/2 KEYS: annotate struct user_key_payload with __counted_by
Add the __counted_by() compiler attribute to the flexible array member 'data' to improve bounds checking via CONFIG_UBSAN_BOUNDS and CONFIG_FORTIFY_SOURCE.
---
Changes in v3:
- Formatting only, do not split the declaration into two lines (Jarkko)
- v2: https://lore.kernel.org/lkml/[email protected]/
Changes in v2:
- Use __aligned(8) as suggested by David
- v1: https://lore.kernel.org/lkml/[email protected]/
--- include/keys/user-type.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
include/keys/user-type.h +1 -1
@@ -27,7 +27,7 @@struct user_key_payload {struct rcu_head rcu;/* RCU destructor */ unsigned short datalen;/* length of this data */ -char data[]__aligned(__alignof__(u64)) ;/* actual data */ + char data[] __aligned(8) __counted_by(datalen); /* actual data */ };extern struct key_type key_type_user;
Jarkko Sakkinen
maintainerRe: [PATCH net-next v3 2/2] KEYS: annotate struct user_key_payload with __counted_by
Quoted 5 lines · Thorsten Blum
Add the
__counted_by()compiler attribute to the flexible array member 'data' to improve bounds checking viaCONFIG_UBSAN_BOUNDSandCONFIG_FORTIFY_SOURCE.Signed-off-by Thorsten Blum <[email protected]>
This is again a crippled commit message.
I.e. this requires either knowing, remembering and/or cross-referencing "bunch of" unrelated to keyring.
I gave up already.
BR, Jarkko
Quoted 25 lines
---
Changes in v3:
- Formatting only, do not split the declaration into two lines (Jarkko)
- v2: https://lore.kernel.org/lkml/[email protected]/Changes in v2:
- Use__aligned(8)as suggested by David
- v1: https://lore.kernel.org/lkml/[email protected]/--- include/keys/user-type.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)include/keys/user-type.h +1
-1@@ -27,7 +27,7 @@struct user_key_payload {struct rcu_head rcu;/* RCU destructor */ unsigned short datalen;/* length of this data */ -char data[]__aligned(__alignof__(u64)) ;/* actual data */ + char data[] __aligned(8) __counted_by(datalen); /* actual data */ };extern struct key_type key_type_user;
Re: [PATCH net-next v3 2/2] KEYS: annotate struct user_key_payload with __counted_by
Quoted 11 lines · Jarkko Sakkinen
Quoted 5 lines · Thorsten Blum
Add the
__counted_by()compiler attribute to the flexible array member 'data' to improve bounds checking viaCONFIG_UBSAN_BOUNDSandCONFIG_FORTIFY_SOURCE.Signed-off-by Thorsten Blum <[email protected]>This is again a crippled commit message.
I.e. this requires either knowing, remembering and/or cross-referencing "bunch of" unrelated to keyring.
I kept the commit message short because it follows the same pattern as many other __counted_by() patches that have been accepted across several subsystems.
I'm not sure which part of the message you want expanded. Could you be more specific?
Thanks,
Thorsten
Jarkko Sakkinen
maintainerRe: [PATCH net-next v3 2/2] KEYS: annotate struct user_key_payload with __counted_by
Quoted 13 lines · Thorsten Blum
Quoted 11 lines · Jarkko Sakkinen
Quoted 5 lines · Thorsten Blum
Add the
__counted_by()compiler attribute to the flexible array member 'data' to improve bounds checking viaCONFIG_UBSAN_BOUNDSandCONFIG_FORTIFY_SOURCE.Signed-off-by Thorsten Blum <[email protected]>This is again a crippled commit message.
I.e. this requires either knowing, remembering and/or cross-referencing "bunch of" unrelated to keyring.
Quoted 6 lines
I kept the commit message short because it follows the same pattern as many other
__counted_by()patches that have been accepted across several subsystems.I'm not sure which part of the message you want expanded. Could you be more specific?
"Describe your problem. Whether your patch is a one-line bug fix or 5000 lines of a new feature, there must be an underlying problem that motivated you to do this work. Convince the reviewer that there is a problem worth fixing and that it makes sense for them to read past the first paragraph."
This is a direct quote from https://docs.kernel.org/process/submitting-patches.html#describe-your-changes
Quoted 3 lines
Thanks,
Thorsten
BR, Jarkko
Jarkko Sakkinen
maintainerRe: [PATCH net-next v3 2/2] KEYS: annotate struct user_key_payload with __counted_by
Quoted 21 lines · Jarkko Sakkinen
Quoted 13 lines · Thorsten Blum
Quoted 11 lines · Jarkko Sakkinen
Quoted 5 lines · Thorsten Blum
Add the
__counted_by()compiler attribute to the flexible array member 'data' to improve bounds checking viaCONFIG_UBSAN_BOUNDSandCONFIG_FORTIFY_SOURCE.Signed-off-by Thorsten Blum <[email protected]>This is again a crippled commit message.
I.e. this requires either knowing, remembering and/or cross-referencing "bunch of" unrelated to keyring.
Quoted 6 lines
I kept the commit message short because it follows the same pattern as many other
__counted_by()patches that have been accepted across several subsystems.I'm not sure which part of the message you want expanded. Could you be more specific?
Quoted 7 lines
"Describe your problem. Whether your patch is a one-line bug fix or 5000 lines of a new feature, there must be an underlying problem that motivated you to do this work. Convince the reviewer that there is a problem worth fixing and that it makes sense for them to read past the first paragraph."
This is a direct quote from https://docs.kernel.org/process/submitting-patches.html#describe-your-changes
And there's pretty good reasons to do this too as commit message is not just a cover leter for a patch. It's also reminder in the commit log why something was done.
BR, Jarkko
Re: [PATCH net-next v3 2/2] KEYS: annotate struct user_key_payload with __counted_by
In reply to Thorsten BlumQuoted 8 lines · Thorsten Blum
Quoted 7 lines · Jarkko Sakkinen
Quoted 5 lines · Thorsten Blum
Add the
__counted_by()compiler attribute to the flexible array member 'data' to improve bounds checking viaCONFIG_UBSAN_BOUNDSandCONFIG_FORTIFY_SOURCE.Signed-off-by Thorsten Blum <[email protected]>
Quoted 8 lines
Quoted 4 lines
This is again a crippled commit message.
I.e. this requires either knowing, remembering and/or cross-referencing "bunch of" unrelated to keyring.
I kept the commit message short because it follows the same pattern as many other
__counted_by()patches that have been accepted across several subsystems.
That's clearly not a good example of how to document changes, so I wouldn't use it as a reference.
-Gustavo
Jakub Kicinski
maintainerQuoted 1 line · On Mon, 27 Apr 2026 13:44:23 +0200 Thorsten Blum wrote:
Subject: [PATCH net-next v3 1/2] keys, dns: drop unused
upayload->dataNUL terminator
to be clear - I expect "keys" maintainers to handle this, not net-next directly.
Jarkko Sakkinen
maintainerQuoted 5 lines · Thorsten Blum
->data includes an extra NUL terminator despite never being used as a C string and only accessing ->datalen bytes. Remove the redundant NUL terminator and allocate one byte less in
dns_resolver_preparse().Signed-off-by Thorsten Blum <[email protected]>
Never being used where?
Let me go this through.
I read this from the documentation:
/*
* Preparse instantiation data for a dns_resolver key.
*
* For normal hostname lookups, the data must be a NUL-terminated string, with
* the NUL char accounted in datalen.
So what is confusing here for me is that should upayload, which is original data with options and '\0'.
So my question is which is the regression here:
1. Incorrect length. Then the fix would be simply setting length as 'result_len + 1', which aligns also with the snippet of documentation I pasted.
2. Unnecessary '\0'.
If there is an issue, your commit is lacking fixes tag and cc tag to the author of potentially failing commit.
Quoted 26 lines
---
Changes in v3:
- Update commit message
- v2: https://lore.kernel.org/lkml/[email protected]/Changes in v2:
- No changes in patch 1/2
- v1: https://lore.kernel.org/lkml/[email protected]/--- net/dns_resolver/dns_key.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)net/dns_resolver/dns_key.c +1
-1@@ -203,7 +203,7 @@ dns_resolver_preparse(struct key_preparsed_payload *prep)kdebug ("store result" ); prep->quotalen = result_len; - upayload =kmalloc_flex (*upayload, data, result_len +1 ); + upayload =kmalloc_flex (*upayload, data, result_len);if (!upayload) {kleave (" = -ENOMEM" );return -ENOMEM ;
net/dns_resolver/dns_key.c dns_resolver_preparse(struct key_preparsed_payload *prep) · line 216
Quoted 7 lines
net/dns_resolver/dns_key.c +0
-1@@ -211,7 +211,6 @@ dns_resolver_preparse(struct key_preparsed_payload *prep) upayload->datalen = result_len;memcpy (upayload->data, data, result_len); - upayload->data[result_len] ='\0' ; prep->payload.data[dns_key_data] = upayload;kleave (" = 0" );
BR, Jarkko
Quoted 8 lines · Jarkko Sakkinen
Quoted 5 lines · Thorsten Blum
->data includes an extra NUL terminator despite never being used as a C string and only accessing ->datalen bytes. Remove the redundant NUL terminator and allocate one byte less in
dns_resolver_preparse().Signed-off-by Thorsten Blum <[email protected]>Never being used where?
Does this conversation [1] with Jakub answer your question?
[1] https://lore.kernel.org/lkml/[email protected]/
Quoted 9 lines
Let me go this through.
I read this from the documentation:
/*
* Preparse instantiation data for adns_resolverkey.
*
* For normal hostname lookups, the data must be a NUL-terminated string, with
* the NUL char accounted in datalen.
This documents prep->data and prep->datalen, which must be NUL-terminated and is checked here in dns_resolver_preparse():
if (!data || data[datalen - 1] != '\0') return -EINVAL;
According to this, datalen (prep->datalen really) must include the NUL terminator, otherwise -EINVAL is returned.
However, my patch is about upayload->data and upayload->datalen, and upayload->data currently has a trailing '\0', which upayload->datalen doesn't account for (a mismatch that prevents adding __counted_by).
Quoted 8 lines
So what is confusing here for me is that should upayload, which is original data with options and '\0'.
So my question is which is the regression here:
1. Incorrect length. Then the fix would be simply setting length as '
result_len+ 1', which aligns also with the snippet of documentation I pasted.
This would be an option, but there is currently no consumer of upayload->data in the kernel that uses the trailing '\0'.
Quoted 1 line
2. Unnecessary '\0'.
Yes, '\0' is an unnecessary extra byte that no consumer of upayload->data uses, and my patch removes it.
Quoted 2 lines
If there is an issue, your commit is lacking fixes tag and cc tag to the author of potentially failing commit.
It's just an unused extra byte that prevents adding __counted_by(), which is otherwise harmless, hence no fixes tag.
Thanks,
Thorsten