Netdev List
 help / color / mirror / Atom feed
* [PATCH net] tun: flush uc and mc addresses in TUNSETLINK
@ 2026-11-18 12:54 Eric Dumazet
  2026-11-18 12:58 ` netdev-bot+sinfo
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Eric Dumazet @ 2026-11-18 12:54 UTC (permalink / raw)
  To: David S . Miller, Jakub Kicinski, Paolo Abeni
  Cc: Willem de Bruijn, Simon Horman, netdev, edumazet, Henry Martin,
	Willem de Bruijn, Jason Wang, Andrew Lunn

TUNSETLINK changes dev->type and dev->addr_len, but leaves
dev->uc and dev->mc untouched.

Entries added with the old addr_len stay in lists and rb-trees
that are now searched and dumped with the new addr_len.

When addr_len grows (eg ARPHRD_NONE -> ARPHRD_IP6GRE), dumps like
/proc/net/dev_mcast and RTM_GETMULTICAST expose bytes of
netdev_hw_addr that were never initialized.

bonding and team already call dev_uc_flush() and dev_mc_flush()
between NETDEV_PRE_TYPE_CHANGE and the type change. Do the same
in tun, but only when addr_len changes: if it does not, existing
entries are still valid and there is no reason to drop them.

Fixes: cca8ea3b05c9 ("net: tun: set tun->dev->addr_len during TUNSETLINK processing")
Link: https://lore.kernel.org/netdev/20261116024056.1274402-1-bsdhenrymartin@gmail.com/
Signed-off-by: Eric Dumazet <edumazet@kernel.org>
---
Cc: Henry Martin <bsdhenrymartin@gmail.com>
Cc: Willem de Bruijn <willemdebruijn.kernel@gmail.com>
Cc: Jason Wang <jasowangio@gmail.com>
Cc: Andrew Lunn <andrew+netdev@lunn.ch>
---
 drivers/net/tun.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/drivers/net/tun.c b/drivers/net/tun.c
index d4870bdc156f..a2f56a4febb5 100644
--- a/drivers/net/tun.c
+++ b/drivers/net/tun.c
@@ -3379,6 +3379,8 @@ static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
 			   (unsigned short)arg == ARPHRD_MCTP) {
 			ret = -EINVAL;
 		} else {
+			unsigned char addr_len = tun_get_addr_len(arg);
+
 			ret = call_netdevice_notifiers(NETDEV_PRE_TYPE_CHANGE,
 						       tun->dev);
 			ret = notifier_to_errno(ret);
@@ -3387,8 +3389,13 @@ 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. */
+			if (addr_len != tun->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);
+			tun->dev->addr_len = addr_len;
 			netif_info(tun, drv, tun->dev, "linktype set to %d\n",
 				   tun->dev->type);
 			call_netdevice_notifiers(NETDEV_POST_TYPE_CHANGE,
-- 
2.53.0


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

* Re: [PATCH net] tun: flush uc and mc addresses in TUNSETLINK
  2026-11-18 12:54 [PATCH net] tun: flush uc and mc addresses in TUNSETLINK Eric Dumazet
@ 2026-11-18 12:58 ` netdev-bot+sinfo
  2026-11-19  8:34   ` Eric Dumazet
  2026-11-18 23:47 ` Willem de Bruijn
  2026-11-19 22:17 ` netdev-bot+sashiko
  2 siblings, 1 reply; 5+ messages in thread
From: netdev-bot+sinfo @ 2026-11-18 12:58 UTC (permalink / raw)
  To: Eric Dumazet
  Cc: David S . Miller, Jakub Kicinski, Paolo Abeni, Willem de Bruijn,
	Simon Horman, netdev, Henry Martin, Willem de Bruijn, Jason Wang,
	Andrew Lunn

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.
-- 
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] 5+ messages in thread

* Re: [PATCH net] tun: flush uc and mc addresses in TUNSETLINK
  2026-11-18 12:54 [PATCH net] tun: flush uc and mc addresses in TUNSETLINK Eric Dumazet
  2026-11-18 12:58 ` netdev-bot+sinfo
@ 2026-11-18 23:47 ` Willem de Bruijn
  2026-11-19 22:17 ` netdev-bot+sashiko
  2 siblings, 0 replies; 5+ messages in thread
From: Willem de Bruijn @ 2026-11-18 23:47 UTC (permalink / raw)
  To: Eric Dumazet, David S . Miller, Jakub Kicinski, Paolo Abeni
  Cc: Willem de Bruijn, Simon Horman, netdev, edumazet, Henry Martin,
	Willem de Bruijn, Jason Wang, Andrew Lunn

Eric Dumazet wrote:
> TUNSETLINK changes dev->type and dev->addr_len, but leaves
> dev->uc and dev->mc untouched.
> 
> Entries added with the old addr_len stay in lists and rb-trees
> that are now searched and dumped with the new addr_len.
> 
> When addr_len grows (eg ARPHRD_NONE -> ARPHRD_IP6GRE), dumps like
> /proc/net/dev_mcast and RTM_GETMULTICAST expose bytes of
> netdev_hw_addr that were never initialized.
> 
> bonding and team already call dev_uc_flush() and dev_mc_flush()
> between NETDEV_PRE_TYPE_CHANGE and the type change. Do the same
> in tun, but only when addr_len changes: if it does not, existing
> entries are still valid and there is no reason to drop them.
> 
> Fixes: cca8ea3b05c9 ("net: tun: set tun->dev->addr_len during TUNSETLINK processing")
> Link: https://lore.kernel.org/netdev/20261116024056.1274402-1-bsdhenrymartin@gmail.com/
> Signed-off-by: Eric Dumazet <edumazet@kernel.org>

Reviewed-by: Willem de Bruijn <willemb@google.com>

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

* Re: [PATCH net] tun: flush uc and mc addresses in TUNSETLINK
  2026-11-18 12:58 ` netdev-bot+sinfo
@ 2026-11-19  8:34   ` Eric Dumazet
  0 siblings, 0 replies; 5+ messages in thread
From: Eric Dumazet @ 2026-11-19  8:34 UTC (permalink / raw)
  To: netdev-bot+sinfo
  Cc: David S . Miller, Jakub Kicinski, Paolo Abeni, Willem de Bruijn,
	Simon Horman, netdev, Henry Martin, Willem de Bruijn, Jason Wang,
	Andrew Lunn

Le mer. 18 nov. 2026 à 13:58, <netdev-bot+sinfo@kernel.org> a écrit :
>
> 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.

The issue was reported by Henry Martin, see the Link: tag:

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

I wrote this patch after reviewing his, by code inspection:
TUNSETLINK is missing the dev_uc_flush()/dev_mc_flush() calls
that bonding and team perform when they change the device type.

>
>  - 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.
>

Henry reported triggering it on v7.4-rc3: after TUNSETLINK from
ARPHRD_NONE to ARPHRD_IP6GRE, RTM_GETMULTICAST and /proc/net/dev_mcast
exposed uninitialized bytes of netdev_hw_addr, including kernel heap
pointers. Details are in his v2:

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

There is no splat, this is an information leak.

> 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] 5+ messages in thread

* Re: [PATCH net] tun: flush uc and mc addresses in TUNSETLINK
  2026-11-18 12:54 [PATCH net] tun: flush uc and mc addresses in TUNSETLINK Eric Dumazet
  2026-11-18 12:58 ` netdev-bot+sinfo
  2026-11-18 23:47 ` Willem de Bruijn
