* [PATCH net v6] genetlink: Reject joining multicast groups no family owns
@ 2026-11-12 9:42 Anil Kaushik
2026-11-13 15:11 ` Nicolas Dichtel
2026-11-16 9:43 ` netdev-bot+sashiko
0 siblings, 2 replies; 5+ messages in thread
From: Anil Kaushik @ 2026-11-12 9:42 UTC (permalink / raw)
To: netdev
Cc: David S . Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
Simon Horman, Ido Schimmel, Nicolas Dichtel, Jacob Keller,
Jiri Pirko, Florian Westphal, Mat Martineau, XingWang Xiang,
Alice Ryhl, linux-kernel, Anil Kaushik
genl_bind() checks the GENL_MCAST_CAP_* flags of a group only when a
family owns it. For a group ID that no family owns, it returns 0, so any
user can join it.
A family registered later can get that ID, and the socket stays a member:
nothing checks it again. An unprivileged user can join the free IDs, load
a family module with CTRL_CMD_GETFAMILY, which calls request_module(),
and then receive the notifications of a group with
GENL_MCAST_CAP_NET_ADMIN or GENL_MCAST_CAP_SYS_ADMIN. For example the
drop_monitor "events" group always gets ID 1, and is free until the
drop_monitor module is loaded.
Fix by returning -ENOENT from genl_bind() when no family owns the group.
There are no group flags to check before the family registers, so this
applies to privileged callers too: a program that joins a fixed ID such
as NET_DM_GRP_ALERT before the family is loaded no longer gets its
messages. I don't know of a program that does this. One that resolves
the family first still joins.
bind() takes a mask of groups, and most IDs in it can have no owner. Such
a mask used to work, so keep it working: netlink_bind() skips an ID when
the bind callback returns -ENOENT, and joins the others. Only genl_bind()
returns -ENOENT. A skipped ID is not joined, so it is no longer in the
groups that getsockname() and NETLINK_LIST_MEMBERSHIPS report.
setsockopt() returns the error, as it asks for one group.
This does not cover a family that is unregistered between the check and
the point where the membership bit is set.
Found by the Sashiko review of the gtp multicast group fix. Tested as an
unprivileged user who joins all free IDs, then loads gtp and
drop_monitor:
Before:
joins: ok=62 EPERM=2
gtp/gtp (ID 15): member
NET_DM/events (ID 1): member
After:
joins: ok=19 ENOENT=43 EPERM=2
gtp/gtp (ID 15): not member
NET_DM/events (ID 1): not member
bind(), an owned group and free IDs: ok, member of the owned group only
genl_bind() was added, with its first capability check, in the commit
in the Fixes tag.
Link: https://lore.kernel.org/netdev/179324692107.3134.14443689892607921337@kernel.org/
Fixes: 4d54cc32112d ("mptcp: avoid lock_fast usage in accept path")
Signed-off-by: Anil Kaushik <anilkaushikwireless@gmail.com>
---
v6:
- Drop patch 2 of v5, as Jakub found it too ugly. A family unregistered
between the check and setting the membership bit is not covered.
- Say that early joins to fixed IDs stop working, also for privileged
callers, and that NETLINK_LIST_MEMBERSHIPS changes.
- Document the -ENOENT meaning on the bind member.
- Rebase on net/main.
v5: https://lore.kernel.org/netdev/20261104092125.211537-1-anilkaushikwireless@gmail.com/
I used an LLM to help write and review the code, the tests and the
commit message of this patch. I checked and tested every change myself.
include/linux/netlink.h | 3 +++
net/netlink/af_netlink.c | 6 ++++++
net/netlink/genetlink.c | 3 ++-
3 files changed, 11 insertions(+), 1 deletion(-)
diff --git a/include/linux/netlink.h b/include/linux/netlink.h
index 882e9c1b6c1d..b4eb873850e7 100644
--- a/include/linux/netlink.h
+++ b/include/linux/netlink.h
@@ -48,6 +48,9 @@ struct netlink_kernel_cfg {
unsigned int groups;
unsigned int flags;
void (*input)(struct sk_buff *skb);
+ /* -ENOENT means no one owns the group: bind() skips it and joins the
+ * others, setsockopt() returns the error.
+ */
int (*bind)(struct net *net, int group);
void (*unbind)(struct net *net, int group);
void (*release) (struct sock *sk, unsigned long *groups);
diff --git a/net/netlink/af_netlink.c b/net/netlink/af_netlink.c
index 69bb951b5fb8..ee573ba6396d 100644
--- a/net/netlink/af_netlink.c
+++ b/net/netlink/af_netlink.c
@@ -1033,6 +1033,12 @@ static int netlink_bind(struct socket *sock, struct sockaddr_unsized *addr,
err = nlk->netlink_bind(net, group + 1);
if (!err)
continue;
+ /* no one owns this group, still join the others */
+ if (err == -ENOENT) {
+ __clear_bit(group, &groups);
+ err = 0;
+ continue;
+ }
netlink_undo_bind(group, groups, sk);
return err;
}
diff --git a/net/netlink/genetlink.c b/net/netlink/genetlink.c
index 5cc1037d4917..f038f04ef4ea 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;
--
2.25.1
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: [PATCH net v6] genetlink: Reject joining multicast groups no family owns
2026-11-12 9:42 [PATCH net v6] genetlink: Reject joining multicast groups no family owns Anil Kaushik
@ 2026-11-13 15:11 ` Nicolas Dichtel
2026-11-15 2:57 ` Anil Kaushik
2026-11-16 9:43 ` netdev-bot+sashiko
1 sibling, 1 reply; 5+ messages in thread
From: Nicolas Dichtel @ 2026-11-13 15:11 UTC (permalink / raw)
To: Anil Kaushik, netdev
Cc: David S . Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
Simon Horman, Ido Schimmel, Jacob Keller, Jiri Pirko,
Florian Westphal, Mat Martineau, XingWang Xiang, Alice Ryhl,
linux-kernel
Le 12/11/2026 à 10:42, Anil Kaushik a écrit :
> genl_bind() checks the GENL_MCAST_CAP_* flags of a group only when a
> family owns it. For a group ID that no family owns, it returns 0, so any
> user can join it.
>
> A family registered later can get that ID, and the socket stays a member:
> nothing checks it again. An unprivileged user can join the free IDs, load
> a family module with CTRL_CMD_GETFAMILY, which calls request_module(),
> and then receive the notifications of a group with
> GENL_MCAST_CAP_NET_ADMIN or GENL_MCAST_CAP_SYS_ADMIN. For example the
> drop_monitor "events" group always gets ID 1, and is free until the
> drop_monitor module is loaded.
>
> Fix by returning -ENOENT from genl_bind() when no family owns the group.
> There are no group flags to check before the family registers, so this
> applies to privileged callers too: a program that joins a fixed ID such
> as NET_DM_GRP_ALERT before the family is loaded no longer gets its
> messages. I don't know of a program that does this. One that resolves
> the family first still joins.
>
> bind() takes a mask of groups, and most IDs in it can have no owner. Such
> a mask used to work, so keep it working: netlink_bind() skips an ID when
> the bind callback returns -ENOENT, and joins the others. Only genl_bind()
> returns -ENOENT. A skipped ID is not joined, so it is no longer in the
> groups that getsockname() and NETLINK_LIST_MEMBERSHIPS report.
> setsockopt() returns the error, as it asks for one group.
>
> This does not cover a family that is unregistered between the check and
> the point where the membership bit is set.
>
> Found by the Sashiko review of the gtp multicast group fix. Tested as an
> unprivileged user who joins all free IDs, then loads gtp and
> drop_monitor:
>
> Before:
> joins: ok=62 EPERM=2
> gtp/gtp (ID 15): member
> NET_DM/events (ID 1): member
>
> After:
> joins: ok=19 ENOENT=43 EPERM=2
> gtp/gtp (ID 15): not member
> NET_DM/events (ID 1): not member
> bind(), an owned group and free IDs: ok, member of the owned group only
>
> genl_bind() was added, with its first capability check, in the commit
> in the Fixes tag.
>
> Link: https://lore.kernel.org/netdev/179324692107.3134.14443689892607921337@kernel.org/
> Fixes: 4d54cc32112d ("mptcp: avoid lock_fast usage in accept path")
> Signed-off-by: Anil Kaushik <anilkaushikwireless@gmail.com>
> ---
> v6:
> - Drop patch 2 of v5, as Jakub found it too ugly. A family unregistered
> between the check and setting the membership bit is not covered.
> - Say that early joins to fixed IDs stop working, also for privileged
> callers, and that NETLINK_LIST_MEMBERSHIPS changes.
> - Document the -ENOENT meaning on the bind member.
> - Rebase on net/main.
>
> v5: https://lore.kernel.org/netdev/20261104092125.211537-1-anilkaushikwireless@gmail.com/
>
> I used an LLM to help write and review the code, the tests and the
> commit message of this patch. I checked and tested every change myself.
Could these tests be added in selftests?
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: [PATCH net v6] genetlink: Reject joining multicast groups no family owns
2026-11-13 15:11 ` Nicolas Dichtel
@ 2026-11-15 2:57 ` Anil Kaushik
0 siblings, 0 replies; 5+ messages in thread
From: Anil Kaushik @ 2026-11-15 2:57 UTC (permalink / raw)
To: nicolas.dichtel, netdev
Cc: davem, edumazet, kuba, pabeni, horms, idosch, jacob.e.keller,
jiri, fw, martineau, v3rdant.xiang, aliceryhl, linux-kernel,
anilkaushikwireless
On Fri, Nov 13, 2026 at 04:11:05PM +0100, Nicolas Dichtel wrote:
> Could these tests be added in selftests?
Yes, I will add a selftest for it. I will wait a day or two for more
review and then send v7 with the test as a second patch.
Thanks,
Anil
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH net v6] genetlink: Reject joining multicast groups no family owns
2026-11-12 9:42 [PATCH net v6] genetlink: Reject joining multicast groups no family owns Anil Kaushik
2026-11-13 15:11 ` Nicolas Dichtel
@ 2026-11-16 9:43 ` netdev-bot+sashiko
2026-11-16 17:20 ` Anil Kaushik
1 sibling, 1 reply; 5+ messages in thread
From: netdev-bot+sashiko @ 2026-11-16 9:43 UTC (permalink / raw)
To: anilkaushikwireless
Cc: netdev, davem, edumazet, kuba, pabeni, horms, idosch,
nicolas.dichtel, jacob.e.keller, jiri, fw, martineau,
v3rdant.xiang, aliceryhl, linux-kernel
Thank you for your contribution! Sashiko AI review found 2 potential
issue(s) to consider.
Critical: 0 · High: 0 · Medium: 1 · Low: 1
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] The fix still lets a socket become a member of a multicast
group ID that no family owns.
- [Low] The patch changes how the reserved, uAPI-exported static
multicast group IDs behave, and nothing a uAPI consumer would read…
--
genetlink: Reject joining multicast groups no family owns
With this patch, genl_bind() returns -ENOENT for a multicast group ID
that no registered family owns. This stops unprivileged sockets from
joining IDs ahead of time and later getting the messages of a
capability-gated family. netlink_bind() skips IDs whose bind callback
returns -ENOENT and joins the others, and
setsockopt(NETLINK_ADD_MEMBERSHIP) returns the error.
Link: https://lore.kernel.org/netdev/179324692107.3134.14443689892607921337@kernel.org/
> diff --git a/net/netlink/af_netlink.c b/net/netlink/af_netlink.c
> index 69bb951b5fb8a..ee573ba6396dc 100644
> --- a/net/netlink/af_netlink.c
> +++ b/net/netlink/af_netlink.c
> @@ -1033,6 +1033,12 @@ static int netlink_bind(struct socket *sock, struct sockaddr_unsized *addr,
> err = nlk->netlink_bind(net, group + 1);
> if (!err)
> continue;
> + /* no one owns this group, still join the others */
> + if (err == -ENOENT) {
> + __clear_bit(group, &groups);
> + err = 0;
> + continue;
> + }
[Severity: Low]
Should the uAPI side document this change for the reserved static IDs?
include/uapi/linux/net_dropmon.h still exports:
/*
* Our group identifiers
*/
#define NET_DM_GRP_ALERT 1
genetlink.c also still reserves that ID for static use in mc_group_start
("the drop-monitor code abuses the API and thinks it can statically use
group 1"). It reserves GENL_ID_VFS_DQUOT and GENL_ID_PMCRAID the same
way, and genl_validate_assign_mc_groups() always uses first_id = 1 for
NET_DM.
After this patch, genl_bind() returns -ENOENT for these IDs until the
owning family registers. If setsockopt(NETLINK_ADD_MEMBERSHIP,
NET_DM_GRP_ALERT) runs before drop_monitor (or pmcraid) is loaded, it now
fails with ENOENT.
A bind() with nl_groups bit 0 set returns 0. Because of the __clear_bit()
above, the socket does not get that membership, so the program sees no
events and no error.
The commit message accepts this trade-off ("a program that joins a fixed
ID such as NET_DM_GRP_ALERT before the family is loaded no longer gets
its messages"). Could the uAPI header and the comment above mc_group_start
be updated to say that the family has to be registered before the join?
> netlink_undo_bind(group, groups, sk);
> return err;
> }
> 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: Medium]
Can a socket still become a member of an ID that no family owns?
genl_bind() checks ownership under down_read(&cb_lock) and releases the
lock before it returns. The membership is set later, and ownership is
not checked again:
netlink_bind()
err = nlk->netlink_bind(net, group + 1); /* genl_bind(), cb_lock dropped */
...
netlink_table_grab();
...
nlk->groups[0] = (nlk->groups[0] & ~0xffffffffUL) | groups;
netlink_setsockopt() has the same gap for NETLINK_ADD_MEMBERSHIP:
err = nlk->netlink_bind(sock_net(sk), val);
...
netlink_table_grab();
netlink_update_socket_mc(nlk, val,
optname == NETLINK_ADD_MEMBERSHIP);
If genl_unregister_family() runs in that window, it takes cb_lock for
write and calls genl_unregister_mc_groups():
__netlink_clear_multicast_users(
net->genl_sock, family->mcgrp_offset + i);
...
if (grp_id != 1)
clear_bit(grp_id, mc_groups);
The binding socket is not a member yet, so this does not clear it. The
ID is then freed and the family is removed from genl_fam_idr. After
that, netlink_bind() or netlink_update_socket_mc() sets the bit on the
free ID.
A family registered later through genl_allocate_reserve_groups() could
get that ID and inherit the member. One example is a family loaded on
demand through CTRL_CMD_GETFAMILY -> request_module(). NET_DM could also
come back on ID 1. Either way, the GENL_MCAST_CAP_NET_ADMIN or
GENL_MCAST_CAP_SYS_ADMIN check never runs for that socket.
When the socket closes, netlink_release() -> genl_unbind() then calls the
new family's unbind(i) with no matching bind(i). Could that unbalance the
listener counting in families that implement bind/unbind, such as
thermal_genl_unbind()?
The commit message says this window is not covered ("This does not
cover a family that is unregistered between the check and the point
where the membership bit is set"). Hitting it needs a family to be
unregistered at the same time, usually a privileged module unload or a
module init failure. But the result is the state this patch is meant to
prevent.
Is a recheck at the point where the membership is set planned as a
follow-up?
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261112094205.1120090-1-anilkaushikwireless%40gmail.com
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: [PATCH net v6] genetlink: Reject joining multicast groups no family owns
2026-11-16 9:43 ` netdev-bot+sashiko
@ 2026-11-16 17:20 ` Anil Kaushik
0 siblings, 0 replies; 5+ messages in thread
From: Anil Kaushik @ 2026-11-16 17:20 UTC (permalink / raw)
To: netdev
Cc: davem, edumazet, kuba, pabeni, horms, idosch, nicolas.dichtel,
jacob.e.keller, jiri, fw, martineau, v3rdant.xiang, aliceryhl,
linux-kernel, anilkaushikwireless
On Mon, Nov 16, 2026 at 09:43:58AM +0000, netdev-bot+sashiko@kernel.org wrote:
> - [Medium] The fix still lets a socket become a member of a multicast
> group ID that no family owns.
This race is not new. It was there before this patch, also for groups
with GENL_MCAST_CAP_*. This patch does not fix it, and the commit
message says so. It needs a privileged module unload at the same time
as the join.
I can send a separate fix for net-next if needed.
> - [Low] The patch changes how the reserved, uAPI-exported static
> multicast group IDs behave, and nothing a uAPI consumer would read...
Agreed. v7 updates the comments on the static IDs and on
NET_DM_GRP_ALERT to say they can be joined only after the family is
registered:
https://lore.kernel.org/netdev/20261116124030.1595567-1-anilkaushikwireless@gmail.com/
Thanks,
Anil
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2026-11-16 17:20 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-12 9:42 [PATCH net v6] genetlink: Reject joining multicast groups no family owns Anil Kaushik
2026-11-13 15:11 ` Nicolas Dichtel
2026-11-15 2:57 ` Anil Kaushik
2026-11-16 9:43 ` netdev-bot+sashiko
2026-11-16 17:20 ` Anil Kaushik
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®