Article View: linux.kernel.netdev
Article #23114Re: [PATCH net v9 2/2] selftests: net: test joining genetlink groups no family owns
From: netdev-bot+sashiko
Date: Thu, 26 Nov 2026 14:47
Date: Thu, 26 Nov 2026 14:47
160 lines
14425 bytes
14425 bytes
Thank you for your contribution! Sashiko AI review found 3 potential
issue(s) to consider.
Critical: 0 · High: 0 · Medium: 1 · Low: 2
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] In bind_before_family()
(tools/testing/selftests/net/nl_genl_mcast.py), the `finally:` block…
- [Low] _free_ids() in tools/testing/selftests/net/nl_genl_mcast.py
decides it is in init_net by comparing…
- [Low] _members() in tools/testing/selftests/net/nl_genl_mcast.py calls
sk.getsockopt(SOL_NETLINK, NETLINK_LIST_MEMBERSHIPS, 64) and decodes…
--
selftests: net: test joining genetlink groups no family owns
This adds a Python selftest. It checks that Generic Netlink multicast
group IDs no family owns cannot be joined with setsockopt() or bind(). It
also checks that a socket bound to free IDs does not become a member of
the NET_DM groups once drop_monitor is loaded.
> diff --git a/tools/testing/selftests/net/nl_genl_mcast.py b/tools/testing/selftests/net/nl_genl_mcast.py
> new file mode 100755
> index 0000000000000..8bbe3d22225cf
> --- /dev/null
> +++ b/tools/testing/selftests/net/nl_genl_mcast.py
[ ... ]
> +# include/uapi/linux/nsfs.h
> +NET_NS_INIT_INO = 0xEFFFFFF9
[ ... ]
> +def _free_ids(ctrl):
> + """Return the IDs in 1..32 that no family owns."""
> + # Outside init_net, the dump skips the families that are not netnsok,
> + # but their groups are still owned.
> + if os.stat('/proc/self/ns/net').st_ino != NET_NS_INIT_INO:
> + raise KsftSkipEx("not in the initial network namespace")
[Severity: Low]
Can this check ever match on kernels older than commit 9b0240b3ccc325
("netns: use stable inode number for initial mount ns")?
That commit added NET_NS_INIT_INO to include/uapi/linux/nsfs.h. Before
it, the ns.inum of init_net was a dynamically allocated proc inode number
(PROC_DYNAMIC_FIRST and up), so this comparison never matches.
join_free(), bind_mask() and bind_before_family() all call _free_ids()
first. On those kernels all three subtests would skip, even when run in
the initial network namespace. The printed reason, "not in the initial
network namespace", would also be wrong.
The companion fix "genetlink: Reject joining multicast groups no family
owns" has a Fixes: tag, so it is a likely backport candidate for stable
trees such as 6.12, 6.6, 6.1 and 5.15. If this test is backported with
it, the fix would never be exercised there.
The commit message explains why the fixed inode number is used, but it
does not mention this limitation. Would a fallback help here? For
example, the test could compare against the inode of /proc/1/ns/net when
the fixed value is not in use. Another option is a skip message that
states the actual condition.
[ ... ]
> +def _members(sk):
> + buf = sk.getsockopt(SOL_NETLINK, NETLINK_LIST_MEMBERSHIPS, 64)
> + # An array of u32 in host byte order
> + words = struct.unpack(f'={len(buf) // 4}I', buf)
> + return sum(w << (32 * i) for i, w in enumerate(words))
[Severity: Low]
Could _members() decode uninitialised bytes when the socket has more
than 512 groups?
In netlink_getsockopt(), the NETLINK_LIST_MEMBERSHIPS case stops copying
once the user buffer is full. It then reports the full required size
anyway:
net/netlink/af_netlink.c:netlink_getsockopt() {
...
opt->optlen = ALIGN(BITS_TO_BYTES(nlk->ngroups), sizeof(u32));
...
}
do_sock_getsockopt() in net/socket.c writes this value back to user
space without clamping it. CPython's socket.getsockopt() then resizes
the returned bytes object to that length. Everything past the 64 bytes
the kernel actually wrote is left uninitialised.
For a genetlink socket, nlk->ngroups follows mc_groups_longs *
BITS_PER_LONG, and that grows on demand in genl_allocate_reserve_groups()
and genl_validate_assign_mc_groups(). If it goes above 512, the
full-value ksft_eq() checks in join_free() and bind_mask() could fail
because of garbage high bits.
Would it be safer to decode only the first min(len(buf), 64) bytes, or
to size the buffer from the returned optlen?
[ ... ]
> +def bind_before_family(ctrl) -> None:
> + """A free ID joined with bind() stays unjoined when a family takes it."""
> + names = [fam['family-name'] for fam in ctrl.getfamily({}, dump=True)]
> + if 'NET_DM' in names:
> + raise KsftSkipEx("NET_DM is already registered")
> +
> + free = _free_ids(ctrl)
> + try:
> + with _sock() as sk:
> + sk.bind((0, sum(_bit(gid) for gid in free)))
> +
> + # Looking up the family loads drop_monitor.
> + try:
> + ids = _groups(ctrl.getfamily({'family-name': 'NET_DM'}))
> + except NlError as e:
> + raise KsftSkipEx("drop_monitor is not available") from e
[ ... ]
> + finally:
> + # So that the next run can load it again
> + cmd("modprobe -q -r drop_monitor", fail=False)
[Severity: Medium]
Can this finally block turn the "drop_monitor is not available" skip into
a failure?
With shell=None, cmd() in lib/py/utils.py splits the string into a list
and runs it through subprocess.Popen() without a shell. If modprobe is
not on PATH, Popen() raises FileNotFoundError. fail=False only ignores a
non-zero exit code, not a failure to start the command.
An exception raised in a finally block replaces the pending one. The
KsftSkipEx raised when getfamily() fails with NlError is then lost.
ksft_run() catches the FileNotFoundError under except BaseException and
counts the test as a failure, with a traceback.
Without modprobe, request_module() in the kernel would also fail. That
makes the NlError path the one taken in exactly this environment. The
cleanup also runs when the test never loaded drop_monitor.
modprobe may only be in /sbin or /usr/sbin, and the test may run with a
PATH that excludes them. In that case even the success path would end in
FileNotFoundError and be reported as a failure.
Would it help to run modprobe -r only after getfamily() succeeds, or to
catch OSError around the cleanup?
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261125144514.2717012-1-anilkaushikwireless%40gmail.com
Technical Details
Message-ID:
<179570443724.3135.6495722482046462156@kernel.org>Path:
mbox-mo1.pugleaf.net!srv.newsdeef.eu!news.mb-net.net!open-news-network.org!2.eu.feeder.erje.net!feeder.erje.net!feeder1.feed.ams11.usenet.farm!feed.usenet.farm!feeder.usenetexpress.com!tr3.eu1.usenetexpress.com!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-372160-linux-kernel-netdev=dewy.ruReferences:
<20261125144514.2717012-3-anilkaushikwireless@gmail.com>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!news.mb-net.net!open-news-network.org!2.eu.feeder.erje.net!feeder.erje.net!feeder1.feed.ams11.usenet.farm!feed.usenet.farm!feeder.usenetexpress.com!tr3.eu1.usenetexpress.com!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-372160-linux-kernel-netdev=dewy.ru From: netdev-bot+sashiko@kernel.org Newsgroups: linux.kernel.netdev Subject: Re: [PATCH net v9 2/2] selftests: net: test joining genetlink groups no family owns Date: Thu, 26 Nov 2026 14:47:17 +0000 Organization: Usenet Network Message-ID: <179570443724.3135.6495722482046462156@kernel.org> References: <20261125144514.2717012-3-anilkaushikwireless@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit Injection-Info: usenet.network; logging-data="488331"; mail-complaints-to="abuse@usenet.network" Cancel-Lock: sha1:nRCjMuNnOM4PZRb1J8Y3boBcQRc= sha256:aDQDmov2qj9Ldoahh1I8ELbxi02AKCL1ovw9JeQyMDM= sha1:eyBemspWefnEKhBUKwcNA7jGRyA= sha256:V9E8DSOicCnetljrXr5gFC6Ry1pou+2ggeIiBJxSKuI= 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 05567125EE1; Thu, 26 Nov 2026 17:47:45 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at usenet.network X-Spam-Flag: NO X-Spam-Score: -3.501 X-Spam-Status: No, score=-3.501 tagged_above=-9999 required=6.31 tests=[DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, 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=kernel.org 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 Q4EoPaPWbgSQ; Thu, 26 Nov 2026 17:47:41 +0300 (MSK) X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.232.135.74; helo=sto.lore.kernel.org; envelope-from=netdev+bounces-372160-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> X-Authentication-Results: OpenDMARC; dmarc=pass (p=quarantine dis=none) header.from=kernel.org X-Received: from sto.lore.kernel.org (sto.lore.kernel.org [172.232.135.74]) by mail.dewy.ru (Postfix) with ESMTPS id 1A4AF125EE0; Thu, 26 Nov 2026 17:47:32 +0300 (MSK) X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92]) by sto.lore.kernel.org (Postfix) with ESMTP id 95315605B7D; Thu, 26 Nov 2026 14:47:31 +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=1795704449; b=qVFb1I6Ff5PAieDQvMTX82km8jMgDpV8p5QUf4CRbvqC6DkuujAoYf/h1SKW7Qy6g1Ja f1DFxxLzuDPZnpbGZPWI7veryazCB9AMF2nMVyZBApSrbJYE2Kodt+PDVwUTjmU9CZlXe 5CTWXZifVOFCXCQQ9rmaSSlBjWH+psQ/4G3l6ohdLwt67IGKery9TEPj6+qJUpdvU7EvT Y1oyHlhUppfapPOIgjb6X93bKM/eiNnuMcFdP2O11dEADLYDV9/tHrN2GxWXi9KNRU6fq izwRFLUpQv2xryciJs69Q97hhFj7cfy5xYZg9Q86py22C/zHboiH3fuOVr2jxqQR8lQ== X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795704449; h=X-Original-To:Received:Received:DKIM-Signature:Subject:From:To:Cc: Date:Message-ID:In-Reply-To:References:X-sashiko-severity: Content-Type:Content-Transfer-Encoding:X-Mailing-List:List-Id: List-Post:List-Help:List-Subscribe:List-Unsubscribe:List-Owner: Precedence:MIME-Version; bh=/q/pFzvKWu2mEF9/DwcsF9YD9/DZAPV7fZSCS+XMqKU=; b=Qlgo7CfiZ5KdoreoFUJSChFV2hrXfCFekuJ6iS65HAEggPhTPFmsqqiLJCNao9sxWybC MRQKuz3iMOrzAoVm9q3fhxhGMa2pZDNPVFm+2FrNgdvs9Etd3zYdAfOEX3u0dw/Y+lfGV UqPzFfxoojOxW/ywHJuk+0pFIpAp7DjSWZ1ddkqg5XOnOIy1DhpEk6fs4RKbu7HHAVQMp z1qjFzwU0XtCye0OqgaO+8nmuePxGuvU966cFqpAFiFaxLDycTw4cUTvghSYgvNB7pSfs 3T7VlIeUtCz8mvFYcxYNTDUrYXVUnDxHZLrkEV04x/kpg2K/+7qLJi5bHv0GHM33biw== X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=TnusCb4W; 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 A858F606A323; Thu, 26 Nov 2026 14:47:29 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=TnusCb4W X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795704438; b=JehB1U67RWryZIckWQ5edJSWT2tPEU45G2PafSF7Noiy/BElTfngzMQtmaPAAyC+uwas UvjnaQnaMNh4/FnmNMAYeVV8HOimJZGNTK3A1M8bV1UlM4dn/vSSa4ubTfnhm0jeYMFDU XQ35mITBQWfhKNes/GJqL/DdGvD/9rLzOU13pTNRf5bEHCRFFGkNcdU/znS8HUqNsCBOJ SlZrk4jip0EeGegK5nGIiXaUyNCiHo2+bbr3ikoFdRQ/aDbsoji39FB9ub74yVgXy6vj/ ZMlSpAVBenbxrk2I3Q1Z21674+9N3a6hCvwn3zNNFFGlxIq+957/2TYCabjeh4FGttw== X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795704438; h=Received:DKIM-Signature:Subject:From:To:Cc:Date:Message-ID: In-Reply-To:References:X-sashiko-severity:Content-Type: Content-Transfer-Encoding:MIME-Version; bh=/q/pFzvKWu2mEF9/DwcsF9YD9/DZAPV7fZSCS+XMqKU=; b=I9HbsfXmLCHEC6qHvnlq6ioN5E4ZyqhvCqBRY0UsBVm6b20FUa9+hmmUpO4btsTxdhLQ heaXDGQslhxntp32g28w10Qhr326zviSRyBPqyz/YY0P5MDg7ILuUwNdA/TyexJtMPSjZ D34h7T+Y89rQcrrZfwol1jLHVcOwxR5dylglt0lEc3Ci07kO4TfbuztWjJwsUXTMKQsJN z/sEvUi/+ECMTvu7lQ+BYRH7nVybFyNAdzJHb7qtFCtpQ7QvyFd9/2S3wrcYqUQ4koF/N jMhqkbnsY72MmkT2Ih+q3b0GLgmooJMipNjazEHuCltCe2kHjGnOF5O7e6mgQbKe68Q== X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=TnusCb4W; arc=none smtp.remote-ip=100.103.45.18 X-Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C4035606A31C; Thu, 26 Nov 2026 14:47:18 +0000 (UTC) X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id AA2621F000C0; Thu, 26 Nov 2026 14:47:17 +0000 (UTC) X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1795704438; bh=/q/pFzvKWu2mEF9/DwcsF9YD9/DZAPV7fZSCS+XMqKU=; h=Subject:From:To:Cc:Date:In-Reply-To:References; b=TnusCb4W4Q6qbGBNI/+jR7w8yDxVE4LJQfEBrhJ6cZFXGapUzlFTf3WMBxxMNbUeZ 7XJ/CuvWT5y24oUsLfgecaKlBERKAz1OzmvH50dDghi/kAdDc0zfT9mh8zFHgxnxJu d4213BuLgwWQeuNAyBZprdzTrjEavQFzp1Diram+4u+iv6nTh1l8/GrXGMoVUHOMI9 1sPHXVNf29OWNBJH6tDfAM7PWd+sx8uzQvzorHEsGxE3CVabagg/fy2XvHRTynXB+N Fc+8hJenVdWTNp/VftnqWgECRoEPV00Er7wPt4ljJzK42a8ezXl+OsKC368ooFspUy 4Mb6SuTqCNYoA== X-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 X-In-Reply-To: <20261125144514.2717012-3-anilkaushikwireless@gmail.com> X-sashiko-severity: Medium 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