@ 2026-11-19 22:17 ` netdev-bot+sashiko
  2 siblings, 0 replies; 5+ messages in thread
From: netdev-bot+sashiko @ 2026-11-19 22:17 UTC (permalink / raw)
  To: edumazet
  Cc: davem, kuba, pabeni, willemb, horms, netdev, bsdhenrymartin,
	willemdebruijn.kernel, jasowangio, andrew+netdev

Thank you for your contribution! Sashiko AI review found 2 potential
issue(s) to consider.

Critical: 0 · High: 1 · Medium: 1 · Low: 0

If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).

- [High] The fix's own claim is still reachable through a race, so
  uninitialized kernel memory can still leak.
- [Medium] The new dev_uc_flush()/dev_mc_flush() in TUNSETLINK
  (drivers/net/tun.c:3393-3396) frees every netdev_hw_addr in…

--

tun: flush uc and mc addresses in TUNSETLINK

When the new link type changes dev->addr_len, this patch makes TUNSETLINK
flush dev->uc and dev->mc. Entries created with the old addr_len would
otherwise be searched and dumped with the new length. This follows what
bonding and team do between NETDEV_PRE_TYPE_CHANGE and the type change.

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

> diff --git a/drivers/net/tun.c b/drivers/net/tun.c
> index d4870bdc156f4..a2f56a4febb57 100644
> --- a/drivers/net/tun.c
> +++ b/drivers/net/tun.c
> @@ -3379,6 +3379,8 @@ static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
>  			   (unsigned short)arg == ARPHRD_MCTP) {
>  			ret = -EINVAL;
>  		} else {
> +			unsigned char addr_len = tun_get_addr_len(arg);
> +
>  			ret = call_netdevice_notifiers(NETDEV_PRE_TYPE_CHANGE,
>  						       tun->dev);
>  			ret = notifier_to_errno(ret);
> @@ -3387,8 +3389,13 @@ 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. */
> +			if (addr_len != tun->dev->addr_len) {
> +				dev_uc_flush(tun->dev);
> +				dev_mc_flush(tun->dev);
> +			}

[Severity: Medium]
Can this flush break the reference bookkeeping of holders other than
IPv4 and IPv6?

dev_uc_flush() and dev_mc_flush() free every netdev_hw_addr no matter
what its refcount, sync_cnt or global_use is. Only IPv4 and addrconf
(ipv6_mc_unmap()/ipv6_mc_remap()) give back and re-take their references
across PRE/POST_TYPE_CHANGE.

Upper devices that sync into a tap do not veto NETDEV_PRE_TYPE_CHANGE on
the lower device. Two examples are bonding, via bond_set_rx_mode() ->
dev_uc_sync()/dev_mc_sync(), and macsec, via dev_uc_add(real_dev,
dev->dev_addr) in macsec_dev_open() and the syncs in
macsec_dev_set_rx_mode(). After the flush, the upper device's entries
still have sync_cnt == 1 and the extra refcount.

On bond failover, bond_hw_addr_swap() -> bond_hw_addr_flush() ->
dev_mc_unsync() reaches:

net/core/dev_addr_lists.c:__hw_addr_unsync_one() {
	err = __hw_addr_del_ex(to_list, ha->addr, addr_len, ha->type,
			       false, true);
	if (err)
		return;
	ha->sync_cnt--;
}

This returns early on -ENOENT. __hw_addr_sync() then skips the entry for
the new active slave, because sync_cnt is still non-zero:

	if (!ha->sync_cnt) {
		err = __hw_addr_sync_one(to_list, ha, addr_len);
	...

Would the bond's uc/mc addresses then never be synced to the new active
slave?

The same applies to AF_PACKET PACKET_ADD_MEMBERSHIP. The packet_mclist
entry survives the flush. If addr_len later returns to its original value
(for example ETHER -> NONE -> ETHER), packet_dev_mc() passes its check on
close or drop:

	if (i->alen != dev->addr_len)
		return -EINVAL;
	...
	return dev_mc_del(dev, i->addr);

Can this plain delete in __hw_addr_del_entry() decrement, or even free,
an entry that now belongs to another holder (SIOCADDMULTI, IPv6, or an
upper device's sync)?

bonding and team only flush their own master lists, and only when they
have no lower ports, so no downstream sync state exists at that point.
tun can be a lower device and has no such check. Should it handle this
case differently?

>  			tun->dev->type = (int) arg;
> -			tun->dev->addr_len = tun_get_addr_len(tun->dev->type);
> +			tun->dev->addr_len = addr_len;

[Severity: High]
Is the uninitialized-byte exposure described in the commit message still
reachable through a race here?

dev_uc_flush() and dev_mc_flush() each take and drop netif_addr_lock_bh.
The dev->type and dev->addr_len stores come afterwards, as plain stores
outside that lock. __dev_mc_add() reads dev->addr_len under the addr
lock:

	err = __hw_addr_add_ex(&dev->mc, addr, dev->addr_len,

IPV6_ADD_MEMBERSHIP does not take RTNL. do_ipv6_setsockopt() only does
sockopt_lock_sock(), and the join path is:

__ipv6_sock_mc_join()
  ip6_mc_find_dev()
  __ipv6_dev_mc_inc()          /* holds only idev->mc_lock */
    igmp6_group_added()
      ndisc_mc_map(&mc->mca_addr, buf, dev, 0)  /* uses dev->type */
      dev_mc_add(dev, buf)

igmp6_group_added() does this before its IFF_UP check, so it also runs
on the down device that TUNSETLINK requires.

Take a tap switching from ARPHRD_ETHER (addr_len 6) to ARPHRD_IP6GRE
(addr_len 16):

TUNSETLINK                        IPV6_ADD_MEMBERSHIP
PRE_TYPE_CHANGE (ipv6_mc_unmap)
dev_mc_flush()
                                  mutex_lock(&idev->mc_lock)
                                  ndisc_mc_map() fills 6 bytes
                                  __dev_mc_add() reads addr_len == 6
                                  __hw_addr_create(): kmalloc(),
                                    memcpy() of 6 bytes
dev->addr_len = 16
POST_TYPE_CHANGE (ipv6_mc_remap)
  igmp6_group_added() skips the
  group, MAF_LOADED already set

The entry survives. Afterwards, dev_mc_seq_show() (/proc/net/dev_mcast)
and dev_mc_fill_addr() (RTM_GETMULTICAST) copy dev->addr_len bytes of
ha->addr to user space:

	nla_put(skb, IFA_MULTICAST, dev->addr_len, ha->addr) ||

Since __hw_addr_create() does not zero the allocation, wouldn't 10 of
those 16 bytes be uninitialized slab memory?

There is also a stack variant. idev->mc_lock is a mutex, so the joining
thread can be preempted after ndisc_mc_map() has written only 6 bytes of
the on-stack buf[MAX_ADDR_LEN]. If TUNSETLINK then flushes and stores
addr_len = 16, its POST remap blocks on mc_lock. When the join resumes,
dev_mc_add() copies 16 bytes from buf into a long-lived netdev_hw_addr,
10 of them uninitialized stack.

Would the flush and the dev->type/dev->addr_len update need to be atomic
under netif_addr_lock_bh? Would mappers that build the address from
dev->type also need to agree with the addr_len used for the copy, for
example by zero-initializing buf in igmp6_group_added() or re-checking
under the lock?

>  			netif_info(tun, drv, tun->dev, "linktype set to %d\n",
>  				   tun->dev->type);
>  			call_netdevice_notifiers(NETDEV_POST_TYPE_CHANGE,

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261118125443.1137177-1-edumazet%40kernel.org

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

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

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-18 12:54 [PATCH net] tun: flush uc and mc addresses in TUNSETLINK Eric Dumazet
2026-11-18 12:58 ` netdev-bot+sinfo
2026-11-19  8:34   ` Eric Dumazet
2026-11-18 23:47 ` Willem de Bruijn
2026-11-19 22:17 ` netdev-bot+sashiko

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