From: Anil Kaushik <anilkaushikwireless@gmail.com>
To: netdev@vger.kernel.org
Cc: "David S . Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@kernel.org>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
Simon Horman <horms@kernel.org>, Ido Schimmel <idosch@nvidia.com>,
Nicolas Dichtel <nicolas.dichtel@6wind.com>,
Jacob Keller <jacob.e.keller@intel.com>,
Jiri Pirko <jiri@resnulli.us>,
XingWang Xiang <v3rdant.xiang@gmail.com>,
Alice Ryhl <aliceryhl@google.com>,
linux-kernel@vger.kernel.org
Subject: [PATCH net v2 2/2] genetlink: Clear stale members when assigning multicast group IDs
Date: Sat, 31 Oct 2026 05:46:32 +0000 [thread overview]
Message-ID: <20261031054632.3697295-3-anilkaushikwireless@gmail.com> (raw)
In-Reply-To: <20261031054632.3697295-1-anilkaushikwireless@gmail.com>
genl_bind() checks a group under cb_lock, but netlink_setsockopt() and
netlink_bind() set the membership bit only after it returns and the lock
is dropped. If the family is unregistered in between, its members are
cleared before this socket is one, and the socket stays a member of a
group ID that no family owns. A family registered later can get that ID
and its GENL_MCAST_CAP_* flags are never checked for the socket.
Clear the members of the group IDs when a family is given them, the
same way genl_unregister_mc_groups() does when they are freed. No socket
can be a valid member at that point: cb_lock is held for writing, so
genl_bind() cannot see the new family yet.
Link: https://lore.kernel.org/netdev/179340003139.3131.11274717768928642724@kernel.org/
Fixes: e03781879a0d ("drop_monitor: Require 'CAP_SYS_ADMIN' when joining "events" group")
Signed-off-by: Anil Kaushik <anilkaushikwireless@gmail.com>
---
net/netlink/genetlink.c | 31 +++++++++++++++++++++----------
1 file changed, 21 insertions(+), 10 deletions(-)
diff --git a/net/netlink/genetlink.c b/net/netlink/genetlink.c
index f038f04ef4ea..0ddebd828585 100644
--- a/net/netlink/genetlink.c
+++ b/net/netlink/genetlink.c
@@ -452,6 +452,22 @@ static int genl_allocate_reserve_groups(int n_groups, int *first_id)
static struct genl_family genl_ctrl;
+static void genl_clear_mc_users(const struct genl_family *family)
+{
+ struct net *net;
+ int i;
+
+ netlink_table_grab();
+ rcu_read_lock();
+ for_each_net_rcu(net) {
+ for (i = 0; i < family->n_mcgrps; i++)
+ __netlink_clear_multicast_users(net->genl_sock,
+ family->mcgrp_offset + i);
+ }
+ rcu_read_unlock();
+ netlink_table_ungrab();
+}
+
static int genl_validate_assign_mc_groups(struct genl_family *family)
{
int first_id;
@@ -527,23 +543,18 @@ static int genl_validate_assign_mc_groups(struct genl_family *family)
clear_bit(family->mcgrp_offset + i, mc_groups);
}
+ /* drop sockets that joined the IDs while no family owned them */
+ if (!err)
+ genl_clear_mc_users(family);
+
return err;
}
static void genl_unregister_mc_groups(const struct genl_family *family)
{
- struct net *net;
int i;
- netlink_table_grab();
- rcu_read_lock();
- for_each_net_rcu(net) {
- for (i = 0; i < family->n_mcgrps; i++)
- __netlink_clear_multicast_users(
- net->genl_sock, family->mcgrp_offset + i);
- }
- rcu_read_unlock();
- netlink_table_ungrab();
+ genl_clear_mc_users(family);
for (i = 0; i < family->n_mcgrps; i++) {
int grp_id = family->mcgrp_offset + i;
--
2.25.1
prev parent reply other threads:[~2026-10-31 5:46 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-31 5:46 [PATCH net v2 0/2] genetlink: fix joining multicast groups no family owns Anil Kaushik
2026-10-31 5:46 ` [PATCH net v2 1/2] genetlink: Reject " Anil Kaushik
2026-10-31 5:46 ` Anil Kaushik [this message]
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=20261031054632.3697295-3-anilkaushikwireless@gmail.com \
--to=anilkaushikwireless@gmail.com \
--cc=aliceryhl@google.com \
--cc=davem@davemloft.net \
--cc=edumazet@kernel.org \
--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=netdev@vger.kernel.org \
--cc=nicolas.dichtel@6wind.com \
--cc=pabeni@redhat.com \
--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
all inboxes | Powered by JetHome®