[PATCH net v9 0/2] genetlink: Reject joining multicast groups no family owns

From: Anil Kaushik

Date: Wed Nov 25 2026 - 09:45:30 EST


genl_bind() lets any user join a multicast group ID that no family owns.
A family registered later can get that ID, and the socket stays a member
without a capability check. Patch 1 makes genl_bind() return -ENOENT for
such an ID. Patch 2 adds a selftest for it.

v9:
- In the selftest, find the initial network namespace with its fixed
nsfs inode number, not by comparing with PID 1, which is in the same
namespace as the test in a container (Sashiko).
- Unload drop_monitor at the end of the selftest, so that the next run
does not skip that check (Sashiko).
- Patch 1 is unchanged. The Sashiko point on it in v8, a family
unregistered during the join, is the window the commit message
describes. The fix for it was patch 2 of v5, which was not accepted.

v8: https://lore.kernel.org/netdev/20261123155503.2497063-1-anilkaushikwireless@xxxxxxxxx/
- In the selftest, read the group memberships in host byte order, so it
also works on big-endian (Sashiko).
- Skip the selftest outside the initial network namespace: the family
dump there does not list the families that are not netnsok, so it
could take one of their groups as free (Sashiko).
- Close the selftest sockets, also when a check is skipped (Sashiko).
- Skip the drop_monitor check when NET_DM gets no group ID that was
free, so it cannot pass without testing anything (Sashiko).
- Rebase on net.

v7: https://lore.kernel.org/netdev/20261116124030.1595567-1-anilkaushikwireless@xxxxxxxxx/

I used an LLM to help write and review the code, the tests and the
commit messages of this series. I checked and tested every change
myself.

Anil Kaushik (2):
genetlink: Reject joining multicast groups no family owns
selftests: net: test joining genetlink groups no family owns

include/linux/netlink.h | 3 +
include/uapi/linux/net_dropmon.h | 2 +
net/netlink/af_netlink.c | 6 +
net/netlink/genetlink.c | 5 +-
tools/testing/selftests/net/Makefile | 1 +
tools/testing/selftests/net/nl_genl_mcast.py | 128 +++++++++++++++++++
6 files changed, 144 insertions(+), 1 deletion(-)
create mode 100755 tools/testing/selftests/net/nl_genl_mcast.py


base-commit: 7b0c5f0c757cb61e28dc4128633877aaa8f6f9bd
--
2.25.1