From: Dave Seddon <dave.seddon.ca@gmail.com>
To: netdev@vger.kernel.org
Cc: Dave Seddon <dave.seddon.ca@gmail.com>,
Stephen Hemminger <stephen@networkplumber.org>,
David Ahern <dsahern@kernel.org>
Subject: [PATCH iproute2] libnetlink: zero padding in rta_addattr_l()
Date: Tue, 3 Nov 2026 21:29:01 -0800 [thread overview]
Message-ID: <20261104052901.2735000-1-dave.seddon.ca@gmail.com> (raw)
rta_addattr_l() copies alen bytes but advances the parent by
RTA_ALIGN(len), so the 1-3 padding bytes are never written. 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()). Do the same here.
Fixes: 6ef87f9cce21 ("ip: route: add congestion control metric")
Assisted-by: Claude:claude-opus-5-5
Signed-off-by: Dave Seddon <dave.seddon.ca@gmail.com>
---
addattr_l() has the same gap, but all its callers zero their request,
so it is left alone.
Kernel side: nla_next() advances by NLA_ALIGN(nla_len), so padding is
never read; __nla_reserve() memsets it to zero.
---
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
next reply other threads:[~2026-11-04 5:29 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-04 5:29 Dave Seddon [this message]
2026-11-09 1:57 ` [PATCH iproute2] libnetlink: zero padding in rta_addattr_l() Stephen Hemminger
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261104052901.2735000-1-dave.seddon.ca@gmail.com \
--to=dave.seddon.ca@gmail.com \
--cc=dsahern@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=stephen@networkplumber.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox