Article View: linux.kernel.netdev
Article #17150[PATCH net v7 1/2] genetlink: Reject joining multicast groups no family owns
From: Anil Kaushik
Date: Mon, 16 Nov 2026 12:40
Date: Mon, 16 Nov 2026 12:40
137 lines
16431 bytes
16431 bytes
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. Say so in the comments on the static
IDs.
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. Hitting it needs a
privileged module unload at the same time, and the capability check
already has the same window.
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>
---
include/linux/netlink.h | 3 +++
include/uapi/linux/net_dropmon.h | 2 ++
net/netlink/af_netlink.c | 6 ++++++
net/netlink/genetlink.c | 5 ++++-
4 files changed, 15 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/include/uapi/linux/net_dropmon.h b/include/uapi/linux/net_dropmon.h
index 87cbef48d4c7..4f2fee982c8a 100644
--- a/include/uapi/linux/net_dropmon.h
+++ b/include/uapi/linux/net_dropmon.h
@@ -58,6 +58,8 @@ enum {
/*
* Our group identifiers
+ *
+ * The group can be joined only after the NET_DM family is registered.
*/
#define NET_DM_GRP_ALERT 1
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..e5d4f3c4e22a 100644
--- a/net/netlink/genetlink.c
+++ b/net/netlink/genetlink.c
@@ -85,6 +85,8 @@ static DEFINE_IDR(genl_fam_idr);
* cater to that by giving it a static family and group ID.
* Bit 18 is marked as already used since the PMCRAID driver
* did the same thing as the VFS quota code (maybe copied?)
+ * These IDs can be joined only after the family that owns them
+ * is registered.
*/
static unsigned long mc_group_start = 0x3 | BIT(GENL_ID_CTRL) |
BIT(GENL_ID_VFS_DQUOT) |
@@ -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;
--
2.25.1
Technical Details
Message-ID:
<20261116124030.1595567-2-anilkaushikwireless@gmail.com>Path:
mbox-mo1.pugleaf.net!news-lax.pugleaf.net!srl.newsdeef.eu!news.mb-net.net!open-news-network.org!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-364308-linux-kernel-netdev=dewy.ruReferences:
<20261116124030.1595567-1-anilkaushikwireless@gmail.com>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-lax.pugleaf.net!srl.newsdeef.eu!news.mb-net.net!open-news-network.org!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-364308-linux-kernel-netdev=dewy.ru
From: anilkaushikwireless@gmail.com (Anil Kaushik)
Newsgroups: linux.kernel.netdev
Subject: [PATCH net v7 1/2] genetlink: Reject joining multicast groups no family owns
Date: Mon, 16 Nov 2026 12:40:29 +0000
Organization: Usenet Network
Message-ID: <20261116124030.1595567-2-anilkaushikwireless@gmail.com>
References: <20261116124030.1595567-1-anilkaushikwireless@gmail.com>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
logging-data="2062981"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:s9E32/pGw1RmcRMJLVN30VANZOY= sha256:eewRfEw2bwgOYVbY4MDx6bl7x/vJVdbrJs3Bp50EBJs=
sha1:ZV8n2wqtDHxdd7Ub3yaKOYFVhHs= sha256:zixy3SAEfBFrJy/jxiKP73R0q+FkUeaqnyzgJRX9kqw=
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 7D81A114C07; Mon, 16 Nov 2026 15:41:09 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.049
X-Spam-Status: No, score=-3.049 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, FREEMAIL_FORGED_FROMDOMAIN=0.001,
FREEMAIL_FROM=0.001, 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] autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key)
header.d=gmail.com
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 UiQCI5pTdk5Y;
Mon, 16 Nov 2026 15:41:05 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-364308-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN>
X-Authentication-Results: OpenDMARC; dmarc=fail (p=none dis=none) header.from=gmail.com
X-Received: from sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10])
by mail.dewy.ru (Postfix) with ESMTPS id 87626114C08; Mon, 16 Nov 2026 15:40:57 +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 BEC322D88F; Mon, 16 Nov 2026 12:40:48 +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=1794832848;
b=4gsRO7sNm7eYC4FcuJaAe4gWkPqo1U8oHOlSxwBBpyn72KCZAGQpmdGy1cM5S7IywU89
0PksKBByunCd8zUlBIPeftW22qQP6sBWvOTldm2f/qWwR0HW2ItnBF+ja38shi2xI0IwW
WmgxbuQ37iLRUGoqeP9248F6sI7Re5cFyLyBef+fRoTA5MX3ElpEF0Tl6pGMYubbTViZd
3Guxkv80v2uBNtdEBld6l3zp7YyMXXuZ6KQLNO8T8EwzjQQb/ItX2o5/nZgIEzWHiQFZi
upZYFHKpgFhwyuA2IjwIlVArWwaxxZ5AGlaufK5rW4dQFe0JhrCNp1AEdZXYQjvjQ5g==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
a=rsa-sha256; c=relaxed/relaxed; t=1794832848;
h=X-Original-To:Received:DMARC-Filter:Received:DKIM-Signature:
X-Google-DKIM-Signature:X-Gm-Message-State:X-Gm-Gg:X-Received:
Received:From:To:Cc:Subject:Date:Message-Id:X-Mailer:In-Reply-To:
References:X-Mailing-List:List-Id:List-Post:List-Help:List-Subscribe:
List-Unsubscribe:List-Owner:Precedence:MIME-Version:
Content-Transfer-Encoding;
bh=hznFWbWvFOaXuVUd+3ixFiuNbdML6L6UHVu/kgMSL3M=;
b=qFn/gBSqOhKLKQ7XgqW60ahhfAfEjKVYjRmEpGZN4GPneoUyughiGwRvbES1CYB2+9b8
ci6dxlhzGaD3enEhaqFJAxfS/o+wDinTkMnamYFQhql6UcrFzWzQRWC+NswNRfaxCsdC+
AEVkgCPcHNcWwBPTluwbcbQQ8FT89P6W0QW+H2KqY6H3CTGFvMxPrl0DUxBIWEDjyuOv5
oR5/Ik0WGbW/Jhc65ZE0Zqqfr0IyACmwsKECy/vKPa0F7HDGvSiZ53474SAF0bWl/ErYJ
qoRWhj9JBg0l3CLTP+K2jva4YhZnF+ZXPReFzs2hHe7hP3VxKvFfSIQSbQhdbqK8Z5Q==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org;
dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b="h/mUxU8i";
dmarc=pass header.from=gmail.com;
spf=pass smtp.mailfrom=gmail.com;
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 F2E32606A33E;
Mon, 16 Nov 2026 12:40:47 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=h/mUxU8i
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.210.47
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
t=1794832847;
b=yTD2DBmmoRgMzCXdkhVHdBrl7QF/UCdaEjAHoFb6eZwncbrMFrB2ktsToWC5K5mt9ory
yWz39mVJhjdDnFlJ6nRpEyb2mENg32wbyKrvoUAwkJxgXn1D/Dl6AyWZ3XNlBJy4wDd2H
K3JesuqnPG2hO02tJC7NJMXSkhuTwgah1zUjLYNq5MtYy/0gJImQf+kAT+fq+WZTADk61
Pn2IMEKBtboMD64tB4KqfxNFoBOgMLZP6JVsNZQIoqui5ZulSB6G1MLoErqUEkStWpNa4
g/hnyRmTuSNwDc4/3/31JK9eFWVZnJ+MInpzHdakIBpU4Wbs2O2M2OOIWmbVyMSNLQA==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
a=rsa-sha256; c=relaxed/relaxed; t=1794832847;
h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature:
X-Gm-Message-State:X-Gm-Gg:X-Received:Received:From:To:Cc:Subject:
Date:Message-Id:X-Mailer:In-Reply-To:References:MIME-Version:
Content-Transfer-Encoding;
bh=hznFWbWvFOaXuVUd+3ixFiuNbdML6L6UHVu/kgMSL3M=;
b=tybYntSKHhdBtRWkVNRqnJxVYnjIAa8YxM4+s0+kt+cPOoZ9bJ2QnLPXprvQ+HWIvLhH
UOQWWDJ4D2xJ1FtpFNkiAvT88BuTtWR080F/BWjZHMHSVZL00U1QfOfbZhpPQYfagKKJX
QHS39pDjOuhvt5Fh62WkGZa2HDp2fMO2XuEadhRbMwmRs4RASbmt7E4/ZmT0S9JGhxsrR
kqTtR2WXkniTIh9o141Jin45YwR9c7ZXKfJc8FaXhO7HKU6KXqey/29jhAWtATTgze19C
KJd+Eh+E7U4fjuAPO2s4epeYjx3YGoME5LnTTEanoNELgKfHVzkmzlGRjvhS/Y8xOew==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org;
dmarc=pass header.from=gmail.com;
spf=pass smtp.mailfrom=gmail.com;
dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b="h/mUxU8i";
arc=none smtp.remote-ip=209.85.210.47
X-Received: from mail-ot1-f47.google.com (mail-ot1-f47.google.com [209.85.210.47])
(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 C96C2606A334
for <netdev@vger.kernel.org>; Mon, 16 Nov 2026 12:40:46 +0000 (UTC)
X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org C96C2606A334
X-Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com
X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com
X-Received: by mail-ot1-f47.google.com with SMTP id 46e09a7af769-862b9c2e78aso669628a34.2
for <netdev@vger.kernel.org>; Mon, 16 Nov 2026 04:40:46 -0800 (PST)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=gmail.com; s=20260707; t=1794832846; x=1795437646; darn=vger.kernel.org;
h=content-transfer-encoding:mime-version:references:in-reply-to
:message-id:date:subject:cc:to:from:from:to:cc:subject:date
:message-id:reply-to:content-type;
bh=hznFWbWvFOaXuVUd+3ixFiuNbdML6L6UHVu/kgMSL3M=;
b=h/mUxU8iT5smy/Nn3/TImjg0PoArS74qd8+QGBliY7Qu+r8ZahiepWhdAe+dWF8FY/
RsE7FXfC4YyF0zNfa+rJ1fUQ1bg6Tw3KtvLYa47LuoDp7oOmpNRr7n9IB5kqKawpZ1wQ
7Ewl7FpCFtkRWsB5H6dfXRQt4JWhVYPuNyAQAVc31HEPdH3ONmSIZ7T5yCqxajo1Ky/R
10rXRQQ0NDgMrvyBZvDw97pz0+Awos07NBYeaN/elymWk+aER6GgjIt37xWKGSyWVcdN
adJ11onhhPuvH06pPviW885hm7lTGi2gA86v+w6ZLLcToPZz2zaci1bYYlNO2T6lh/SX
704w==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20260707; t=1794832846; x=1795437646;
h=content-transfer-encoding:mime-version:references:in-reply-to
:message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from
:to:cc:subject:date:message-id:reply-to:content-type;
bh=hznFWbWvFOaXuVUd+3ixFiuNbdML6L6UHVu/kgMSL3M=;
b=xR2BMjSRDUba1tpcUs/nqm6dC5PiFVqOrXugFkrIdwFaeV/ADhYReBg+OxRnwzgnYH
iLClSTr3cLclER4z5XHq/tnmvpELJRdC+Q14uFb/9cS8sFfTHKf3SIh6ErUIiSjgMuni
ijP4ysghb46E0bTJeob3nwz7Pxr25AwZYJqSbBQVDW0CELmyLR1Zvz2D5zFJ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:85f:c55:b0e8 with SMTP id 46e09a7af769-862898287b3mr8933968a34.5.1794832845686;
Mon, 16 Nov 2026 04:40:45 -0800 (PST)
X-Received: from ramen-dev-security-2.asia-south1-c.c.ramen-dev-345017.internal (90.156.200.35.bc.googleusercontent.com. [35.200.156.90])
by smtp.gmail.com with ESMTPSA id 46e09a7af769-862c4dd9abesm2830937a34.20.2026.11.16.04.40.39
(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
Mon, 16 Nov 2026 04:40:45 -0800 (PST)
X-Cc: 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,
anilkaushikwireless@gmail.com
X-Mailer: git-send-email 2.25.1
X-In-Reply-To: <20261116124030.1595567-1-anilkaushikwireless@gmail.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