Netdev List
 help / color / mirror / Atom feed
* [PATCH net] l2tp: require CAP_NET_ADMIN to join the l2tp multicast group
@ 2026-11-20  8:51 Suyuan Wang via B4 Relay
  2026-11-24  9:12 ` netdev-bot+sashiko
  0 siblings, 1 reply; 2+ messages in thread
From: Suyuan Wang via B4 Relay @ 2026-11-20  8:51 UTC (permalink / raw)
  To: davem, edumazet, kuba, pabeni
  Cc: stephen, linux-kernel, maoyixie.tju, netdev, 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.

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.

Found with a static analysis tool and checked by hand.

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

This covers joining the registered group. Joining a group ID before any
family owns it is a separate genetlink issue, handled by "genetlink:
Reject joining multicast groups no family owns".
---
 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 89ef04c78787..98290cc956fe 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] 2+ messages in thread

* Re: [PATCH net] l2tp: require CAP_NET_ADMIN to join the l2tp multicast group
  2026-11-20  8:51 [PATCH net] l2tp: require CAP_NET_ADMIN to join the l2tp multicast group Suyuan Wang via B4 Relay
@ 2026-11-24  9:12 ` netdev-bot+sashiko
  0 siblings, 0 replies; 2+ messages in thread
From: netdev-bot+sashiko @ 2026-11-24  9:12 UTC (permalink / raw)
  To: shyckless
  Cc: davem, edumazet, kuba, pabeni, stephen, linux-kernel,
	maoyixie.tju, netdev, 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] The commit message says the patch stops unprivileged listeners
  in the tunnel's own netns from getting l2tp notifications ("This patch…

--

l2tp: require CAP_NET_ADMIN to join the l2tp multicast group

This commit marks the l2tp generic netlink multicast group with
GENL_MCAST_CAP_NET_ADMIN. With the flag set, genl_bind() requires
CAP_NET_ADMIN in the user namespace that owns the network namespace before
a socket can join the group. The goal is to keep unprivileged listeners in
the tunnel's namespace from receiving tunnel and session notifications,
which include L2TPv3 cookies.

> 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 "This patch handles listeners in the tunnel's own
namespace." Does that hold when l2tp_netlink is built as a module and has
not been loaded yet?

genl_bind() only checks the new flag when a registered family owns the
group ID:

net/netlink/genetlink.c:genl_bind() {
    ...
	idr_for_each_entry(&genl_fam_idr, family, id) {
		...
		i = group - family->mcgrp_offset;
		if (i < 0 || i >= family->n_mcgrps)
			continue;

		grp = &family->mcgrps[i];
		if ((grp->flags & GENL_MCAST_CAP_NET_ADMIN) &&
		    !ns_capable(net->user_ns, CAP_NET_ADMIN))
			ret = -EPERM;
    ...
}

If no family owns the ID, ret stays 0 and the join succeeds. Apart from the
NL_CFG_F_NONROOT_RECV check, netlink_setsockopt(NETLINK_ADD_MEMBERSHIP)
only compares the ID against nlk->ngroups.

It looks like an unprivileged user in the same netns could do this:

  setsockopt(NETLINK_ADD_MEMBERSHIP) on every free genetlink group ID
  send CTRL_CMD_GETFAMILY "l2tp"
    ctrl_getfamily()->request_module()     (MODULE_ALIAS_GENL_FAMILY("l2tp"))
      genl_register_family()
        genl_allocate_reserve_groups()
          find_first_zero_bit()            <- returns an ID already joined

genl_validate_assign_mc_groups() does not remove sockets that are already
subscribed to that ID. Later notifications sent through
genlmsg_multicast_netns() would then reach the pre-joined socket, and
genl_bind() never checks the new flag for it. Those notifications include
the cookies that l2tp_nl_session_send() adds.

The note below the --- line mentions a companion patch, "genetlink: Reject
joining multicast groups no family owns". That note is dropped when the
patch is applied, and genl_bind() is unchanged in this tree.

This patch is Cc: stable. Could it be sent as a series with the genetlink
fix, or could the commit message name that dependency? Otherwise a backport
of this commit alone would leave the cookie leak reachable on CONFIG_L2TP=m
builds.

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261120-l2tp-mcast-perm-v1-1-22dbffa88655%40gmail.com

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-11-24  9:12 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-20  8:51 [PATCH net] l2tp: require CAP_NET_ADMIN to join the l2tp multicast group Suyuan Wang via B4 Relay
2026-11-24  9:12 ` netdev-bot+sashiko

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox