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 --- Cc: Henry Martin Cc: Willem de Bruijn Cc: Jason Wang Cc: Andrew Lunn --- 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