Thread View: linux.kernel.netdev
4 messages
4 total messages
Started by Henry Martin
Mon, 23 Nov 2026 12:13
[PATCH net v3] net: zero the tail of ha->addr when allocating address list entries
Author: Henry Martin
Date: Mon, 23 Nov 2026 12:13
Date: Mon, 23 Nov 2026 12:13
67 lines
13427 bytes
13427 bytes
__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
Re: [PATCH net v3] net: zero the tail of ha->addr when allocating address list entries
Author: Yuyang Huang
Date: Mon, 23 Nov 2026 12:21
Date: Mon, 23 Nov 2026 12:21
78 lines
15323 bytes
15323 bytes
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>
Re: [PATCH net v3] net: zero the tail of ha->addr when allocating address list entries
Author: Eric Dumazet
Date: Mon, 23 Nov 2026 12:26
Date: Mon, 23 Nov 2026 12:26
86 lines
12474 bytes
12474 bytes
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>
Re: [PATCH net v3] net: zero the tail of ha->addr when allocating address list entries
Author: patchwork-bot+netdevbpf
Date: Mon, 30 Nov 2026 03:50
Date: Mon, 30 Nov 2026 03:50
33 lines
9292 bytes
9292 bytes
Hello:
This patch was applied to netdev/net.git (main)
by Willem de Bruijn <willemb@google.com>:
On Mon, 23 Nov 2026 20:13:25 +0800 you 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.
>
> [...]
Here is the summary with links:
- [net,v3] net: zero the tail of ha->addr when allocating address list entries
https://git.kernel.org/netdev/net/c/0c79efef1680
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads