* [PATCH net v2] l2tp: require CAP_NET_ADMIN to join the l2tp multicast group
@ 2026-11-24 9:57 Suyuan Wang via B4 Relay
2026-11-25 9:58 ` netdev-bot+sashiko
2026-12-02 17:20 ` patchwork-bot+netdevbpf
0 siblings, 2 replies; 4+ messages in thread
From: Suyuan Wang via B4 Relay @ 2026-11-24 9:57 UTC (permalink / raw)
To: pabeni, kuba, davem, edumazet
Cc: netdev, maoyixie.tju, anilkaushikwireless, stephen, linux-kernel,
horms
From: Suyuan Wang <stevewong@hust.edu.cn>
The l2tp generic netlink family sends a notification on its "l2tp"
multicast group whenever a tunnel or session is created, modified or
deleted. The message is built by the same l2tp_nl_tunnel_send() and
l2tp_nl_session_send() helpers as the replies to TUNNEL_GET and
SESSION_GET, so it carries the tunnel and session IDs, the addresses
and ports, the statistics and, for L2TPv3 sessions with cookies
configured, the local and peer cookies.
The tunnel and session commands, including the GET commands, need
CAP_NET_ADMIN in the user namespace owning the network namespace
(GENL_UNS_ADMIN_PERM), but generic netlink lets any user join a
multicast group by default. So an unprivileged user in the same network
namespace can read all of this by joining the group. Configured cookies
help an L2TPv3 endpoint reject blindly injected packets, and leaking
them weakens that.
Commit ed267f783c0c ("l2tp: send netlink notifications in the tunnel's
net namespace") already noted that a listener needs no privilege, but
only stopped the notifications from reaching other network namespaces.
This patch handles listeners in the tunnel's own namespace that join
the group after the l2tp family is registered.
Mark the group with GENL_MCAST_CAP_NET_ADMIN, as was done for gtp in
commit db627e71b6da ("gtp: Require 'CAP_NET_ADMIN' when joining the gtp
multicast group"). genl_bind() then requires CAP_NET_ADMIN in the user
namespace owning the network namespace, the same capability and
namespace as the tunnel and session commands.
genl_bind() only checks the flag for a group ID that a registered
family owns. A socket that joins the ID before the l2tp family is
registered, for example before l2tp_netlink is loaded, keeps getting
the notifications. This affects every family that uses
GENL_MCAST_CAP_*, including gtp, and is fixed separately in genetlink
[1]. Backports need that fix too to cover this case.
Found with a static analysis tool and checked by hand.
Link: https://lore.kernel.org/all/20261123155503.2497063-1-anilkaushikwireless@gmail.com/ [1]
Fixes: 33f72e6f0c67 ("l2tp : multicast notification to the registered listeners")
Cc: stable@vger.kernel.org
Co-developed-by: Kaixuan Li <kaixuan.li@ntu.edu.sg>
Signed-off-by: Kaixuan Li <kaixuan.li@ntu.edu.sg>
Signed-off-by: Suyuan Wang <stevewong@hust.edu.cn>
---
Tested in QEMU (x86_64): three listeners join the "l2tp" group, then
root creates an L2TPv3 tunnel and a session with a cookie.
Before:
root: joined, gets TUNNEL_CREATE and SESSION_CREATE (with the cookie)
root without CAP_NET_ADMIN: same
nobody: same
After:
root: joined, gets both notifications
root without CAP_NET_ADMIN: EPERM
nobody: EPERM
Changes in v2:
- Say in the commit message that joining the group ID before the family
is registered is not covered here, and that backports also need the
pending genetlink fix (Sashiko).
v1: https://lore.kernel.org/all/20261120-l2tp-mcast-perm-v1-1-22dbffa88655@gmail.com/
---
net/l2tp/l2tp_netlink.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/net/l2tp/l2tp_netlink.c b/net/l2tp/l2tp_netlink.c
index a07009d4cb00..c442e953df66 100644
--- a/net/l2tp/l2tp_netlink.c
+++ b/net/l2tp/l2tp_netlink.c
@@ -31,6 +31,7 @@ static struct genl_family l2tp_nl_family;
static const struct genl_multicast_group l2tp_multicast_group[] = {
{
.name = L2TP_GENL_MCGROUP,
+ .flags = GENL_MCAST_CAP_NET_ADMIN,
},
};
^ permalink raw reply related [flat|nested] 4+ messages in thread* Re: [PATCH net v2] l2tp: require CAP_NET_ADMIN to join the l2tp multicast group 2026-11-24 9:57 [PATCH net v2] l2tp: require CAP_NET_ADMIN to join the l2tp multicast group Suyuan Wang via B4 Relay @ 2026-11-25 9:58 ` netdev-bot+sashiko 2026-11-27 11:06 ` Wong Steve 2026-12-02 17:20 ` patchwork-bot+netdevbpf 1 sibling, 1 reply; 4+ messages in thread From: netdev-bot+sashiko @ 2026-11-25 9:58 UTC (permalink / raw) To: shyckless Cc: pabeni, kuba, davem, edumazet, netdev, maoyixie.tju, anilkaushikwireless, stephen, linux-kernel, horms Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider. Critical: 0 · High: 0 · Medium: 1 · Low: 0 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] On its own, this patch does not stop an unprivileged local user from receiving l2tp tunnel and session notifications, including… -- l2tp: require CAP_NET_ADMIN to join the l2tp multicast group This patch marks the l2tp generic netlink multicast group with GENL_MCAST_CAP_NET_ADMIN. After this, genl_bind() requires CAP_NET_ADMIN in the user namespace that owns the network namespace before a socket can join the group. Tunnel and session notifications, including L2TPv3 cookies, then no longer reach unprivileged listeners that join after the family is registered. Link: https://lore.kernel.org/all/20261123155503.2497063-1-anilkaushikwireless@gmail.com/ [1] > diff --git a/net/l2tp/l2tp_netlink.c b/net/l2tp/l2tp_netlink.c > index a07009d4cb009..c442e953df66a 100644 > --- a/net/l2tp/l2tp_netlink.c > +++ b/net/l2tp/l2tp_netlink.c > @@ -31,6 +31,7 @@ static struct genl_family l2tp_nl_family; > static const struct genl_multicast_group l2tp_multicast_group[] = { > { > .name = L2TP_GENL_MCGROUP, > + .flags = GENL_MCAST_CAP_NET_ADMIN, [Severity: Medium] The commit message says the pre-registration case remains open, and gives this example: "A socket that joins the ID before the l2tp family is registered, for example before l2tp_netlink is loaded, keeps getting the notifications." Can an unprivileged user also control when that registration happens? If so, the leak is still reachable as long as this patch is applied without [1]. The new flag is only checked in genl_bind(), and only when a registered family owns the requested group ID: net/netlink/genetlink.c:genl_bind() { ... i = group - family->mcgrp_offset; if (i < 0 || i >= family->n_mcgrps) continue; ... } For an ID that no family owns, ret stays 0 and the join succeeds. netlink_setsockopt(NETLINK_ADD_MEMBERSHIP) checks only NL_CFG_F_NONROOT_RECV, which genetlink sets, and that val - 1 is below nlk->ngroups. So any free bit in the genl group bitmap can be joined without a capability. When l2tp_netlink registers, genl_allocate_reserve_groups() picks a free bit with find_first_zero_bit(), and genl_validate_assign_mc_groups() assigns it: family->mcgrp_offset = first_id; On this path __netlink_clear_multicast_users() is never called. It is only called from genl_unregister_mc_groups(), so existing subscribers keep their membership. CTRL_CMD_GETFAMILY has no admin permission flag. For an unknown name, ctrl_getfamily() loads the module: net/netlink/genetlink.c:ctrl_getfamily() { ... if (res == NULL) { genl_unlock(); up_read(&cb_lock); request_module("net-pf-%d-proto-%d-family-%s", PF_NETLINK, NETLINK_GENERIC, name); ... } l2tp_netlink declares MODULE_ALIAS_GENL_FAMILY("l2tp"), so this sequence looks possible: unprivileged user: NETLINK_ADD_MEMBERSHIP on every free genl group ID genl_bind() returns 0 (no owner) CTRL_CMD_GETFAMILY name="l2tp" ctrl_getfamily()->request_module() l2tp_nl_init() registers the family on a bit already joined root: creates an L2TPv3 tunnel and session with cookies l2tp_session_notify()->genlmsg_multicast_netns() The message is built by l2tp_nl_session_send(), which includes L2TP_ATTR_COOKIE and L2TP_ATTR_PEER_COOKIE. It reaches the unprivileged socket, and membership is never checked again. Since the case here can be triggered on demand on any system with module autoloading where l2tp_netlink is not loaded yet, should the commit message say that an unprivileged user can trigger the load? Should [1] also be merged with or before this patch, and be listed as a hard dependency for the stable backports? > }, > }; > -- Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261124-l2tp-mcast-perm-v2-1-416741ccb334%40gmail.com ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH net v2] l2tp: require CAP_NET_ADMIN to join the l2tp multicast group 2026-11-25 9:58 ` netdev-bot+sashiko @ 2026-11-27 11:06 ` Wong Steve 0 siblings, 0 replies; 4+ messages in thread From: Wong Steve @ 2026-11-27 11:06 UTC (permalink / raw) To: netdev-bot+sashiko Cc: pabeni, kuba, davem, edumazet, netdev, maoyixie.tju, anilkaushikwireless, stephen, linux-kernel, horms > Can an unprivileged user also control when that registration happens? If > so, the leak is still reachable as long as this patch is applied > without [1]. Yes. Where l2tp_netlink is a module that is not loaded yet, an unprivileged user can join the free genl group IDs and then trigger the load with CTRL_CMD_GETFAMILY, which calls request_module() for the "l2tp" family alias. So the pre-registration case can be reached on demand, not only by joining early by chance. The commit message understates that. > Should [1] also be merged with or before this patch, and be listed as a > hard dependency for the stable backports? The two patches are independent. This one stops unprivileged sockets from joining the l2tp group once the family is registered, and does that on its own. [1] (now "genetlink: Reject joining multicast groups no family owns", v8) closes the pre-registration case for every family that uses GENL_MCAST_CAP_*, including gtp. Neither patch depends on the other to build or work, and the order does not matter, but a backport needs both to close both cases. If the maintainers want it, I can send a v3 that only changes the commit message: say that an unprivileged user can trigger the module load, and that stable backports should take [1] as well. Otherwise I'll leave v2 as it is. Thanks, Suyuan <netdev-bot+sashiko@kernel.org> 于2026年11月25日周三 17:58写道: > > Thank you for your contribution! Sashiko AI review found 1 potential > issue(s) to consider. > > Critical: 0 · High: 0 · Medium: 1 · Low: 0 > > 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] On its own, this patch does not stop an unprivileged local > user from receiving l2tp tunnel and session notifications, including… > > -- > > l2tp: require CAP_NET_ADMIN to join the l2tp multicast group > > This patch marks the l2tp generic netlink multicast group with > GENL_MCAST_CAP_NET_ADMIN. After this, genl_bind() requires CAP_NET_ADMIN > in the user namespace that owns the network namespace before a socket can > join the group. Tunnel and session notifications, including L2TPv3 > cookies, then no longer reach unprivileged listeners that join after the > family is registered. > > Link: https://lore.kernel.org/all/20261123155503.2497063-1-anilkaushikwireless@gmail.com/ [1] > > > diff --git a/net/l2tp/l2tp_netlink.c b/net/l2tp/l2tp_netlink.c > > index a07009d4cb009..c442e953df66a 100644 > > --- a/net/l2tp/l2tp_netlink.c > > +++ b/net/l2tp/l2tp_netlink.c > > @@ -31,6 +31,7 @@ static struct genl_family l2tp_nl_family; > > static const struct genl_multicast_group l2tp_multicast_group[] = { > > { > > .name = L2TP_GENL_MCGROUP, > > + .flags = GENL_MCAST_CAP_NET_ADMIN, > > [Severity: Medium] > The commit message says the pre-registration case remains open, and gives > this example: > > "A socket that joins the ID before the l2tp family is registered, for > example before l2tp_netlink is loaded, keeps getting the notifications." > > Can an unprivileged user also control when that registration happens? If > so, the leak is still reachable as long as this patch is applied > without [1]. > > The new flag is only checked in genl_bind(), and only when a registered > family owns the requested group ID: > > net/netlink/genetlink.c:genl_bind() { > ... > i = group - family->mcgrp_offset; > if (i < 0 || i >= family->n_mcgrps) > continue; > ... > } > > For an ID that no family owns, ret stays 0 and the join succeeds. > > netlink_setsockopt(NETLINK_ADD_MEMBERSHIP) checks only > NL_CFG_F_NONROOT_RECV, which genetlink sets, and that val - 1 is below > nlk->ngroups. So any free bit in the genl group bitmap can be joined > without a capability. > > When l2tp_netlink registers, genl_allocate_reserve_groups() picks a free > bit with find_first_zero_bit(), and genl_validate_assign_mc_groups() > assigns it: > > family->mcgrp_offset = first_id; > > On this path __netlink_clear_multicast_users() is never called. It is > only called from genl_unregister_mc_groups(), so existing subscribers > keep their membership. > > CTRL_CMD_GETFAMILY has no admin permission flag. For an unknown name, > ctrl_getfamily() loads the module: > > net/netlink/genetlink.c:ctrl_getfamily() { > ... > if (res == NULL) { > genl_unlock(); > up_read(&cb_lock); > request_module("net-pf-%d-proto-%d-family-%s", > PF_NETLINK, NETLINK_GENERIC, name); > ... > } > > l2tp_netlink declares MODULE_ALIAS_GENL_FAMILY("l2tp"), so this sequence > looks possible: > > unprivileged user: > NETLINK_ADD_MEMBERSHIP on every free genl group ID > genl_bind() returns 0 (no owner) > CTRL_CMD_GETFAMILY name="l2tp" > ctrl_getfamily()->request_module() > l2tp_nl_init() registers the family on a bit already joined > > root: > creates an L2TPv3 tunnel and session with cookies > l2tp_session_notify()->genlmsg_multicast_netns() > > The message is built by l2tp_nl_session_send(), which includes > L2TP_ATTR_COOKIE and L2TP_ATTR_PEER_COOKIE. It reaches the unprivileged > socket, and membership is never checked again. > > Since the case here can be triggered on demand on any system with module > autoloading where l2tp_netlink is not loaded yet, should the commit > message say that an unprivileged user can trigger the load? Should [1] > also be merged with or before this patch, and be listed as a hard > dependency for the stable backports? > > > }, > > }; > > > > -- > Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261124-l2tp-mcast-perm-v2-1-416741ccb334%40gmail.com ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH net v2] l2tp: require CAP_NET_ADMIN to join the l2tp multicast group 2026-11-24 9:57 [PATCH net v2] l2tp: require CAP_NET_ADMIN to join the l2tp multicast group Suyuan Wang via B4 Relay 2026-11-25 9:58 ` netdev-bot+sashiko @ 2026-12-02 17:20 ` patchwork-bot+netdevbpf 1 sibling, 0 replies; 4+ messages in thread From: patchwork-bot+netdevbpf @ 2026-12-02 17:20 UTC (permalink / raw) To: Suyuan Wang Cc: pabeni, kuba, davem, edumazet, netdev, maoyixie.tju, anilkaushikwireless, stephen, linux-kernel, horms Hello: This patch was applied to netdev/net-next.git (main) by Paolo Abeni <pabeni@redhat.com>: On Tue, 24 Nov 2026 09:57:36 +0000 you wrote: > From: Suyuan Wang <stevewong@hust.edu.cn> > > The l2tp generic netlink family sends a notification on its "l2tp" > multicast group whenever a tunnel or session is created, modified or > deleted. The message is built by the same l2tp_nl_tunnel_send() and > l2tp_nl_session_send() helpers as the replies to TUNNEL_GET and > SESSION_GET, so it carries the tunnel and session IDs, the addresses > and ports, the statistics and, for L2TPv3 sessions with cookies > configured, the local and peer cookies. > > [...] Here is the summary with links: - [net,v2] l2tp: require CAP_NET_ADMIN to join the l2tp multicast group https://git.kernel.org/netdev/net-next/c/41055751bb7b You are awesome, thank you! -- Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html ^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-12-02 17:20 UTC | newest] Thread overview: 4+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2026-11-24 9:57 [PATCH net v2] l2tp: require CAP_NET_ADMIN to join the l2tp multicast group Suyuan Wang via B4 Relay 2026-11-25 9:58 ` netdev-bot+sashiko 2026-11-27 11:06 ` Wong Steve 2026-12-02 17:20 ` patchwork-bot+netdevbpf
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox