From: netdev-bot+sashiko@kernel.org
To: anilkaushikwireless@gmail.com
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
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 [thread overview]
Message-ID: <179570443724.3135.6495722482046462156@kernel.org> (raw)
In-Reply-To: <20261125144514.2717012-3-anilkaushikwireless@gmail.com>
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
prev parent reply other threads:[~2026-11-26 14:47 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-25 14:45 [PATCH net v9 0/2] genetlink: Reject joining multicast groups no family owns Anil Kaushik
2026-11-25 14:45 ` [PATCH net v9 1/2] " Anil Kaushik
2026-11-25 14:45 ` [PATCH net v9 2/2] selftests: net: test joining genetlink " Anil Kaushik
2026-11-26 14:47 ` netdev-bot+sashiko [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=179570443724.3135.6495722482046462156@kernel.org \
--to=netdev-bot+sashiko@kernel.org \
--cc=aliceryhl@google.com \
--cc=anilkaushikwireless@gmail.com \
--cc=davem@davemloft.net \
--cc=edumazet@kernel.org \
--cc=fw@strlen.de \
--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=linux-kselftest@vger.kernel.org \
--cc=martineau@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=nhorman@tuxdriver.com \
--cc=nicolas.dichtel@6wind.com \
--cc=pabeni@redhat.com \
--cc=shuah@kernel.org \
--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