🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #7303

[PATCH net v4] netlink: fix out-of-bounds bitmap access clearing stale mc groups

#7303
From: Henry Martin
Date: Mon, 26 Oct 2026 03:09
68 lines
13326 bytes
netlink_realloc_groups() sizes nlk->groups to the number of groups
that exist at bind/ADD_MEMBERSHIP time.  When more multicast groups
are registered later (e.g. a new genl family), existing sockets keep
their smaller bitmap.

When clearing a multicast group of a departing family,
__netlink_clear_multicast_users() runs netlink_update_socket_mc() on
each socket on mc_list, which does test_bit()/__assign_bit() on
group - 1 with no regard to nlk->ngroups.  Skip sockets whose bitmap
predates the group: such a socket can never have joined it.

The overflow windows differ per architecture, both needing privileged
module (un)loading.  On 32-bit kernels the ~54 dynamically allocated
genl groups already exceed the initial 32-bit bitmap, so the table
can grow there directly.  On 64-bit kernels the same in-tree set fits
the initial 64-bit bitmap only while allocation stays contiguous:
genl_allocate_reserve_groups() takes the first free contiguous range
and unregister does not compact, so an unload/reload sequence can
fragment the ~59 free IDs until no fitting range remains, forcing
the table past 64 bits and reaching the same stale-bitmap overflow on
the next family teardown.

This issue was discovered by Tencent CodeBuddy Security.

Fixes: 84659eb529b3 ("[NETLIKN]: Allow removing multicast groups.")
Signed-off-by: Henry Martin <bsdhenrymartin@gmail.com>
---

v4: Skip stale-bitmap sockets in __netlink_clear_multicast_users()
    itself instead of guarding inside netlink_update_socket_mc(), so
    the guard cannot silently swallow a future
    netlink_update_socket_mc(..., 1) caller (suggested by Eric
    Dumazet).

v3: Correct the reachability again (sashiko review): 64-bit is also
    reachable - group IDs are allocated in contiguous ranges without
    compaction, so fragmentation from an unload/reload sequence can
    force the table past the initial 64-bit bitmap too.

v2: Correct the Fixes tag (the clear path was added by 84659eb529b3,
    not by the dynamic bitmap commit), drop Cc: stable and describe
    the actual reachability (32-bit kernels with in-tree families)
    instead of implying generic heap corruption.

 net/netlink/af_netlink.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/net/netlink/af_netlink.c b/net/netlink/af_netlink.c
index 9fdf964224ab4..ee0a6df6eb5d6 100644
--- a/net/netlink/af_netlink.c
+++ b/net/netlink/af_netlink.c
@@ -2156,8 +2156,12 @@ void __netlink_clear_multicast_users(struct sock *ksk, unsigned int group)
 	struct netlink_table *tbl = &nl_table[ksk->sk_protocol];
 	struct hlist_node *tmp;
 
-	sk_for_each_bound_safe(sk, tmp, &tbl->mc_list)
+	sk_for_each_bound_safe(sk, tmp, &tbl->mc_list) {
+		/* bitmap predates the group, can't be a member */
+		if (group - 1 >= nlk_sk(sk)->ngroups)
+			continue;
 		netlink_update_socket_mc(nlk_sk(sk), group, 0);
+	}
 }
 
 struct nlmsghdr *
