Netdev List
 help / color / mirror / Atom feed
From: netdev-bot+sashiko@kernel.org
To: anilkaushikwireless@gmail.com
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,
	jacob.e.keller@intel.com, jiri@resnulli.us, fw@strlen.de,
	martineau@kernel.org, v3rdant.xiang@gmail.com,
	aliceryhl@google.com, linux-kernel@vger.kernel.org,
	nhorman@tuxdriver.com, shuah@kernel.org,
	linux-kselftest@vger.kernel.org
Subject: Re: [PATCH net v8 1/2] genetlink: Reject joining multicast groups no family owns
Date: Tue, 24 Nov 2026 15:56:34 +0000	[thread overview]
Message-ID: <179553579407.3135.13476478403966318528@kernel.org> (raw)
In-Reply-To: <20261123155503.2497063-2-anilkaushikwireless@gmail.com>

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

Critical: 0 · High: 0 · 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).

- [Medium] Check-then-act race (TOCTOU) between the ownership/capability
  check in genl_bind() and the point where af_netlink sets the…

--

genetlink: Reject joining multicast groups no family owns

With this commit, genl_bind() returns -ENOENT when no genetlink family
owns the requested multicast group. Unprivileged users can then no longer
join free group IDs that a privileged family takes later. netlink_bind()
skips such IDs in a bind() mask instead of failing, and
setsockopt(NETLINK_ADD_MEMBERSHIP) returns the error.

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..e5d4f3c4e22ac 100644
> --- a/net/netlink/genetlink.c
> +++ b/net/netlink/genetlink.c

[ ... ]

> @@ -1825,7 +1827,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 +1843,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: Medium]
The commit message says "This does not cover a family that is
unregistered between the check and the point where the membership bit is
set."

Can that window still leave a socket as a member of a group ID that no
family owns? That is the state this patch is meant to prevent.

genl_bind() decides ownership under down_read(&cb_lock). It then drops
cb_lock and returns 0. The caller sets the bit later, and holds only
netlink_table_grab() when it does:

netlink_bind()
    err = nlk->netlink_bind(net, group + 1);  /* cb_lock taken, dropped */
    ...
    netlink_table_grab();
    ...
    nlk->groups[0] = (nlk->groups[0] & ~0xffffffffUL) | groups;

netlink_setsockopt(NETLINK_ADD_MEMBERSHIP) follows the same pattern
through netlink_update_socket_mc().

One possible interleaving:

CPU0                              CPU1
bind() to group X of family F
  genl_bind() returns 0
  up_read(&cb_lock)
                                  genl_unregister_family(F)
                                    genl_lock_all()
                                    genl_unregister_mc_groups()
                                      __netlink_clear_multicast_users(X)
                                        /* CPU0 bit not set yet */
                                      clear_bit(X, mc_groups)
                                    idr_remove()
  netlink_table_grab()
  sets bit X in nlk->groups

After this, the socket is a member of X and X has no owner.

A later family G can be given X by find_first_zero_bit() in
genl_allocate_reserve_groups(). An unprivileged user can trigger that
registration with CTRL_CMD_GETFAMILY -> request_module().

Nothing checks the socket again. It would get G's notifications even when
the group has GENL_MCAST_CAP_NET_ADMIN or GENL_MCAST_CAP_SYS_ADMIN set.

The unregister side usually needs a privileged rmmod, but an unprivileged
user can keep calling bind() until an admin unloads a module.

Module init error paths, such as ila_init(), seg6_init() and fou_init(),
can also unregister a family. That can happen after a request_module()
the attacker triggered, if init fails partway.

There is also a side effect. F->bind(i) ran for the old family, but on
close genl_unbind() would call G->unbind(i). The family bind and unbind
callbacks could then get out of balance.

Could this be closed fully? One option is to recheck ownership, or a
registration generation, under netlink_table_grab() before setting the
bit. Another is to clear stale members of a group ID when it is given to
a new family.

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261123155503.2497063-1-anilkaushikwireless%40gmail.com

  reply	other threads:[~2026-11-24 15:56 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-23 15:55 [PATCH net v8 0/2] genetlink: Reject joining multicast groups no family owns Anil Kaushik
2026-11-23 15:55 ` [PATCH net v8 1/2] " Anil Kaushik
2026-11-24 15:56   ` netdev-bot+sashiko [this message]
2026-11-23 15:55 ` [PATCH net v8 2/2] selftests: net: test joining genetlink " Anil Kaushik
2026-11-24 15:56   ` netdev-bot+sashiko

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=179553579407.3135.13476478403966318528@kernel.org \
    --to=netdev-bot+sashiko@kernel.org \
    --cc=aliceryhl@google.com \
    --cc=anilkaushikwireless@gmail.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@kernel.org \
    --cc=fw@strlen.de \
    --cc=horms@kernel.org \
    --cc=idosch@nvidia.com \
    --cc=jacob.e.keller@intel.com \
    --cc=jiri@resnulli.us \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=martineau@kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=nhorman@tuxdriver.com \
    --cc=nicolas.dichtel@6wind.com \
    --cc=pabeni@redhat.com \
    --cc=shuah@kernel.org \
    --cc=v3rdant.xiang@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox