From: Henry Martin <bsdhenrymartin@gmail.com>
To: davem@davemloft.net, edumazet@kernel.org, kuba@kernel.org,
pabeni@redhat.com, sdf.kernel@gmail.com,
nicolas.dichtel@6wind.com, sigefriedhyy@gmail.com
Cc: horms@kernel.org, netdev@vger.kernel.org,
Henry Martin <bsdhenrymartin@gmail.com>,
stable@vger.kernel.org,
Daniel Machon <daniel.machon@microchip.com>
Subject: [PATCH net v3] net: zero the tail of ha->addr when allocating address list entries
Date: Mon, 23 Nov 2026 20:13:25 +0800 [thread overview]
Message-ID: <20261123121325.3137049-1-bsdhenrymartin@gmail.com> (raw)
__hw_addr_create() allocates entries with kmalloc() and initializes only
addr_len bytes of ha->addr, but the dump paths emit each entry using the
current dev->addr_len, so an entry created with a smaller addr_len is
dumped with an uninitialized tail.
dev->addr_len can grow at runtime and nothing flushes the lists. While
addr_len is 0 every addition collapses into one node, because
__hw_addr_add_ex() compares zero bytes, so the test adds one zero-length
multicast entry to each of 64 tun devices and switches them to
ARPHRD_IP6GRE (addr_len 16). RTM_GETMULTICAST then returned 64 entries
of 16 bytes, 37 with non-zero bytes and 21 starting with a kernel heap
pointer (e.g. 0xffff8188_04857ee0). tun has to flush dev->uc and
dev->mc in TUNSETLINK as well, which is a separate patch; qmi_wwan raw
IP mode and the HDLC attach/detach paths change addr_len in the same
way, so tun is not the only case.
Allocate with kzalloc() so the tail is zeroed at creation; the explicit
ha->sync_cnt = 0 then becomes redundant.
Found by an automated static analysis scan (Tencent CodeBuddy Security)
and triggered at runtime on v7.4-rc3 as an unprivileged user.
Cc: stable@vger.kernel.org
Fixes: cca8ea3b05c9 ("net: tun: set tun->dev->addr_len during TUNSETLINK processing")
Link: https://lore.kernel.org/netdev/20261116024056.1274402-1-bsdhenrymartin@gmail.com/
Link: https://lore.kernel.org/netdev/20261118125443.1137177-1-edumazet@kernel.org/
Reviewed-by: Daniel Machon <daniel.machon@microchip.com>
Reviewed-by: Nicolas Dichtel <nicolas.dichtel@6wind.com>
Signed-off-by: Henry Martin <bsdhenrymartin@gmail.com>
---
v2 -> v3:
- describe the test setup accurately: one entry on each of 64 tun
devices, since all additions collapse into one node while addr_len
is 0
- point Fixes: at cca8ea3b05c9, which made the leak reachable from tun
- link to v1 instead of the earlier review thread, and link to the
companion tun patch
- note that other drivers change addr_len without flushing the lists
- state how the issue was found
net/core/dev_addr_lists.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/net/core/dev_addr_lists.c b/net/core/dev_addr_lists.c
index d827cc21867b..9613c8a9ed7f 100644
--- a/net/core/dev_addr_lists.c
+++ b/net/core/dev_addr_lists.c
@@ -96,7 +96,7 @@ __hw_addr_create(const unsigned char *addr, int addr_len,
alloc_size = sizeof(*ha);
if (alloc_size < L1_CACHE_BYTES)
alloc_size = L1_CACHE_BYTES;
- ha = kmalloc(alloc_size, GFP_ATOMIC);
+ ha = kzalloc(alloc_size, GFP_ATOMIC);
if (!ha)
return NULL;
memcpy(ha->addr, addr, addr_len);
@@ -104,7 +104,6 @@ __hw_addr_create(const unsigned char *addr, int addr_len,
ha->refcount = 1;
ha->global_use = global;
ha->synced = sync ? 1 : 0;
- ha->sync_cnt = 0;
return ha;
}
--
2.43.7
reply other threads:[~2026-11-23 12:13 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20261123121325.3137049-1-bsdhenrymartin@gmail.com \
--to=bsdhenrymartin@gmail.com \
--cc=daniel.machon@microchip.com \
--cc=davem@davemloft.net \
--cc=edumazet@kernel.org \
--cc=horms@kernel.org \
--cc=kuba@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=nicolas.dichtel@6wind.com \
--cc=pabeni@redhat.com \
--cc=sdf.kernel@gmail.com \
--cc=sigefriedhyy@gmail.com \
--cc=stable@vger.kernel.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