* [PATCH net] vlan: require real device netns admin to change GVRP and MVRP
@ 2026-11-17 13:04 Suyuan Wang via B4 Relay
2026-11-21 23:15 ` Jakub Kicinski
2026-11-21 23:20 ` patchwork-bot+netdevbpf
0 siblings, 2 replies; 3+ messages in thread
From: Suyuan Wang via B4 Relay @ 2026-11-17 13:04 UTC (permalink / raw)
To: netdev; +Cc: edumazet, kuba, davem, linux-kernel, elb12345, horms, pabeni
From: Suyuan Wang <stevewong@hust.edu.cn>
A VLAN device can be moved to another network namespace while its real
device stays behind. CAP_NET_ADMIN in the VLAN's namespace is then
enough to change its flags, through IFLA_VLAN_FLAGS or the
SET_VLAN_FLAG_CMD ioctl. Two of those flags act on the real device
rather than on the VLAN:
if (netif_running(dev) && (new_flags ^ old_flags) & VLAN_FLAG_GVRP) {
if (new_flags & VLAN_FLAG_GVRP)
vlan_gvrp_request_join(dev);
...
vlan_gvrp_request_join() and vlan_mvrp_request_join() declare the VLAN's
own VID on real_dev's GARP/MRP applicant, so the real device starts
sending registrations for it on the wire, and the switch on the other
end may add the port to that VLAN. On a running VLAN, clearing the flag
withdraws the declaration the same way.
So an administrator of the VLAN's namespace, with no capability in the
real device's namespace, can make the real device emit GVRP/MVRP
registrations on the wire. Check CAP_NET_ADMIN in the real device's
namespace in vlan_dev_change_flags() when GVRP or MVRP changes, which
covers both the rtnetlink and the ioctl path. rtnl_dev_link_net_capable()
allows it right away when both devices are in the same namespace, so
nothing changes for that case. This matches macvlan and the changelink
series that gated the tunnel drivers and, recently, macsec.
rtnl_dev_link_net_capable() was added by commit 8165f7ff57d9 ("net:
ip_gre: require CAP_NET_ADMIN in the device netns for changelink"); a
stable tree without it needs that first.
Found with a static analysis tool and checked by hand.
Fixes: 70c03b49b80b ("vlan: Add GVRP support")
Fixes: 86fbe9bb599f ("net/8021q: Implement Multiple VLAN Registration Protocol (MVRP)")
Cc: stable+noautosel@kernel.org # local DoS by a userns admin; low severity
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 under QEMU with network namespaces (x86_64, GVRP and MVRP
enabled): an unprivileged user+net namespace admin can toggle GVRP and
MVRP on a VLAN whose real device stays in the init netns before this
patch, via both the SET_VLAN_FLAG_CMD ioctl and the rtnetlink
IFLA_VLAN_FLAGS path, and is denied with -EPERM after it, while a
same-netns privileged admin still can. W=1 and sparse show no new
warnings. I haven't run it against a real switch.
The same gap in macsec was fixed in commit ed502e485685 ("macsec:
require CAP_NET_ADMIN in the device netns for changelink"). Its author
described the identical VLAN case there and said a separate VLAN patch
would follow; I could not find one on netdev, so this is sent
independently.
Link: https://lore.kernel.org/netdev/AS8P251MB000190AAD82CD30EFBC57B4DC8B42@AS8P251MB0001.EURP251.PROD.OUTLOOK.COM/
---
net/8021q/vlan_dev.c | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/net/8021q/vlan_dev.c b/net/8021q/vlan_dev.c
index bca0a3693636..44067b0ccf35 100644
--- a/net/8021q/vlan_dev.c
+++ b/net/8021q/vlan_dev.c
@@ -269,6 +269,12 @@ int vlan_dev_change_flags(const struct net_device *dev, u32 flags, u32 mask)
return -EINVAL;
new_flags = (old_flags & ~mask) | (flags & mask);
+
+ /* GVRP and MVRP act on the real device, which may be in another netns */
+ if (((new_flags ^ old_flags) & (VLAN_FLAG_GVRP | VLAN_FLAG_MVRP)) &&
+ !rtnl_dev_link_net_capable(dev, dev_net(vlan->real_dev)))
+ return -EPERM;
+
WRITE_ONCE(vlan->flags, new_flags);
if (netif_running(dev) && (new_flags ^ old_flags) & VLAN_FLAG_GVRP) {
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH net] vlan: require real device netns admin to change GVRP and MVRP
2026-11-17 13:04 [PATCH net] vlan: require real device netns admin to change GVRP and MVRP Suyuan Wang via B4 Relay
@ 2026-11-21 23:15 ` Jakub Kicinski
2026-11-21 23:20 ` patchwork-bot+netdevbpf
1 sibling, 0 replies; 3+ messages in thread
From: Jakub Kicinski @ 2026-11-21 23:15 UTC (permalink / raw)
To: Suyuan Wang via B4 Relay
Cc: shyckless, netdev, edumazet, davem, linux-kernel, elb12345, horms,
pabeni
On Tue, 17 Nov 2026 13:04:41 +0000 Suyuan Wang via B4 Relay wrote:
> The same gap in macsec was fixed in commit ed502e485685 ("macsec:
> require CAP_NET_ADMIN in the device netns for changelink"). Its author
> described the identical VLAN case there and said a separate VLAN patch
> would follow; I could not find one on netdev, so this is sent
> independently.
We can apply this as hardening but I'm not sure this is an issue.
netns can already "disable" the vlan by deleting the interface.
I guess we shouldn't let netns enable the vlan. But then again
I don't see the use case for having a vlan that's not announced,
or the harm announcing it would cause.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH net] vlan: require real device netns admin to change GVRP and MVRP
2026-11-17 13:04 [PATCH net] vlan: require real device netns admin to change GVRP and MVRP Suyuan Wang via B4 Relay
2026-11-21 23:15 ` Jakub Kicinski
@ 2026-11-21 23:20 ` patchwork-bot+netdevbpf
1 sibling, 0 replies; 3+ messages in thread
From: patchwork-bot+netdevbpf @ 2026-11-21 23:20 UTC (permalink / raw)
To: Suyuan Wang
Cc: netdev, edumazet, kuba, davem, linux-kernel, elb12345, horms,
pabeni
Hello:
This patch was applied to netdev/net-next.git (main)
by Jakub Kicinski <kuba@kernel.org>:
On Tue, 17 Nov 2026 13:04:41 +0000 you wrote:
> From: Suyuan Wang <stevewong@hust.edu.cn>
>
> A VLAN device can be moved to another network namespace while its real
> device stays behind. CAP_NET_ADMIN in the VLAN's namespace is then
> enough to change its flags, through IFLA_VLAN_FLAGS or the
> SET_VLAN_FLAG_CMD ioctl. Two of those flags act on the real device
> rather than on the VLAN:
>
> [...]
Here is the summary with links:
- [net] vlan: require real device netns admin to change GVRP and MVRP
https://git.kernel.org/netdev/net-next/c/e678e4283983
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] 3+ messages in thread
end of thread, other threads:[~2026-11-21 23:20 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-17 13:04 [PATCH net] vlan: require real device netns admin to change GVRP and MVRP Suyuan Wang via B4 Relay
2026-11-21 23:15 ` Jakub Kicinski
2026-11-21 23: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