Linux kernel -stable discussions
 help / color / mirror / Atom feed
* [PATCH net v2] net: zero the tail of ha->addr when allocating address list entries
@ 2026-11-19  4:01 Henry Martin
  2026-11-19  4:07 ` netdev-bot+sinfo
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Henry Martin @ 2026-11-19  4:01 UTC (permalink / raw)
  To: Paolo Abeni, David S . Miller, Eric Dumazet, Jakub Kicinski,
	Simon Horman, Stanislav Fomichev, Nicolas Dichtel, Yuyang Huang,
	Aleksandr Loktionov
  Cc: netdev, linux-kernel, Henry Martin, stable, Daniel Machon

__hw_addr_create() allocates entries with kmalloc() and initializes only
addr_len bytes of ha->addr.  The dump paths emit each entry using the
current dev->addr_len, so an entry that was created with a smaller
addr_len is dumped with uninitialized tail bytes.

dev->addr_len 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).  On v7.4-rc3, with 64 entries armed on a down tun device
and the link type then set to ARPHRD_IP6GRE, RTM_GETMULTICAST returned
16 bytes per entry of which 37 were non-zero and 21 started with a
kernel heap pointer (e.g. 0xffff8188_04857ee0); /proc/net/dev_mcast
exposed the same bytes.  This discloses stale heap contents to readers
of those interfaces.

Allocate with kzalloc(), so the tail is always zeroed and a dump can
only emit bytes that were written or zeroed at creation.  This also
makes the explicit ha->sync_cnt = 0 initialization redundant.

Cc: stable@vger.kernel.org
Fixes: a748ee242681 ("net: move address list functions to a separate file")
Link: https://lists.openwall.net/linux-kernel/2026/09/10/320
Signed-off-by: Henry Martin <bsdhenrymartin@gmail.com>
Reviewed-by: Daniel Machon <daniel.machon@microchip.com>
---
v1 -> v2:
 - allocate with kzalloc() and drop the manual ha->sync_cnt = 0, as
   suggested by Eric Dumazet and Daniel Machon
 - add the runtime observation to the changelog

 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


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

* Re: [PATCH net v2] net: zero the tail of ha->addr when allocating address list entries
  2026-11-19  4:01 [PATCH net v2] net: zero the tail of ha->addr when allocating address list entries Henry Martin
@ 2026-11-19  4:07 ` netdev-bot+sinfo
  2026-11-19  8:15 ` Nicolas Dichtel
  2026-11-19  8:29 ` Eric Dumazet
  2 siblings, 0 replies; 4+ messages in thread
From: netdev-bot+sinfo @ 2026-11-19  4:07 UTC (permalink / raw)
  To: Henry Martin
  Cc: Paolo Abeni, David S . Miller, Eric Dumazet, Jakub Kicinski,
	Simon Horman, Stanislav Fomichev, Nicolas Dichtel, Yuyang Huang,
	Aleksandr Loktionov, netdev, linux-kernel, stable, Daniel Machon

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.

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.
-- 
The evaluation is done by an LLM so it may be wrong, if you think
that is the case please reply and explain.

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

* Re: [PATCH net v2] net: zero the tail of ha->addr when allocating address list entries
  2026-11-19  4:01 [PATCH net v2] net: zero the tail of ha->addr when allocating address list entries Henry Martin
  2026-11-19  4:07 ` netdev-bot+sinfo
@ 2026-11-19  8:15 ` Nicolas Dichtel
  2026-11-19  8:29 ` Eric Dumazet
  2 siblings, 0 replies; 4+ messages in thread
From: Nicolas Dichtel @ 2026-11-19  8:15 UTC (permalink / raw)
  To: Henry Martin, Paolo Abeni, David S . Miller, Eric Dumazet,
	Jakub Kicinski, Simon Horman, Stanislav Fomichev, Yuyang Huang,
	Aleksandr Loktionov
  Cc: netdev, linux-kernel, stable, Daniel Machon

Le 19/11/2026 à 05:01, Henry Martin a écrit :
> __hw_addr_create() allocates entries with kmalloc() and initializes only
> addr_len bytes of ha->addr.  The dump paths emit each entry using the
> current dev->addr_len, so an entry that was created with a smaller
> addr_len is dumped with uninitialized tail bytes.
> 
> dev->addr_len 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).  On v7.4-rc3, with 64 entries armed on a down tun device
> and the link type then set to ARPHRD_IP6GRE, RTM_GETMULTICAST returned
> 16 bytes per entry of which 37 were non-zero and 21 started with a
> kernel heap pointer (e.g. 0xffff8188_04857ee0); /proc/net/dev_mcast
> exposed the same bytes.  This discloses stale heap contents to readers
> of those interfaces.
> 
> Allocate with kzalloc(), so the tail is always zeroed and a dump can
> only emit bytes that were written or zeroed at creation.  This also
> makes the explicit ha->sync_cnt = 0 initialization redundant.
> 
> Cc: stable@vger.kernel.org
> Fixes: a748ee242681 ("net: move address list functions to a separate file")
> Link: https://lists.openwall.net/linux-kernel/2026/09/10/320
> Signed-off-by: Henry Martin <bsdhenrymartin@gmail.com>
> Reviewed-by: Daniel Machon <daniel.machon@microchip.com>

Reviewed-by: Nicolas Dichtel <nicolas.dichtel@6wind.com>

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

* Re: [PATCH net v2] net: zero the tail of ha->addr when allocating address list entries
  2026-11-19  4:01 [PATCH net v2] net: zero the tail of ha->addr when allocating address list entries Henry Martin
  2026-11-19  4:07 ` netdev-bot+sinfo
  2026-11-19  8:15 ` Nicolas Dichtel
@ 2026-11-19  8:29 ` Eric Dumazet
  2 siblings, 0 replies; 4+ messages in thread