-- 
2.43.7
Technical Details
Message-ID: <20261026030928.719276-1-bsdhenrymartin@gmail.com>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!eternal-september.org!feeder.eternal-september.org!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-351668-linux-kernel-netdev=dewy.ru

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!eternal-september.org!feeder.eternal-september.org!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-351668-linux-kernel-netdev=dewy.ru
From: bsdhenrymartin@gmail.com (Henry Martin)
Newsgroups: linux.kernel.netdev
Subject: [PATCH net v4] netlink: fix out-of-bounds bitmap access clearing stale mc groups
Date: Mon, 26 Oct 2026 11:09:28 +0800
Organization: Usenet Network
Message-ID: <20261026030928.719276-1-bsdhenrymartin@gmail.com>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="1209240"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:sdx9cen2VvNF1e7ALaz7vArGYtQ= sha256:ibrzyFqKUZ7qFrhU5KKKijb4mTpYxub8IkgoqxiJ3sM=
	sha1:/HrZerQIg1yqr65VgtwiTIeZVkM= sha256:CUGCLTm/tMHNWjI9yUAb4r3EIlL40wtugauNWJG2iLE=
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 A2704125B8A; Mon, 26 Oct 2026 06:10:18 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.048
X-Spam-Status: No, score=-3.048 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.25,
	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 jYaFZKS1Bm4S;
	Mon, 26 Oct 2026 06:10:15 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.105.105.114; helo=tor.lore.kernel.org; envelope-from=netdev+bounces-351668-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 tor.lore.kernel.org (tor.lore.kernel.org [172.105.105.114])
	by mail.dewy.ru (Postfix) with ESMTPS id 5B6AF125B87; Mon, 26 Oct 2026 06:10:06 +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 2E3DD29F64; Mon, 26 Oct 2026 03:09:54 +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=1792984193;
	b=FdgzwsofHFRl4SdBjoS+tP/pDE1SFu54zC++i33Mp8GYxrDvHXnh7Wf84c0ksezTdWwL
	 q3XdXmi9wPY73FhVKEbhP1NF7gIBiIfuPSU89FpNivfH0QyV93itBnpn49yOOhlqCBwSM
	 vIOMsbRxH81I2cMRRMZn91mzgA0FX+XLtp/mX2EYGCpVAqCH3CMmTiMZpyMxbzhqt3WE4
	 V2QgMWo/2/7QwJUO75WWB3NFWQgTaq2q3pt1hvGCLENs8kpHh0nmnpIcHh5E4+8pw9oRJ
	 uPjE272rPviKpRnX8K7M+tD62xrb1IxtgfeLHPZ7uyrrGIC2A1xcYNCEnkt+bU7aLzg==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1792984193;
	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:X-Mailing-List:
	 List-Id:List-Post:List-Help:List-Subscribe:List-Unsubscribe:
	 List-Owner:Precedence:MIME-Version:Content-Transfer-Encoding;
	bh=cTXVJUOKRughwuSMYrqOOlwP+3rFl6wn/3gsJxxcBAs=;
	b=dh8fyhRH4igRA6RbA/YZ1z4by8fz+3tiSOGCohREGLEnJhwPEo9XSWPZwmCfmWj0lv2M
	 3S0AGN3tcFH1jzLsUwse3cXDkly2vEqwc6dh/ydjsqPozFH5oPmkrMKA5DNP4ghlTQv3p
	 syQJLvY8D+KBqQkw7W5g7s2aTtejjrszHOCqyEU2o/dW43r58wZHOZaxLjiQaHa+Qj232
	 BXVS6AUGnsXP2eKWyWawh28JS3ksLxNEUv+QEPxj/Nv0/aRNr38/5AfBk3X2p+WXs/EgZ
	 9zPuFXLBI27uHIMuW3kjYFYksneT1cbVdUIZsS9S4RaDsfdh8AChy6eyrr2Hb5pZ2JQ==
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=20251104 header.b=a9vwO6vH;
	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 7A324606A31D;
	Mon, 26 Oct 2026 03:09:53 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key, unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20251104 header.b=a9vwO6vH
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.231.137
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
	t=1792984181;
	b=gzpBT5nQgFetGv90nXTAHXKWnZyPk6VeLt9p+kIBgSWWRiXFgoGWEQFrgwGTrF/Cm9SW
	 HAfgwh6eUZUtTAP1LyFbb/5+xjjA9nq9pgG0eLQJVZ/Ujh9jpDKotDc1Y4lAt03QS6Lzj
	 J7OVXe9WxyFs0IdVosjUdGECnyT8k8oVfy3tp5APeRsFqn+uq8zs1zAnnxBhlnryaX+sD
	 N/ByAvlx8dkK5G6kO1Ry7zOWW0AVeI1CO9JnhhQ4BfCSmYbH8ZYcEJRsKj/nPyPHxT9mM
	 vhF80q1HZdiL8t47/4saZSqA7IL3mla6+CBvduNGEmgYUTi1xeJiemwqGt0J56bekWQ==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1792984181;
	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:MIME-Version:Content-Transfer-Encoding;
	bh=cTXVJUOKRughwuSMYrqOOlwP+3rFl6wn/3gsJxxcBAs=;
	b=4TxgiIdhnbwpX/Lu6i+KCIseJ+vf4rAsL2ZwAgwvpRzm3BUE43swOGLyc5OL/eK1Cx5k
	 dXffY1jViYHz2cthRMePkcbPIjsPhuJIJhQEkcx8rHt00IlEy8+87BddXW0GT5wFJKwTg
	 /QwXHJV2O+MZMJFwzUkUwCW9DNGM/VAytpVGMuxQaK2nftYFWr3P4f4fvzDEH1pPUatSz
	 Y1EgUqbsJH0CiW/G//M8+gSfgmLZH2vfmU80LD3+V/gTqCu0JL83ypUDTyyvLimO2cZ13
	 4xhbo80XbX4iyX8x9MsJ/eVUEyySjuuwbhkUXeMivveST5oSB6wP/G7hDQXRYghm1Bg==
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=20251104 header.b=a9vwO6vH;
	arc=none smtp.remote-ip=74.125.231.137
