Re: [PATCH] net: fix uninitialized heap leak in multicast address dumps

From: Eric Dumazet

Date: Wed Nov 18 2026 - 05:39:30 EST


Le mer. 18 nov. 2026 à 11:07, Daniel Machon
<daniel.machon@xxxxxxxxxxxxx> a écrit :
>
> Hi,
>
> > __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.
> >
> > Cc: stable@xxxxxxxxxxxxxxx
> > 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@xxxxxxxxx>
> > ---
> > net/core/dev_addr_lists.c | 5 +++++
> > 1 file changed, 5 insertions(+)
> >
> > diff --git a/net/core/dev_addr_lists.c b/net/core/dev_addr_lists.c
> > index d827cc21867b..53a2dfa2706c 100644
> > --- a/net/core/dev_addr_lists.c
> > +++ b/net/core/dev_addr_lists.c
> > @@ -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;
> > --
> > 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.
>
> Reviewed-by: Daniel Machon <daniel.machon@xxxxxxxxxxxxx>

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.