Skip to contentSkip to conversation

net: zero hw address entries on allocation

PATCH In review Yuyang Huang 5 participants 7 messages Nov 22 – Nov 23

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 net: zero hw address entries on allocation

__hw_addr_create() allocates struct netdev_hw_addr with kmalloc() and copies only addr_len bytes into ha->addr[MAX_ADDR_LEN], leaving the rest uninitialized.

If dev->addr_len later grows while entries remain (e.g., adding a multicast address to a down TAP device with SIOCADDMULTI and then switching it to ARPHRD_TUNNEL6 via TUNSETLINK), readers using dev->addr_len such as /proc/net/dev_mcast and AF_PACKET RTM_GETMULTICAST expose the uninitialized trailing slab bytes, and __hw_addr_add_ex() reads them in memcmp().

Switch __hw_addr_create() to kzalloc() so the unused tail of ha->addr is always zero.

---
 net/core/dev_addr_lists.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/core/dev_addr_lists.c +1 -1
index b6f25e487984..ff0815d8f6a8 100644
@@ -100,7 +100,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);
Signature · 1 line
2.56.1.750.gf70dc682cf-goog
#1 lore raw
This is an automated message. This series looks like a fix, but its commit messages seem to be missing some information:

Hi!

This is an automated message. This series looks like a fix, but its commit messages seem to be missing some information:

- How the issue was discovered, e.g. hit in production, hit during development, syzbot report, manual code inspection, LLM or static analysis tool scan.

- Whether the issue was actually triggered, or is only theoretical (e.g. found by LLM and not proven at runtime). If it was triggered please include the symptoms, like the stack trace or kernel messages.

Please do not repost the series just to address the above. Instead, reply to this email with the missing information, so that reviewers can take it into account.

*IMPORTANT*: If you do repost (for other reasons) - please include the relevant info in the cover letter or commit messages.

Signature · 2 lines
The evaluation is done by an LLM so it may be wrong, if you think
that is the case please reply and explain.
#2 lore raw
Quoted 6 lines · On Sun, 22 Nov 2026 00:32:38 +0000, [email protected] wrote:

This is an automated message. This series looks like a fix, but its commit messages seem to be missing some information:

- How the issue was discovered, e.g. hit in production, hit during development, syzbot report, manual code inspection, LLM or static analysis tool scan.

This was flagged by Sashiko AI review on the AF_PACKET multicast dump series (see the Link: tag).

Quoted 3 lines

- Whether the issue was actually triggered, or is only theoretical (e.g. found by LLM and not proven at runtime). If it was triggered please include the symptoms, like the stack trace or kernel messages.

It was reproduced at runtime in a virtme-ng VM booted with slub_debug=P (CONFIG_TUN=y, CONFIG_SLUB_DEBUG=y, CONFIG_INIT_ON_ALLOC_DEFAULT_ON=n):

1. Create a down TAP device (ARPHRD_ETHER, addr_len 6).
2. Add 01:00:5e:11:22:33 via SIOCADDMULTI.
3. Switch link type to ARPHRD_TUNNEL6 (addr_len 16) via TUNSETLINK.
4. Read /proc/net/dev_mcast and dump AF_PACKET RTM_GETMULTICAST.

Before the patch, both exposed 10 bytes of 0x6b SLUB poison:

/proc/net/dev_mcast:

    8    taprepro0       1     1     01005e1122336b6b6b6b6b6b6b6b6b6b
  AF_PACKET RTM_GETMULTICAST:
    01005e1122336b6b6b6b6b6b6b6b6b6b

With this patch, all 10 trailing bytes are zero:

/proc/net/dev_mcast:

    8    taprepro0       1     1     01005e11223300000000000000000000
  AF_PACKET RTM_GETMULTICAST:
    01005e11223300000000000000000000
Quoted 2 lines

*IMPORTANT*: If you do repost (for other reasons) - please include the relevant info in the cover letter or commit messages.

Will include these details in the commit message if a v2 is needed.

Thanks,
Yuyang

Reviewed-by on v1 1/1
#3 lore raw
In reply to Yuyang Huang
Quoted 11 lines · Yuyang Huang

__hw_addr_create() allocates struct netdev_hw_addr with kmalloc() and copies only addr_len bytes into ha->addr[MAX_ADDR_LEN], leaving the rest uninitialized.

If dev->addr_len later grows while entries remain (e.g., adding a multicast address to a down TAP device with SIOCADDMULTI and then switching it to ARPHRD_TUNNEL6 via TUNSETLINK), readers using dev->addr_len such as /proc/net/dev_mcast and AF_PACKET RTM_GETMULTICAST expose the uninitialized trailing slab bytes, and __hw_addr_add_ex() reads them in memcmp().

Quoted 5 lines

Switch __hw_addr_create() to kzalloc() so the unused tail of ha->addr is always zero.

Andrew

#4 lore raw
In reply to Yuyang Huang

Le 22/11/2026 à 01:26, Yuyang Huang a écrit :

Quoted 11 lines

__hw_addr_create() allocates struct netdev_hw_addr with kmalloc() and copies only addr_len bytes into ha->addr[MAX_ADDR_LEN], leaving the rest uninitialized.

If dev->addr_len later grows while entries remain (e.g., adding a multicast address to a down TAP device with SIOCADDMULTI and then switching it to ARPHRD_TUNNEL6 via TUNSETLINK), readers using dev->addr_len such as /proc/net/dev_mcast and AF_PACKET RTM_GETMULTICAST expose the uninitialized trailing slab bytes, and __hw_addr_add_ex() reads them in memcmp().

Quoted 5 lines

Switch __hw_addr_create() to kzalloc() so the unused tail of ha->addr is always zero.

Henry already starts a thread on this:
https://lore.kernel.org/netdev/[email protected]/

He will probably send a v3.

Regards,
Nicolas

Quoted 17 lines
---
 net/core/dev_addr_lists.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/core/dev_addr_lists.c +1 -1
index b6f25e487984..ff0815d8f6a8 100644
@@ -100,7 +100,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);