Skip to contentSkip to conversation

net: fix uninitialized heap leak in multicast address dumps

PATCH In review Henry Martin 5 participants 6 messages Nov 16 – Nov 18

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

PATCH 1/1 net: fix uninitialized heap leak in multicast address dumps

__hw_addr_create() allocates entries with kmalloc() and initializes only addr_len bytes of ha->addr. Dump paths emit entries using the current dev->addr_len, which can grow after the entry was created:
tun's TUNSETLINK changes a device from ARPHRD_NONE (addr_len 0) to ARPHRD_IP6GRE (addr_len 16). Both the RTM_GETMULTICAST dump and /proc/net/dev_mcast then emit up to 16 bytes of never-written slab memory per entry.

This discloses leftover kernel heap contents to anyone reading those interfaces.

Zero the tail of ha->addr at creation time, so dumps can only emit initialized bytes.

Fixes a748ee242681 ("net: move address list functions to a separate file")
---
 net/core/dev_addr_lists.c | 5 +++++
 1 file changed, 5 insertions(+)
net/core/dev_addr_lists.c +5 -0
index d827cc21867b..53a2dfa2706c 100644
@@ -100,6 +100,11 @@ __hw_addr_create(const unsigned char *addr, int addr_len,
 	if (!ha)
 		return NULL;
 	memcpy(ha->addr, addr, addr_len);
+	/* Entries are dumped with the current dev->addr_len, which can grow
+	 * after creation (e.g. tun TUNSETLINK), so never leave the tail
+	 * uninitialized.
+	 */
+	memset(ha->addr + addr_len, 0, MAX_ADDR_LEN - addr_len);
 	ha->type = addr_type;
 	ha->refcount = 1;
 	ha->global_use = global;
Signature · 1 line
2.43.7
#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.
Reviewed-by on v1 1/1
#2 lore raw
In reply to Henry Martin

Le 16/11/2026 à 03:40, Henry Martin a écrit :

Quoted 11 lines

__hw_addr_create() allocates entries with kmalloc() and initializes only addr_len bytes of ha->addr. Dump paths emit entries using the current dev->addr_len, which can grow after the entry was created:
tun's TUNSETLINK changes a device from ARPHRD_NONE (addr_len 0) to ARPHRD_IP6GRE (addr_len 16). Both the RTM_GETMULTICAST dump and /proc/net/dev_mcast then emit up to 16 bytes of never-written slab memory per entry.

This discloses leftover kernel heap contents to anyone reading those interfaces.

Quoted 7 lines

Zero the tail of ha->addr at creation time, so dumps can only emit initialized bytes.

Fixes a748ee242681 ("net: move address list functions to a separate file")
Reviewed-by on v1 1/1
#3 lore raw
In reply to Henry Martin

Hi,

Quoted 41 lines

__hw_addr_create() allocates entries with kmalloc() and initializes only addr_len bytes of ha->addr. Dump paths emit entries using the current dev->addr_len, which can grow after the entry was created:
tun's TUNSETLINK changes a device from ARPHRD_NONE (addr_len 0) to ARPHRD_IP6GRE (addr_len 16). Both the RTM_GETMULTICAST dump and /proc/net/dev_mcast then emit up to 16 bytes of never-written slab memory per entry.

This discloses leftover kernel heap contents to anyone reading those interfaces.

Zero the tail of ha->addr at creation time, so dumps can only emit initialized bytes.

Fixes a748ee242681 ("net: move address list functions to a separate file")
---
 net/core/dev_addr_lists.c | 5 +++++
 1 file changed, 5 insertions(+)
net/core/dev_addr_lists.c +5 -0
index d827cc21867b..53a2dfa2706c 100644
@@ -100,6 +100,11 @@ __hw_addr_create(const unsigned char *addr, int addr_len,
 	if (!ha)
 		return NULL;
 	memcpy(ha->addr, addr, addr_len);
+	/* Entries are dumped with the current dev->addr_len, which can grow
+	 * after creation (e.g. tun TUNSETLINK), so never leave the tail
+	 * uninitialized.
+	 */
+	memset(ha->addr + addr_len, 0, MAX_ADDR_LEN - addr_len);
 	ha->type = addr_type;
 	ha->refcount = 1;
 	ha->global_use = global;
Signature · 1 line
2.43.7

Looks right.

Just a thought, I think switching to kzalloc, like so:

+ ha = kzalloc(alloc_size, GFP_ATOMIC);

Would give you the same fix, and you would get rid of that extra tail length arithmetic.

maintainer
#4 lore raw
Quoted 47 lines · Daniel Machon

Hi,

Quoted 39 lines

__hw_addr_create() allocates entries with kmalloc() and initializes only addr_len bytes of ha->addr. Dump paths emit entries using the current dev->addr_len, which can grow after the entry was created:
tun's TUNSETLINK changes a device from ARPHRD_NONE (addr_len 0) to ARPHRD_IP6GRE (addr_len 16). Both the RTM_GETMULTICAST dump and /proc/net/dev_mcast then emit up to 16 bytes of never-written slab memory per entry.

This discloses leftover kernel heap contents to anyone reading those interfaces.

Zero the tail of ha->addr at creation time, so dumps can only emit initialized bytes.

Fixes a748ee242681 ("net: move address list functions to a separate file")
---
 net/core/dev_addr_lists.c | 5 +++++
 1 file changed, 5 insertions(+)
net/core/dev_addr_lists.c +5 -1
index d827cc21867b..53a2dfa2706c 100644
@@ -100,6 +100,11 @@ __hw_addr_create(const unsigned char *addr, int addr_len,
      if (!ha)
              return NULL;
      memcpy(ha->addr, addr, addr_len);
+     /* Entries are dumped with the current dev->addr_len, which can grow
+      * after creation (e.g. tun TUNSETLINK), so never leave the tail
+      * uninitialized.
+      */
+     memset(ha->addr + addr_len, 0, MAX_ADDR_LEN - addr_len);
      ha->type = addr_type;
      ha->refcount = 1;
      ha->global_use = global;
--
Quoted 2 lines

2.43.7

Looks right.

Quoted 8 lines

Just a thought, I think switching to kzalloc, like so:

+ ha = kzalloc(alloc_size, GFP_ATOMIC);

Would give you the same fix, and you would get rid of that extra tail length arithmetic.

I agree with Daniel, kzalloc() would be simpler here, this is not fast path. You can then remove the "ha->sync_cnt = 0;" line.

This is fine as a hardening measure, but the root cause is in tun:

bonding and team both call dev_uc_flush() and dev_mc_flush() when they change dev->type and dev->addr_len. TUNSETLINK does not, so entries created with the old addr_len stay in dev->uc and dev->mc, in an rb-tree which is now searched with a different key length.

I think TUNSETLINK should flush both lists, in a separate patch.

Thanks.

maintainer
#5 lore raw
Quoted 62 lines · Eric Dumazet
Quoted 47 lines · Daniel Machon

Hi,

Quoted 39 lines

__hw_addr_create() allocates entries with kmalloc() and initializes only addr_len bytes of ha->addr. Dump paths emit entries using the current dev->addr_len, which can grow after the entry was created:
tun's TUNSETLINK changes a device from ARPHRD_NONE (addr_len 0) to ARPHRD_IP6GRE (addr_len 16). Both the RTM_GETMULTICAST dump and /proc/net/dev_mcast then emit up to 16 bytes of never-written slab memory per entry.

This discloses leftover kernel heap contents to anyone reading those interfaces.

Zero the tail of ha->addr at creation time, so dumps can only emit initialized bytes.

Fixes a748ee242681 ("net: move address list functions to a separate file")
---
 net/core/dev_addr_lists.c | 5 +++++
 1 file changed, 5 insertions(+)
net/core/dev_addr_lists.c +5 -1
index d827cc21867b..53a2dfa2706c 100644
@@ -100,6 +100,11 @@ __hw_addr_create(const unsigned char *addr, int addr_len,
      if (!ha)
              return NULL;
      memcpy(ha->addr, addr, addr_len);
+     /* Entries are dumped with the current dev->addr_len, which can grow
+      * after creation (e.g. tun TUNSETLINK), so never leave the tail
+      * uninitialized.
+      */
+     memset(ha->addr + addr_len, 0, MAX_ADDR_LEN - addr_len);
      ha->type = addr_type;
      ha->refcount = 1;
      ha->global_use = global;
--
Quoted 2 lines

2.43.7

Looks right.

Quoted 8 lines

Just a thought, I think switching to kzalloc, like so:

+ ha = kzalloc(alloc_size, GFP_ATOMIC);

Would give you the same fix, and you would get rid of that extra tail length arithmetic.

I agree with Daniel, kzalloc() would be simpler here, this is not fast path. You can then remove the "ha->sync_cnt = 0;" line.

Quoted 8 lines

This is fine as a hardening measure, but the root cause is in tun:

bonding and team both call dev_uc_flush() and dev_mc_flush() when they change dev->type and dev->addr_len. TUNSETLINK does not, so entries created with the old addr_len stay in dev->uc and dev->mc, in an rb-tree which is now searched with a different key length.

I think TUNSETLINK should flush both lists, in a separate patch.

Something like:

drivers/net/tun.c +0 -0
index d4870bdc156f..f675e5469cfd 100644
@@ -3387,6 +3387,9 @@ static long __tun_chr_ioctl(struct file *file,

unsigned int cmd,

                                           "Refused to change device type\n");
                                break;
                        }
+                       /* Addresses were added with the old dev->addr_len. */
+                       dev_uc_flush(tun->dev);
+                       dev_mc_flush(tun->dev);
                        tun->dev->type = (int) arg;
                        tun->dev->addr_len = tun_get_addr_len(tun->dev->type);
                        netif_info(tun, drv, tun->dev, "linktype set to %d\n",