* [PATCH net-next v2 1/2] keys, dns: drop unused upayload->data NUL terminator
@ 2026-04-09 22:57 Thorsten Blum
2026-04-09 22:57 ` [PATCH net-next v2 2/2] KEYS: annotate struct user_key_payload with __counted_by Thorsten Blum
2026-04-12 21:10 ` [PATCH net-next v2 1/2] keys, dns: drop unused upayload->data NUL terminator Jakub Kicinski
0 siblings, 2 replies; 6+ messages in thread
From: Thorsten Blum @ 2026-04-09 22:57 UTC (permalink / raw)
To: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
Simon Horman, Thorsten Blum, Tim Bird
Cc: netdev, linux-kernel
In dns_resolver_preparse(), do not NUL-terminate ->data and allocate one
byte less. The NUL terminator is never used and only ->datalen bytes are
accessed.
Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
---
No changes in patch 1/2.
---
net/dns_resolver/dns_key.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/net/dns_resolver/dns_key.c b/net/dns_resolver/dns_key.c
index c3c8c3240ef9..451247864a63 100644
--- a/net/dns_resolver/dns_key.c
+++ b/net/dns_resolver/dns_key.c
@@ -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");
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH net-next v2 2/2] KEYS: annotate struct user_key_payload with __counted_by
2026-04-09 22:57 [PATCH net-next v2 1/2] keys, dns: drop unused upayload->data NUL terminator Thorsten Blum
@ 2026-04-09 22:57 ` Thorsten Blum
2026-04-12 21:10 ` [PATCH net-next v2 1/2] keys, dns: drop unused upayload->data NUL terminator Jakub Kicinski
1 sibling, 0 replies; 6+ messages in thread
From: Thorsten Blum @ 2026-04-09 22:57 UTC (permalink / raw)
To: David Howells, Jarkko Sakkinen, Kees Cook, Gustavo A. R. Silva
Cc: Thorsten Blum, netdev, keyrings, linux-kernel, linux-hardening
Add the __counted_by() compiler attribute to the flexible array member
'data' to improve access bounds-checking via CONFIG_UBSAN_BOUNDS and
CONFIG_FORTIFY_SOURCE.
Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
---
Changes in v2:
- Use __aligned(8) as suggested by David
- v1: https://lore.kernel.org/lkml/20260409073711.57020-6-thorsten.blum@linux.dev/
Cc: netdev@vger.kernel.org
---
include/keys/user-type.h | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/include/keys/user-type.h b/include/keys/user-type.h
index 386c31432789..c29ed9f5d300 100644
--- a/include/keys/user-type.h
+++ b/include/keys/user-type.h
@@ -27,7 +27,8 @@
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[] /* actual data */
+ __aligned(8) __counted_by(datalen);
};
extern struct key_type key_type_user;
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH net-next v2 1/2] keys, dns: drop unused upayload->data NUL terminator
2026-04-09 22:57 [PATCH net-next v2 1/2] keys, dns: drop unused upayload->data NUL terminator Thorsten Blum
2026-04-09 22:57 ` [PATCH net-next v2 2/2] KEYS: annotate struct user_key_payload with __counted_by Thorsten Blum
@ 2026-04-12 21:10 ` Jakub Kicinski
2026-04-12 23:04 ` Thorsten Blum
1 sibling, 1 reply; 6+ messages in thread
From: Jakub Kicinski @ 2026-04-12 21:10 UTC (permalink / raw)
To: Thorsten Blum
Cc: David S. Miller, Eric Dumazet, Paolo Abeni, Simon Horman,
Tim Bird, netdev, linux-kernel
On Fri, 10 Apr 2026 00:57:02 +0200 Thorsten Blum wrote:
> In dns_resolver_preparse(), do not NUL-terminate ->data and allocate one
> byte less. The NUL terminator is never used and only ->datalen bytes are
> accessed.
I can't see where this is used at all.
Please write better commit messages, there's no way this 1 byte
is worth the amount of time I wasted trying to review this :/
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH net-next v2 1/2] keys, dns: drop unused upayload->data NUL terminator
2026-04-12 21:10 ` [PATCH net-next v2 1/2] keys, dns: drop unused upayload->data NUL terminator Jakub Kicinski
@ 2026-04-12 23:04 ` Thorsten Blum
2026-04-13 0:05 ` Jakub Kicinski
0 siblings, 1 reply; 6+ messages in thread
From: Thorsten Blum @ 2026-04-12 23:04 UTC (permalink / raw)
To: Jakub Kicinski
Cc: David S. Miller, Eric Dumazet, Paolo Abeni, Simon Horman,
Tim Bird, netdev, linux-kernel
On Sun, Apr 12, 2026 at 02:10:04PM -0700, Jakub Kicinski wrote:
> On Fri, 10 Apr 2026 00:57:02 +0200 Thorsten Blum wrote:
> > In dns_resolver_preparse(), do not NUL-terminate ->data and allocate one
> > byte less. The NUL terminator is never used and only ->datalen bytes are
> > accessed.
>
> I can't see where this is used at all.
> Please write better commit messages, there's no way this 1 byte
> is worth the amount of time I wasted trying to review this :/
The point of patch 1/2 is not the removed NUL terminator itself, but to
prepare for patch 2/2, which adds __counted_by() and requires ->datalen
to match the number of elements in ->data.
Currently, that is not the case because ->data includes an extra NUL
despite never being used as a C string. Removing the unused terminator
makes the length match the allocation size and allows adding the
__counted_by() annotation.
I can fold this into the __counted_by() patch if you prefer.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH net-next v2 1/2] keys, dns: drop unused upayload->data NUL terminator
2026-04-12 23:04 ` Thorsten Blum
@ 2026-04-13 0:05 ` Jakub Kicinski
2026-04-13 0:31 ` Thorsten Blum
0 siblings, 1 reply; 6+ messages in thread
From: Jakub Kicinski @ 2026-04-13 0:05 UTC (permalink / raw)
To: Thorsten Blum
Cc: David S. Miller, Eric Dumazet, Paolo Abeni, Simon Horman,
Tim Bird, netdev, linux-kernel
On Mon, 13 Apr 2026 01:04:54 +0200 Thorsten Blum wrote:
> On Sun, Apr 12, 2026 at 02:10:04PM -0700, Jakub Kicinski wrote:
> > On Fri, 10 Apr 2026 00:57:02 +0200 Thorsten Blum wrote:
> > > In dns_resolver_preparse(), do not NUL-terminate ->data and allocate one
> > > byte less. The NUL terminator is never used and only ->datalen bytes are
> > > accessed.
> >
> > I can't see where this is used at all.
> > Please write better commit messages, there's no way this 1 byte
> > is worth the amount of time I wasted trying to review this :/
>
> The point of patch 1/2 is not the removed NUL terminator itself, but to
> prepare for patch 2/2, which adds __counted_by() and requires ->datalen
> to match the number of elements in ->data.
>
> Currently, that is not the case because ->data includes an extra NUL
> despite never being used as a C string. Removing the unused terminator
> makes the length match the allocation size and allows adding the
> __counted_by() annotation.
>
> I can fold this into the __counted_by() patch if you prefer.
I understand that part, but I don't get where the data from which
the terminating character is removed, is used. Only other access
I saw was freeing it, the rest of the callback seem to looking
at the error, not the data..
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH net-next v2 1/2] keys, dns: drop unused upayload->data NUL terminator
2026-04-13 0:05 ` Jakub Kicinski
@ 2026-04-13 0:31 ` Thorsten Blum
0 siblings, 0 replies; 6+ messages in thread
From: Thorsten Blum @ 2026-04-13 0:31 UTC (permalink / raw)
To: Jakub Kicinski
Cc: David S. Miller, Eric Dumazet, Paolo Abeni, Simon Horman,
Tim Bird, netdev, linux-kernel
On Sun, Apr 12, 2026 at 05:05:08PM -0700, Jakub Kicinski wrote:
> On Mon, 13 Apr 2026 01:04:54 +0200 Thorsten Blum wrote:
> > On Sun, Apr 12, 2026 at 02:10:04PM -0700, Jakub Kicinski wrote:
> > > On Fri, 10 Apr 2026 00:57:02 +0200 Thorsten Blum wrote:
> > > > In dns_resolver_preparse(), do not NUL-terminate ->data and allocate one
> > > > byte less. The NUL terminator is never used and only ->datalen bytes are
> > > > accessed.
> > >
> > > I can't see where this is used at all.
> > > Please write better commit messages, there's no way this 1 byte
> > > is worth the amount of time I wasted trying to review this :/
> >
> > The point of patch 1/2 is not the removed NUL terminator itself, but to
> > prepare for patch 2/2, which adds __counted_by() and requires ->datalen
> > to match the number of elements in ->data.
> >
> > Currently, that is not the case because ->data includes an extra NUL
> > despite never being used as a C string. Removing the unused terminator
> > makes the length match the allocation size and allows adding the
> > __counted_by() annotation.
> >
> > I can fold this into the __counted_by() patch if you prefer.
>
> I understand that part, but I don't get where the data from which
> the terminating character is removed, is used. Only other access
> I saw was freeing it, the rest of the callback seem to looking
> at the error, not the data..
->data and ->datalen are used in multiple places.
For example, in dns_query() in net/dns_resolver/dns_query.c:
upayload = user_key_payload_locked(rkey);
len = upayload->datalen;
if (_result) {
ret = -ENOMEM;
*_result = kmemdup_nul(upayload->data, len, GFP_KERNEL);
if (!*_result)
goto put;
}
In cifs_set_cifscreds() in fs/smb/client/connect.c:
/* find first : in payload */
payload = upayload->data;
delim = strnchr(payload, upayload->datalen, ':');
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2026-04-13 0:32 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-04-09 22:57 [PATCH net-next v2 1/2] keys, dns: drop unused upayload->data NUL terminator Thorsten Blum
2026-04-09 22:57 ` [PATCH net-next v2 2/2] KEYS: annotate struct user_key_payload with __counted_by Thorsten Blum
2026-04-12 21:10 ` [PATCH net-next v2 1/2] keys, dns: drop unused upayload->data NUL terminator Jakub Kicinski
2026-04-12 23:04 ` Thorsten Blum
2026-04-13 0:05 ` Jakub Kicinski
2026-04-13 0:31 ` Thorsten Blum
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox