Netdev List
 help / color / mirror / Atom feed
* [PATCH net v3] net: zero the tail of ha->addr when allocating address list entries
@ 2026-11-23 12:13 Henry Martin
  2026-11-23 12:21 ` Yuyang Huang
  0 siblings, 1 reply; 3+ messages in thread
From: Henry Martin @ 2026-11-23 12:13 UTC (permalink / raw)
  To: davem, edumazet, kuba, pabeni, sdf.kernel, nicolas.dichtel,
	sigefriedhyy
  Cc: horms, netdev, Henry Martin, stable, Daniel Machon

__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


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

* Re: [PATCH net v3] net: zero the tail of ha->addr when allocating address list entries
  2026-11-23 12:13 [PATCH net v3] net: zero the tail of ha->addr when allocating address list entries Henry Martin
@ 2026-11-23 12:21 ` Yuyang Huang
  2026-11-23 12:26   ` Eric Dumazet
  0 siblings, 1 reply; 3+ messages in thread
From: Yuyang Huang @ 2026-11-23 12:21 UTC (permalink / raw)
  To: Henry Martin
  Cc: davem, edumazet, kuba, pabeni, sdf.kernel, nicolas.dichtel, horms,
	netdev, stable, Daniel Machon

On Mon, Nov 23, 2026 at 9:13 PM Henry Martin <bsdhenrymartin@gmail.com> wrote:
>
> __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
>

 Reviewed-by: Yuyang Huang <sigefriedhyy@gmail.com>

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

* Re: [PATCH net v3] net: zero the tail of ha->addr when allocating address list entries
  2026-11-23 12:21 ` Yuyang Huang
@ 2026-11-23 12:26   ` Eric Dumazet
  0 siblings, 0 replies; 3+ messages in thread
From: Eric Dumazet @ 2026-11-23 12:26 UTC (permalink / raw)
  To: Yuyang Huang
  Cc: Henry Martin, davem, kuba, pabeni, sdf.kernel, nicolas.dichtel,
	horms, netdev, stable, Daniel Machon

Le lun. 23 nov. 2026 à 13:21, Yuyang Huang <sigefriedhyy@gmail.com> a écrit :
>
> On Mon, Nov 23, 2026 at 9:13 PM Henry Martin <bsdhenrymartin@gmail.com> wrote:
> >
> > __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
> >
>
>  Reviewed-by: Yuyang Huang <sigefriedhyy@gmail.com>

Reviewed-by: Eric Dumazet <edumazet@kernel.org>

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

end of thread, other threads:[~2026-11-23 12:26 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-23 12:13 [PATCH net v3] net: zero the tail of ha->addr when allocating address list entries Henry Martin
2026-11-23 12:21 ` Yuyang Huang
2026-11-23 12:26   ` Eric Dumazet

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