Thread View: linux.kernel.netdev
3 messages
3 total messages
Started by Eric Dumazet
Mon, 23 Nov 2026 12:44
[PATCH net] ipv6: mcast: do not pass uninitialized bytes to dev_mc_add()
Author: Eric Dumazet
Date: Mon, 23 Nov 2026 12:44
Date: Mon, 23 Nov 2026 12:44
59 lines
9634 bytes
9634 bytes
igmp6_group_added() and igmp6_group_dropped() build a link-layer
multicast address in an on-stack buffer with ndisc_mc_map(), which
fills a number of bytes depending on dev->type.
dev_mc_add() and dev_mc_del() then use dev->addr_len bytes of it.
Since IPv6 multicast joins and leaves no longer hold RTNL, dev->type
and dev->addr_len can change between the two steps, for instance with
TUNSETLINK, or when bonding or team change their type.
If addr_len grows (eg ARPHRD_ETHER -> ARPHRD_IP6GRE), dev_mc_add()
copies uninitialized stack bytes into a netdev_hw_addr, which can
later be dumped to user space by /proc/net/dev_mcast and
RTM_GETMULTICAST.
Zero the buffers.
Found by Sashiko AI review of a tun patch, by code inspection only.
Kernels built with CONFIG_INIT_STACK_ALL_ZERO=y are not affected.
Fixes: 1767bb2d47b7 ("ipv6: mcast: Don't hold RTNL for IPV6_ADD_MEMBERSHIP and MCAST_JOIN_GROUP.")
Link: https://lore.kernel.org/netdev/179512665919.3136.5931555157250030152@kernel.org/
Cc: Kuniyuki Iwashima <kuniyu@google.com>
Signed-off-by: Eric Dumazet <edumazet@kernel.org>
---
net/ipv6/mcast.c | 10 ++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)
diff --git a/net/ipv6/mcast.c b/net/ipv6/mcast.c
index ecef55f26189..bce7287ae709 100644
--- a/net/ipv6/mcast.c
+++ b/net/ipv6/mcast.c
@@ -684,7 +684,10 @@ bool inet6_mc_check(const struct sock *sk, const struct in6_addr *mc_addr,
static void igmp6_group_added(struct ifmcaddr6 *mc)
{
struct net_device *dev = mc->idev->dev;
- char buf[MAX_ADDR_LEN];
+ /* RTNL might not be held: dev->type and dev->addr_len can change.
+ * Make sure dev_mc_{add|del}() do not use uninitialized bytes.
+ */
+ char buf[MAX_ADDR_LEN] = {};
mc_assert_locked(mc->idev);
@@ -720,7 +723,10 @@ static void igmp6_group_added(struct ifmcaddr6 *mc)
static void igmp6_group_dropped(struct ifmcaddr6 *mc)
{
struct net_device *dev = mc->idev->dev;
- char buf[MAX_ADDR_LEN];
+ /* RTNL might not be held: dev->type and dev->addr_len can change.
+ * Make sure dev_mc_{add|del}() do not use uninitialized bytes.
+ */
+ char buf[MAX_ADDR_LEN] = {};
mc_assert_locked(mc->idev);
--
2.53.0
Re: [PATCH net] ipv6: mcast: do not pass uninitialized bytes to dev_mc_add()
Author: Hangbin Liu
Date: Tue, 24 Nov 2026 06:51
Date: Tue, 24 Nov 2026 06:51
63 lines
10701 bytes
10701 bytes
On Mon, Nov 23, 2026 at 01:44:58PM +0100, Eric Dumazet wrote:
> igmp6_group_added() and igmp6_group_dropped() build a link-layer
> multicast address in an on-stack buffer with ndisc_mc_map(), which
> fills a number of bytes depending on dev->type.
>
> dev_mc_add() and dev_mc_del() then use dev->addr_len bytes of it.
>
> Since IPv6 multicast joins and leaves no longer hold RTNL, dev->type
> and dev->addr_len can change between the two steps, for instance with
> TUNSETLINK, or when bonding or team change their type.
>
> If addr_len grows (eg ARPHRD_ETHER -> ARPHRD_IP6GRE), dev_mc_add()
> copies uninitialized stack bytes into a netdev_hw_addr, which can
> later be dumped to user space by /proc/net/dev_mcast and
> RTM_GETMULTICAST.
>
> Zero the buffers.
>
> Found by Sashiko AI review of a tun patch, by code inspection only.
> Kernels built with CONFIG_INIT_STACK_ALL_ZERO=y are not affected.
>
> Fixes: 1767bb2d47b7 ("ipv6: mcast: Don't hold RTNL for IPV6_ADD_MEMBERSHIP and MCAST_JOIN_GROUP.")
> Link: https://lore.kernel.org/netdev/179512665919.3136.5931555157250030152@kernel.org/
> Cc: Kuniyuki Iwashima <kuniyu@google.com>
> Signed-off-by: Eric Dumazet <edumazet@kernel.org>
> ---
> net/ipv6/mcast.c | 10 ++++++++--
> 1 file changed, 8 insertions(+), 2 deletions(-)
>
> diff --git a/net/ipv6/mcast.c b/net/ipv6/mcast.c
> index ecef55f26189..bce7287ae709 100644
> --- a/net/ipv6/mcast.c
> +++ b/net/ipv6/mcast.c
> @@ -684,7 +684,10 @@ bool inet6_mc_check(const struct sock *sk, const struct in6_addr *mc_addr,
> static void igmp6_group_added(struct ifmcaddr6 *mc)
> {
> struct net_device *dev = mc->idev->dev;
> - char buf[MAX_ADDR_LEN];
> + /* RTNL might not be held: dev->type and dev->addr_len can change.
> + * Make sure dev_mc_{add|del}() do not use uninitialized bytes.
> + */
> + char buf[MAX_ADDR_LEN] = {};
>
> mc_assert_locked(mc->idev);
>
> @@ -720,7 +723,10 @@ static void igmp6_group_added(struct ifmcaddr6 *mc)
> static void igmp6_group_dropped(struct ifmcaddr6 *mc)
> {
> struct net_device *dev = mc->idev->dev;
> - char buf[MAX_ADDR_LEN];
> + /* RTNL might not be held: dev->type and dev->addr_len can change.
> + * Make sure dev_mc_{add|del}() do not use uninitialized bytes.
> + */
> + char buf[MAX_ADDR_LEN] = {};
>
> mc_assert_locked(mc->idev);
>
> --
> 2.53.0
>
Reviewed-by: Hangbin Liu <liuhangbin@kylinos.cn>
Re: [PATCH net] ipv6: mcast: do not pass uninitialized bytes to dev_mc_add()
Author: patchwork-bot+netdevbpf
Date: Thu, 26 Nov 2026 00:10
Date: Thu, 26 Nov 2026 00:10
27 lines
8753 bytes
8753 bytes
Hello:
This patch was applied to netdev/net.git (main)
by Willem de Bruijn <willemb@google.com>:
On Mon, 23 Nov 2026 13:44:58 +0100 you wrote:
> igmp6_group_added() and igmp6_group_dropped() build a link-layer
> multicast address in an on-stack buffer with ndisc_mc_map(), which
> fills a number of bytes depending on dev->type.
>
> dev_mc_add() and dev_mc_del() then use dev->addr_len bytes of it.
>
> Since IPv6 multicast joins and leaves no longer hold RTNL, dev->type
> and dev->addr_len can change between the two steps, for instance with
> TUNSETLINK, or when bonding or team change their type.
>
> [...]
Here is the summary with links:
- [net] ipv6: mcast: do not pass uninitialized bytes to dev_mc_add()
https://git.kernel.org/netdev/net/c/58f419bfa4c3
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