X-Received: from mail-oo2-f9.google.com (mail-oo2-f9.google.com [74.125.231.137])
	(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 DB370606A31B
	for <netdev@vger.kernel.org>; Mon, 26 Oct 2026 03:09:40 +0000 (UTC)
X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org DB370606A31B
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-oo2-f9.google.com with SMTP id 006d021491bc7-6de19ccd89bso366866eaf.0
        for <netdev@vger.kernel.org>; Sun, 25 Oct 2026 20:09:40 -0700 (PDT)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20251104; t=1792984180; x=1793588980; darn=vger.kernel.org;
        h=content-transfer-encoding:mime-version:message-id:date:subject:cc
         :to:from:from:to:cc:subject:date:message-id:reply-to:content-type;
        bh=cTXVJUOKRughwuSMYrqOOlwP+3rFl6wn/3gsJxxcBAs=;
        b=a9vwO6vHViR2IX71zNqDPxMmiKNbdhMXQsJDsyOC6Dc3KyPpmggtN6/HcRB5LPL0KS
         KrflVexMxIHJZLnl58zHgz5pcVGamHHVCcmTuNfYJgqysLIwKYAbIlCHDPvYlmaHkkDe
         gCXTvxAwVxiCPNHi858NcbI0SrwXK8X7W79fsLHMkjnAcMP0QkL/YwdM1x9VR0nBOPSO
         hdUomy6/i/ehZc7jXvjfYuNb4u0GtYx2YhFtPJtKIh5DDPKY1p1AiDmzMJCs87hiSaUj
         lQz17fXmF0n1CqTa5jVcRQwpY5LnyBYEzZJ43foTCPO5bC7XApYEuTkLfamggna2TUgB
         c7zg==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20260707; t=1792984180; x=1793588980;
        h=content-transfer-encoding:mime-version: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=cTXVJUOKRughwuSMYrqOOlwP+3rFl6wn/3gsJxxcBAs=;
        b=bnKSgU06V7jAETMBAvg28xHlaU/oky+cHwEFp170lY06QlOYevWUu+Z2k7Ap2mbhcV
         fxcOKSlLVjv6cxGs0PCmLeWfm7Cpq7RDbI1AurpR1anJgVvu/aMBK90UTb4wnI220vBL
         BE5MugIdiYTpuo/Cq9bO2m8JGQQNFF3Xe2Pi2WYeEkSwDI1koYGpHZuuIWX0lxmvzATL
         +J3kbCW0NuueGqxk8f0gOT1HKm/Ai8nwXy/MXyU7HxIQJI69wNu/U3PAoNNYVQvzr9t8
         zwAy6zhC6/exsk4QYucqAH3x0YXMXLmtpf5fP4f/OOCnbBiVUc/TJi2I/V0CMFAWAPWu
         XhuQ==
X-Gm-Message-State: AFq9FYJqd61SxmF6qlgxAn+5vuDmn3P3ODH8XnkbVsCghEZrEKWlPTSQ
	q/JGiRqPFmO5RnPZ3vfnD8s/Ax27PnldaN4osaMr8n2lPyBcscXFasEh
X-Gm-Gg: AYBFou1L5h4dURBpyWgT5FeWJ6fD8Cqisvk8e0KWKab9dgXyBsB4YoX2aD8lDPkiO+o
	F+hjJXm/QUFZc1qyAQI1SiKxjjy7k31qmp50Wy8zucGHBHBXrE7P2u3vhpu+WgFniN3/RA9aVF+
	D3k8ynSzw4cgpzXrryD9SZe1Eth2RCciTcNa0OqdJKwLoWTZWLkmF334i/FwyHvcG0butKrYdkQ
	fczBG5R6lVSrK2t+97D5O53zsrFCyQD1NX5Omhzh+GpFd8vMXvNDf4lNNQMhD3/ycycjOc+nKvN
	sKvWOmJKJBaapjmQGdIxFxVsAt77MdH55FI9MNASMr0GOS41/SuI9ZrPc43QjNVoYy/n8fsPbTn
	CIdwjZyYtFgX7qi7NTuY97jDc6ES43/NpWEGbeMA67EktfMnxFsXBDVxIoHCgaBSoDkO0pSbPiw
	Qv05JC7ZQ6GUVTCc3KQtX6Xmn0Q8mfM+u8R/mcW7MQrcWVKlNoPUhWMVtCtc0naw1dYee+39vN9
	bIhTm6Wd4Zrxui+383In+8NAjmmhswtQBceXOY0nvqy3gTaKOD297syDRPjYkhLLnI73c7u7aXz
	GuGFkwbSAXmo14XfVnZji3UNOK3eoRlRrY9NF6RLaQ==
X-Received: by 2002:a05:6820:440c:b0:6cd:3fdc:a936 with SMTP id 006d021491bc7-70ba0f81592mr2345843eaf.83.1792984179731;
        Sun, 25 Oct 2026 20:09:39 -0700 (PDT)
X-Received: from localhost.localdomain ([14.116.239.40])
        by smtp.gmail.com with ESMTPSA id 006d021491bc7-70b9e04aa58sm6421308eaf.7.2026.10.25.20.09.33
        (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
        Sun, 25 Oct 2026 20:09:38 -0700 (PDT)
X-Cc: netdev@vger.kernel.org,
	linux-kernel@vger.kernel.org,
	Henry Martin <bsdhenrymartin@gmail.com>
X-Mailer: git-send-email 2.43.7
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