Netdev List
 help / color / mirror / Atom feed
* [PATCH iproute2 v2] libnetlink: zero padding in rta_addattr_l()
@ 2026-11-09 16:41 Dave Seddon
  2026-11-09 17:50 ` patchwork-bot+netdevbpf
  0 siblings, 1 reply; 2+ messages in thread
From: Dave Seddon @ 2026-11-09 16:41 UTC (permalink / raw)
  To: netdev; +Cc: Dave Seddon, Stephen Hemminger, David Ahern

rta_addattr_l() copies alen bytes but advances the parent by
RTA_ALIGN(len), so the 1-3 padding bytes are never written. This affects
every caller that passes an unaligned length. Nests built in stack
buffers (lwtunnel encap, RTA_MULTIPATH, RTA_METRICS) then send those
bytes to the kernel. For example, in

  ip nexthop add id 53 encap mpls 101 ttl 10 via 192.0.2.1 dev d0

the three bytes after MPLS_IPTUNNEL_TTL are stack contents:

  05 00 02 00  0a 7f 00 00    MPLS_IPTUNNEL_TTL, ttl 10, stack bytes
  05 00 02 00  0a 00 00 00    with this patch

and valgrind reports "sendmsg(msg.msg_iov[0]) points to uninitialised
byte(s)".

The kernel skips padding when parsing, so nothing fails, but its own
encoder zeroes it (__nla_reserve()), and so does addraw_l() here. Do
the same.

Assisted-by: Claude:claude-opus-5-5
Signed-off-by: Dave Seddon <dave.seddon.ca@gmail.com>
---
v2:
 - Drop the Fixes: tag; the gap goes back to the initial import (Stephen)
 - Cite addraw_l() as the precedent
 - Correct the note on addattr_l()

addattr_l() doesn't zero its padding either (07f9436201eb added the
memset to addraw_l()), but its callers zero their request first, so it
is left alone. I can send that as a separate patch if wanted.

v1: https://lore.kernel.org/netdev/20261104052901.2735000-1-dave.seddon.ca@gmail.com/
---
 lib/libnetlink.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/lib/libnetlink.c b/lib/libnetlink.c
index edf3a8ba..c4a8e694 100644
--- a/lib/libnetlink.c
+++ b/lib/libnetlink.c
@@ -1502,6 +1502,7 @@ int rta_addattr_l(struct rtattr *rta, int maxlen, int type,
 	subrta->rta_len = len;
 	if (alen)
 		memcpy(RTA_DATA(subrta), data, alen);
+	memset((void *)subrta + len, 0, RTA_ALIGN(len) - len);
 	rta->rta_len = NLMSG_ALIGN(rta->rta_len) + RTA_ALIGN(len);
 	return 0;
 }
-- 
2.56.0


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH iproute2 v2] libnetlink: zero padding in rta_addattr_l()
  2026-11-09 16:41 [PATCH iproute2 v2] libnetlink: zero padding in rta_addattr_l() Dave Seddon
@ 2026-11-09 17:50 ` patchwork-bot+netdevbpf
  0 siblings, 0 replies; 2+ messages in thread
From: patchwork-bot+netdevbpf @ 2026-11-09 17:50 UTC (permalink / raw)
  To: Dave Seddon; +Cc: netdev, stephen, dsahern

Hello:

This patch was applied to iproute2/iproute2.git (main)
by Stephen Hemminger <stephen@networkplumber.org>:

On Mon,  9 Nov 2026 08:41:16 -0800 you wrote:
> rta_addattr_l() copies alen bytes but advances the parent by
> RTA_ALIGN(len), so the 1-3 padding bytes are never written. This affects
> every caller that passes an unaligned length. Nests built in stack
> buffers (lwtunnel encap, RTA_MULTIPATH, RTA_METRICS) then send those
> bytes to the kernel. For example, in
> 
>   ip nexthop add id 53 encap mpls 101 ttl 10 via 192.0.2.1 dev d0
> 
> [...]

Here is the summary with links:
  - [iproute2,v2] libnetlink: zero padding in rta_addattr_l()
    https://git.kernel.org/pub/scm/network/iproute2/iproute2.git/commit/?id=c5b76cbbfefd

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-11-09 17:50 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-09 16:41 [PATCH iproute2 v2] libnetlink: zero padding in rta_addattr_l() Dave Seddon
2026-11-09 17:50 ` patchwork-bot+netdevbpf

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox