๐Ÿš€ go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #9060

Re: [PATCH net] genetlink: Reject joining multicast groups no family owns

#9060
From: netdev-bot+sashiko
Date: Fri, 30 Oct 2026 22:40
115 lines
12237 bytes
Thank you for your contribution! Sashiko AI review found 1 potential
issue(s) to consider.

Critical: 0 ยท High: 1 ยท Medium: 0 ยท 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 is incomplete because of a check-then-use race.

--

genetlink: Reject joining multicast groups no family owns

This patch makes genl_bind() return -ENOENT when no registered family
owns the requested multicast group ID. Before the patch such joins
succeeded. If a family with GENL_MCAST_CAP_* flags was later given that
ID, the socket stayed a member.

Link: https://lore.kernel.org/netdev/179324692107.3134.14443689892607921337@kernel.org/

> diff --git a/net/netlink/genetlink.c b/net/netlink/genetlink.c
> index 5cc1037d4917e..f038f04ef4ead 100644
> --- a/net/netlink/genetlink.c
> +++ b/net/netlink/genetlink.c
> @@ -1825,7 +1825,7 @@ static int genl_bind(struct net *net, int group)
>  {
>  	const struct genl_family *family;
>  	unsigned int id;
> -	int ret = 0;
> +	int ret = -ENOENT;
>  
>  	down_read(&cb_lock);
>  
> @@ -1841,6 +1841,7 @@ static int genl_bind(struct net *net, int group)
>  			continue;
>  
>  		grp = &family->mcgrps[i];
> +		ret = 0;
>  		if ((grp->flags & GENL_MCAST_CAP_NET_ADMIN) &&
>  		    !ns_capable(net->user_ns, CAP_NET_ADMIN))
>  			ret = -EPERM;

[Severity: High]
Does this fully close the case described in the commit message?

genl_bind() checks ownership and the GENL_MCAST_CAP_* flags under
down_read(&cb_lock). It drops the lock before it returns. The caller
sets the membership bit only afterwards:

net/netlink/af_netlink.c:netlink_setsockopt() {
    ...
		if (optname == NETLINK_ADD_MEMBERSHIP && nlk->netlink_bind) {
			err = nlk->netlink_bind(sock_net(sk), val);
			if (err)
				return err;
		}
		netlink_table_grab();
		netlink_update_socket_mc(nlk, val,
					 optname == NETLINK_ADD_MEMBERSHIP);
		netlink_table_ungrab();
    ...
}

netlink_bind() follows the same pattern. It updates nlk->groups[0] under
netlink_table_grab() after genl_bind() has returned.

The owning family can be unregistered inside that window, for example by
a module unload or by a module init that fails after
genl_register_family(). Can the following sequence happen?

CPU1 (unprivileged)                  CPU2
netlink_setsockopt(ADD_MEMBERSHIP, G)
  genl_bind()
    down_read(&cb_lock)
    family F owns G, no caps, ret = 0
    up_read(&cb_lock)
                                     genl_unregister_family(F)
                                       down_write(&cb_lock)
                                       genl_unregister_mc_groups()
                                         __netlink_clear_multicast_users()
                                           (CPU1 not a member yet)
                                         clear_bit(G, mc_groups)
                                       idr_remove()
  netlink_table_grab()
  netlink_update_socket_mc(nlk, G, 1)

After this sequence the socket is a member of a group ID that no family
owns.

Later, genl_register_family()->genl_validate_assign_mc_groups()->
genl_allocate_reserve_groups() can give G to a family whose group has
GENL_MCAST_CAP_NET_ADMIN or GENL_MCAST_CAP_SYS_ADMIN, such as psample,
mptcp pm, ioam6 or cifs. Nothing clears the existing members of G at
that point. do_one_broadcast() delivers based only on the membership
bit. The CTRL_CMD_GETFAMILY->request_module() autoload path from the
commit message could still trigger that registration.

That is the end state the commit message says is fixed:

  "A family registered later can get that ID, and the socket stays a
  member: nothing checks it again."

Would it be more robust to clear existing members of newly assigned
group IDs in genl_validate_assign_mc_groups()? That could run under
netlink_table_grab(), the same way genl_unregister_mc_groups() clears
them on removal. It would cover both the original case and this race,
instead of relying on the check in genl_bind().

-- 
Sashiko AI review ยท https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261029062214.3407223-1-anilkaushikwireless%40gmail.com
Technical Details
Message-ID: <179340003139.3131.11274717768928642724@kernel.org>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-353994-linux-kernel-netdev=dewy.ru
References: <20261029062214.3407223-1-anilkaushikwireless@gmail.com>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-353994-linux-kernel-netdev=dewy.ru
From: netdev-bot+sashiko@kernel.org
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH net] genetlink: Reject joining multicast groups no family owns
Date: Fri, 30 Oct 2026 22:40:31 +0000
Organization: Usenet Network
Message-ID: <179340003139.3131.11274717768928642724@kernel.org>
References: <20261029062214.3407223-1-anilkaushikwireless@gmail.com>
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="2327821"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:SIM/+RXRPmKtI8vj2xCT2ywMUq4= sha256:NI7bBGj2YijRT7ieAl7CtAimZIQyvL6kiP1Uj5Fr9vc=
	sha1:2dhWABiWIU9dW+k8HDk3uLlohXo= sha256:lVrnUPG7T1RmxMy8tHo4CqCj9YpMlFqQGS6bR6P208o=
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 47BDC125CA7; Sat, 31 Oct 2026 01:42:49 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.4
X-Spam-Status: No, score=-3.4 tagged_above=-9999 required=6.31
	tests=[DCC_REPUT_70_89=0.1, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1,
	DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1,
	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 (2048-bit key)
	header.d=kernel.org
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 Inb0K6LyZKye;
	Sat, 31 Oct 2026 01:42:46 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.105.105.114; helo=tor.lore.kernel.org; envelope-from=netdev+bounces-353994-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> 
X-Authentication-Results: OpenDMARC; dmarc=pass (p=quarantine dis=none) header.from=kernel.org
X-Received: from tor.lore.kernel.org (tor.lore.kernel.org [172.105.105.114])
	by mail.dewy.ru (Postfix) with ESMTPS id E0427125CA6; Sat, 31 Oct 2026 01:42:37 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
	by tor.lore.kernel.org (Postfix) with ESMTP id 73BE12D8C3; Fri, 30 Oct 2026 22:40:52 +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=1793400052;
	b=0ZBoeggM4GjuzI7cSI2IDemovsF6ugnq2qjPOtWSOdwxbvljeJLZCzuvVvGyp9rN3UMx
	 duFobVmFqB0ZvS/XeCzCKNUc+Hih8djhfjj0f6ajDr+Ekof5V33/6zyTeoDQs9mGjZCTR
	 nt4KlrolxvtJqlWwrTNUprlCUU1ARLX5CrbMxA7qrA+8zsJGfFDDgsRAve/4NfRz5wimY
	 D+d9nr1MVna155m6iP1hOtkU/TlVVTE3bnYYYsvGNU/Wr37Sp/U2XLL6UGniM+SW++09D
	 wi3+UOTPVg9PWOtLJ9qB8g2XaXg3lcZRAJpvhbBb/V8YiDXq+iiXYBt5VrbFZZQylJA==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1793400052;
	h=X-Original-To:Received:Received:DKIM-Signature:Subject:From:To:Cc:
	 Date:Message-ID:In-Reply-To:References:X-sashiko-severity:
	 Content-Type:Content-Transfer-Encoding:X-Mailing-List:List-Id:
	 List-Post:List-Help:List-Subscribe:List-Unsubscribe:List-Owner:
	 Precedence:MIME-Version;
	bh=RzzWVhBwctPLl5vkJHCmyC9VNdTXXXJa8A/zWY/C3CA=;
	b=S1G6JknqX9rU0yhTytY3w/zuWEtI+3kJWDUxu3ryey10NaHoNPXkTQAQJyLvRsHEyTfv
	 rORZXWttTZsuiitn/JFixEIiXeZ0wAo2PEmAfU7H6CWBBwUsZH2TZBiiNR5/6SW0uMcl5
	 Dv+tCas8iROqdzeFqjcw/ughKkZHh9OOK0FWiyJG3W+icEMlg9NHeU9p3kgdwaBot6uW5
	 LvJrwdTenMx2/elkNkflCO3J9SzkDS3+QjXMxUCMBH8aA7WB6DjjTrpZXXQ52tfmPjc1R
	 KIaC8K/s+1xzo4wF25IFUYx+NUHdc0Ex059Gsg7GHC6G9UA0VjoroE7LU3KmUAHCJTw==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; 
	dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=DgjS2Jko;
	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 2C4AE606A325;
	Fri, 30 Oct 2026 22:40:47 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key, unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=DgjS2Jko
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
	t=1793400033;
	b=re0SholfyNY+yaWwxPgydsVF68wHClF5krODU29hkNPAv4ERXIetjV3r1LOBjGn7cm38
	 NfgONRJM130QkS9G7xAlMzVBlanW5iPT8IzYP0NPZwGnKihh3+UML7kz4WQjNdcrUDA4R
	 xCeeAol2zXxUSdRIm+mSvXzfrvpF+com1AwJGHuwebGvXhaSnqQFFt8zWTXHk0ZxkfSOT
	 iDp7V01iT5eqkrjiz+Jl8mXgFAbsn2q9hyW/VsbArKUJfTxmfCW6AringxsMl78bSL8pL
	 gmsGAc3DIZm7i9wDH/z4Fa35jgRkA7AvfuG6Aep/7dGPGEAh6AiVTKqier8/0k4pk7w==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1793400033;
	h=Received:DKIM-Signature:Subject:From:To:Cc:Date:Message-ID:
	 In-Reply-To:References:X-sashiko-severity:Content-Type:
	 Content-Transfer-Encoding:MIME-Version;
	bh=RzzWVhBwctPLl5vkJHCmyC9VNdTXXXJa8A/zWY/C3CA=;
	b=XJTIPpgnN95xT8rDVmX2IImJ6pQpWIfhNQ9I544qg8akLnKlcqHP5c2rPIYLqoy9//Yj
	 hIJtlfD+wg/Sw3ZZG2nKbl1RR59P4osgGmV26SF11/Wuedv1CPI5Tshln6/vU7X6ucXm/
	 QXHDYRdMwgjt7OycHOOJNnUkf0FBuHRYmEetfMcQJ48SwzYDLFkL1kZFAZxjH2CNKp5uN
	 hlElOfbo3W/2ri5eNUSVHlZrZu2V7eAnbuLCqGTDhVcnxwvkTgy/k7XqJnJgNxl3pNiVX
	 VjzruueYLKXp9k721flhrSfIWmVdfso7FVW3CSSgvl2hZAbwb9epqKzoIClcc2L6CTA==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; 
	dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=DgjS2Jko;
	arc=none smtp.remote-ip=100.103.45.18
X-Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature ECDSA (prime256v1))
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with ESMTPS id C72A4606A333;
	Fri, 30 Oct 2026 22:40:32 +0000 (UTC)
X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id C6AEA1F000C1;
	Fri, 30 Oct 2026 22:40:31 +0000 (UTC)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org;
	s=k20260515; t=1793400032;
	bh=RzzWVhBwctPLl5vkJHCmyC9VNdTXXXJa8A/zWY/C3CA=;
	h=Subject:From:To:Cc:Date:In-Reply-To:References;
	b=DgjS2Jkon2GSzzEl8G0UKsG2Y7JNRvoEbNUA3XG4cM67DSth8TJnVfQEvDIcHpPU9
	 jprJWZvLfNs3X0Hs95FnLGgwo/eye7SmFMO2MFqRE/mLAmPYweR092T06EKwl+TYQI
	 4gkzbSROFh3Y5JHJkfoWXH59/vXhrOFJATYAJSZ8ttMvvjWxNcYxfXbCSQhm5zm2+b
	 moye3Rl9VTqm5e4CTD8R9zjtLrNnqkygMw/9C0AbCC5YkS3yuQRLazLFfVqxn/0pyn
	 sqFss0bGoj94AuXhDYYK35ZDLL722E+V43SDzk0PClJOo4Zqt1a7zgBYTg1Fq4aEh2
	 updJUETFowEIw==
X-Cc: netdev@vger.kernel.org, davem@davemloft.net, edumazet@kernel.org,
 kuba@kernel.org, pabeni@redhat.com, horms@kernel.org, idosch@nvidia.com,
 nicolas.dichtel@6wind.com, v3rdant.xiang@gmail.com, aliceryhl@google.com,
 linux-kernel@vger.kernel.org
X-In-Reply-To: <20261029062214.3407223-1-anilkaushikwireless@gmail.com>
X-sashiko-severity: High
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