Article View: linux.kernel.netdev
Article #21561Re: [PATCH net] ipv6: mcast: do not pass uninitialized bytes to dev_mc_add()
From: 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>
Technical Details
Message-ID:
<20261124065152.GD14932@Liu-laptop>Path:
mbox-mo1.pugleaf.net!srv.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-370056-linux-kernel-netdev=dewy.ruReferences:
<20261123124458.205233-1-edumazet@kernel.org>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-370056-linux-kernel-netdev=dewy.ru From: hangbin.liu@linux.dev (Hangbin Liu) Newsgroups: linux.kernel.netdev Subject: Re: [PATCH net] ipv6: mcast: do not pass uninitialized bytes to dev_mc_add() Date: Tue, 24 Nov 2026 14:51:52 +0800 Organization: Usenet Network Message-ID: <20261124065152.GD14932@Liu-laptop> References: <20261123124458.205233-1-edumazet@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: usenet.network; logging-data="4073352"; mail-complaints-to="abuse@usenet.network" Cancel-Lock: sha1:z+0qhfNvgw0mS1ukUEdZ7ZZpjlM= sha256:LUQPKV5+WOD8jbsAESZqpYrvbG/j8HDks97y4RUuQMI= sha1:Urq9uVSP0gqx4R7dNmj54g+mlyw= sha256:DbSSLflDEET0TC0Ti/Pl3SuwaBdmKqbhUDJIcKsm0oA= Content-Disposition: inline List-ID: <netdev.vger.kernel.org> X-Mailpost-Empty-Hdrs: X-Spam-Level X-Received: from localhost (localhost [127.0.0.1]) by mail.dewy.ru (Postfix) with ESMTP id 9BD25125DD4; Tue, 24 Nov 2026 09:52:15 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at usenet.network X-Spam-Flag: NO X-Spam-Score: -3.05 X-Spam-Status: No, score=-3.05 tagged_above=-9999 required=6.31 tests=[DCC_REPUT_70_89=0.1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, HEADER_FROM_DIFFERENT_DOMAINS=0.249, MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001] autolearn=ham autolearn_force=no X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (1024-bit key) header.d=linux.dev X-Received: from mail.dewy.ru ([127.0.0.1]) by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 2aPHoIQlA1QI; Tue, 24 Nov 2026 09:52:12 +0300 (MSK) X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-370056-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> X-Authentication-Results: OpenDMARC; dmarc=fail (p=none dis=none) header.from=linux.dev X-Received: from sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10]) by mail.dewy.ru (Postfix) with ESMTPS id BEBD9125DD3; Tue, 24 Nov 2026 09:52:03 +0300 (MSK) X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92]) by sea.lore.kernel.org (Postfix) with ESMTP id 3D8D72BE86; Tue, 24 Nov 2026 06:52:02 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1 X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1795503121; b=uH+pguScWCkE7D6Tsa5hWoh3MwMvr2SjlPNuf90zzIx/kCTSIU2mFIGONfgxUknnMie5 L/nDQnN0Ktdb7W80rKrVuxgBJmRk+G9HqXOPqI0B2WpRk9+0zYRgdETrvoVnI2yD7pgeQ II15Juc5FFSnGnHzq6UWCdYrtQHPJan6RiCE+YO/JA64xKLbxdQEfvtRy3GnN2W5pREk4 EbEDCeSqR1yFb8gOhqoLJTq6bNHyA00x3jwNM8iCO+5/NeqfQ/XkbOVdl7oPSRldiQDXY RHm/wV/Gi+SpLTey0/ykectX3PFPj8k8CedUNcO/F2TMg1ktdc8vZxKZMsnRQxtksPQ== X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795503121; h=X-Original-To:Received:DMARC-Filter:X-Envelope-To:DKIM-Signature: X-Envelope-To:Received:X-Mizu-Trace-ID:X-Migadu-Flow:Date:From:To:Cc: Subject:Message-ID:References:X-Mailing-List:List-Id:List-Post: List-Help:List-Subscribe:List-Unsubscribe:List-Owner:Precedence: MIME-Version:Content-Type:Content-Disposition:In-Reply-To; bh=+TQgzbu7eki9ghahx9MmLJOAjgLfaobMZIU49rinkbg=; b=idHzPTuJ+7jM0JUlgNS2iJUXxf8W/A7FFRq5wNvfjVD+JqFb3UnRoFwHbL6ydOof7VXz 0q6aHXyVo/rOw1ZsrYT/yl23vm2evtyu9O4lM0VejWNn7QKZRuRA072g1s7v0F1cKIBaI MzYCuA8H9g3D6he7+Ydpq3kmH16YO0xv0V/zcpwcFRq8kmbDzdFzny66x7PqlWWcY9mvK Yo+aA+fv2Bt1WlYRrkPBOUDrmO+SbCcx57kvMrmkkhjGHEqP8xLoe9MwCpd2ku20TWn+M ji5vHiy76cq/DgowrTsoUUXM1m2rHSPDoTG6h4RsTFPV0JLfaCxogPYgyTin9BKsNLw== X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dkim=pass header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=fmpHXC4r; dmarc=pass header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1 X-Received: from localhost.localdomain (localhost [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 6F626606A32C; Tue, 24 Nov 2026 06:52:01 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key, unprotected) header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=fmpHXC4r X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=91.218.175.159 X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795503120; b=BZD+tz3892zW3kqSUB7USGP4CeQhf/6TwDqE+5e0g+RiZThGV/cht8TFYPVpyHwwausR hPEpqc4DgXIqQtj8qStsMoGsA/3lgAvf7jDLbwSWpjojMkgSwyZG68iCzOKoilpEjTKfv P3Rb/UJKrqNcNOLAbqQ+b/DZNFlS6ZPBt5IxAMjwEU/eIQo+EU0Erh4RZQFVO77b24cCZ nMWMXsEGB08H6ZdAh1+5MgoKgIo3YpGzRXAUhQq8MnDHvx26zd2ZLp57Cs3znnYkomCwU inSqmec5xCWJvcpuXH0se4bDyZYqphaveduF62QCeTlgxid38VrrxdHZbRazRudsgdQ== X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795503120; h=DMARC-Filter:X-Envelope-To:DKIM-Signature:X-Envelope-To:Received: X-Mizu-Trace-ID:X-Migadu-Flow:Date:From:To:Cc:Subject:Message-ID: References:MIME-Version:Content-Type:Content-Disposition:In-Reply-To; bh=+TQgzbu7eki9ghahx9MmLJOAjgLfaobMZIU49rinkbg=; b=hK5w/pXulYszvajMrgcX/05vfwsa1S5cfXjwuqT6ISAb9ETBx1Nzk2QLVzjdP9AFXT9W 5iiGF4dYjC9cEiuTHMojsFEp0RdXtKCJFo6x6zBKEILc0iQ6Wmn+8wMQlV6kLYZ2JaJTF pgZu+NFH9RLW4/OC8i2g1JWN9VJNc2OeDuQKfyvy0MB6y7rXxmnS8rhTb6FNeyyT9qwLv 1gpbkFTo5kpFwzTcX8iXMnV+9LMKmqHpjDcm8EcRdvHAj5nIeef30ydnTlAXUK3l1DWgm IpueeIFVUUNWwRWzH71vNhEX65t9d+cDy219I/wA+qHyHBcVy0XBZxX9IImp2ACCX1w== X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=fmpHXC4r; arc=none smtp.remote-ip=91.218.175.159 X-Received: from mta0.migadu.com (out-159.mta0.migadu.com [91.218.175.159]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D0A29606A31E for <netdev@vger.kernel.org>; Tue, 24 Nov 2026 06:51:59 +0000 (UTC) X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org D0A29606A31E X-Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev X-Envelope-To: netdev@vger.kernel.org X-DKIM-Signature: a=rsa-sha256; bh=2VNXjrXER2Twx8s+CxDzcOf/vNM716Jpu07paukE/EU=; c=simple/simple; d=linux.dev; h=from:to:subject:date:message-id:mime-version:content-type; s=key1; t=1795503117; v=1; x=1796107917; b=fmpHXC4rnHqfqX9Ca/U7SjntT8nkSqWWiGB3rwFSX4UkTOm+GI3IuiUxLLSnFPTLBgF94sWp itESCPZSZZG7hDfTEbSIR87Ihn9I8UWq4i4mcRSHprUnVyPOxxZ8U1zaLdWaT8tNeQksMRGgW67 BUPR25YxBvzIchdNBSOXKDTc= X-Envelope-To: netdev@vger.kernel.org X-Received: by mta12.migadu.com with ESMTPS id b2dea94989d3552c; Tue, 24 Nov 2026 06:51:57 +0000 X-Mizu-Trace-ID: b2dea94989d3552c X-Migadu-Flow: FLOW_OUT X-Cc: "David S . Miller" <davem@davemloft.net>, Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>, Willem de Bruijn <willemb@google.com>, David Ahern <dsahern@kernel.org>, Ido Schimmel <idosch@nvidia.com>, Simon Horman <horms@kernel.org>, netdev@vger.kernel.org, Kuniyuki Iwashima <kuniyu@google.com> X-Mailing-List: netdev@vger.kernel.org X-List-Post: <mailto:netdev@vger.kernel.org> X-List-Help: <mailto:netdev+help@vger.kernel.org> X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org> X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org> X-List-Owner: <mailto:netdev+owner@vger.kernel.org> X-Precedence: list X-In-Reply-To: <20261123124458.205233-1-edumazet@kernel.org>