From: Eric Dumazet @ 2026-11-19  8:29 UTC (permalink / raw)
  To: Henry Martin
  Cc: Paolo Abeni, David S . Miller, Jakub Kicinski, Simon Horman,
	Stanislav Fomichev, Nicolas Dichtel, Yuyang Huang,
	Aleksandr Loktionov, netdev, linux-kernel, stable, Daniel Machon

Le jeu. 19 nov. 2026 à 05:02, Henry Martin <bsdhenrymartin@gmail.com> a écrit :
>
> __hw_addr_create() allocates entries with kmalloc() and initializes only
> addr_len bytes of ha->addr.  The dump paths emit each entry using the
> current dev->addr_len, so an entry that was created with a smaller
> addr_len is dumped with uninitialized tail bytes.
>
> dev->addr_len 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).  On v7.4-rc3, with 64 entries armed on a down tun device
> and the link type then set to ARPHRD_IP6GRE, RTM_GETMULTICAST returned
> 16 bytes per entry of which 37 were non-zero and 21 started with a
> kernel heap pointer (e.g. 0xffff8188_04857ee0); /proc/net/dev_mcast
> exposed the same bytes.  This discloses stale heap contents to readers
> of those interfaces.

How did you get 64 entries on one device while addr_len was 0 ?

__hw_addr_add_ex() does memcmp(addr, ha->addr, 0), so every add of the
same type finds the existing node and only bumps its refcount.

Please describe what was really run (64 devices ? another starting
link type ?)

>
> Allocate with kzalloc(), so the tail is always zeroed and a dump can
> only emit bytes that were written or zeroed at creation.  This also
> makes the explicit ha->sync_cnt = 0 initialization redundant.
>
> Cc: stable@vger.kernel.org
> Fixes: a748ee242681 ("net: move address list functions to a separate file")

This commit only moved code around.

For tun, the issue became reachable with
cca8ea3b05c9 ("net: tun: set tun->dev->addr_len during TUNSETLINK processing")

> Link: https://lists.openwall.net/linux-kernel/2026/09/10/320

Please point to your v1 instead:

https://lore.kernel.org/netdev/20261116024056.1274402-1-bsdhenrymartin@gmail.com/

Also please mention the companion patch, which flushes dev->uc and
dev->mc in TUNSETLINK when addr_len changes:

https://lore.kernel.org/netdev/20261118125443.1137177-1-edumazet@kernel.org/

Your patch is still useful with it: tun is not the only driver
changing dev->addr_len without flushing these lists (qmi_wwan raw_ip,
hdlc protocol attach/detach), so the changelog should not present tun
as the only case.

Also, the bot asked how the issue was discovered, please include this
in the changelog.

The code change itself looks good to me, please send a v3 with
the changelog fixed (after the usual 24 hours).

Thanks.

pw-bot: cr

> Signed-off-by: Henry Martin <bsdhenrymartin@gmail.com>
> Reviewed-by: Daniel Machon <daniel.machon@microchip.com>
> ---
> v1 -> v2:
>  - allocate with kzalloc() and drop the manual ha->sync_cnt = 0, as
>    suggested by Eric Dumazet and Daniel Machon
>  - add the runtime observation to the changelog
>
>  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
>

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

end of thread, other threads:[~2026-11-19  8:29 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-19  4:01 [PATCH net v2] net: zero the tail of ha->addr when allocating address list entries Henry Martin
2026-11-19  4:07 ` netdev-bot+sinfo
2026-11-19  8:15 ` Nicolas Dichtel
2026-11-19  8:29 ` Eric Dumazet

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