Skip to contentSkip to conversation

bridge: Return an error when enabling STP in netns.

PATCH In review Kuniyuki Iwashima 4 participants 7 messages Jul 11, 2023 – Jul 13, 2023

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 bridge: Return an error when enabling STP in netns.

When we create an L2 loop on a bridge in netns, we will see packets storm even if STP is enabled.

  # unshare -n
  # ip link add br0 type bridge
  # ip link add veth0 type veth peer name veth1
  # ip link set veth0 master br0 up
  # ip link set veth1 master br0 up
  # ip link set br0 type bridge stp_state 1
  # ip link set br0 up
  # sleep 30
  # ip -s link show br0
  2: br0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP mode DEFAULT group default qlen 1000
      link/ether b6:61:98:1c:1c:b5 brd ff:ff:ff:ff:ff:ff
      RX: bytes  packets  errors  dropped missed  mcast
      956553768  12861249 0       0       0       12861249  <-. Keep
      TX: bytes  packets  errors  dropped carrier collsns     |  increasing
      1027834    11951    0       0       0       0         <-'   rapidly

This is because llc_rcv() drops all packets in non-root netns and BPDU is dropped.

Let's show an error when enabling STP in netns.

  # unshare -n
  # ip link add br0 type bridge
  # ip link set br0 type bridge stp_state 1
  Error: bridge: STP can't be enabled in non-root netns.

Note this commit will be reverted later when we namespacify the whole LLC infra.

Fixes e730c15519d0 ("[NET]: Make packet reception network namespace safe")
---
 net/bridge/br_stp_if.c | 5 +++++
 1 file changed, 5 insertions(+)
net/bridge/br_stp_if.c +5 -0
index 75204d36d7f9..a807996ac56b 100644
@@ -201,6 +201,11 @@ int br_stp_set_enabled(struct net_bridge *br, unsigned long val,
 {
 	ASSERT_RTNL();
 
+	if (!net_eq(dev_net(br->dev), &init_net)) {
+		NL_SET_ERR_MSG_MOD(extack, "STP can't be enabled in non-root netns");
+		return -EINVAL;
+	}
+
 	if (br_mrp_enabled(br)) {
 		NL_SET_ERR_MSG_MOD(extack,
 				   "STP can't be enabled if MRP is already enabled");
Signature · 1 line
2.30.2
maintainer Acked-by on v1 1/1
#1 lore raw
Quoted 46 lines · Kuniyuki Iwashima

When we create an L2 loop on a bridge in netns, we will see packets storm even if STP is enabled.

  # unshare -n
  # ip link add br0 type bridge
  # ip link add veth0 type veth peer name veth1
  # ip link set veth0 master br0 up
  # ip link set veth1 master br0 up
  # ip link set br0 type bridge stp_state 1
  # ip link set br0 up
  # sleep 30
  # ip -s link show br0
  2: br0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP mode DEFAULT group default qlen 1000
      link/ether b6:61:98:1c:1c:b5 brd ff:ff:ff:ff:ff:ff
      RX: bytes  packets  errors  dropped missed  mcast
      956553768  12861249 0       0       0       12861249  <-. Keep
      TX: bytes  packets  errors  dropped carrier collsns     |  increasing
      1027834    11951    0       0       0       0         <-'   rapidly

This is because llc_rcv() drops all packets in non-root netns and BPDU is dropped.

Let's show an error when enabling STP in netns.

  # unshare -n
  # ip link add br0 type bridge
  # ip link set br0 type bridge stp_state 1
  Error: bridge: STP can't be enabled in non-root netns.

Note this commit will be reverted later when we namespacify the whole LLC infra.

Fixes e730c15519d0 ("[NET]: Make packet reception network namespace safe")
---
 net/bridge/br_stp_if.c | 5 +++++
 1 file changed, 5 insertions(+)
net/bridge/br_stp_if.c +0 -0
index 75204d36d7f9..a807996ac56b 100644
@@ -201,6 +201,11 @@ int br_stp_set_enabled(struct net_bridge *br, unsigned long val,
 {

net/bridge/br_stp_if.c int br_stp_set_enabled(struct net_bridge *br, unsigned long val, · line 211

Quoted 10 lines
net/bridge/br_stp_if.c +5 -0
 	ASSERT_RTNL();
 
+	if (!net_eq(dev_net(br->dev), &init_net)) {
+		NL_SET_ERR_MSG_MOD(extack, "STP can't be enabled in non-root netns");
+		return -EINVAL;
+	}
+
 	if (br_mrp_enabled(br)) {
 		NL_SET_ERR_MSG_MOD(extack,
 				   "STP can't be enabled if MRP is already enabled");

Oh well, I guess this should do for now. Hopefully we don't break scripts that rely on configuring the bridge without any errors. Thanks for the patch,

#2 lore raw
In reply to Kuniyuki Iwashima
Quoted 29 lines · Kuniyuki Iwashima

When we create an L2 loop on a bridge in netns, we will see packets storm even if STP is enabled.

  # unshare -n
  # ip link add br0 type bridge
  # ip link add veth0 type veth peer name veth1
  # ip link set veth0 master br0 up
  # ip link set veth1 master br0 up
  # ip link set br0 type bridge stp_state 1
  # ip link set br0 up
  # sleep 30
  # ip -s link show br0
  2: br0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP mode DEFAULT group default qlen 1000
      link/ether b6:61:98:1c:1c:b5 brd ff:ff:ff:ff:ff:ff
      RX: bytes  packets  errors  dropped missed  mcast
      956553768  12861249 0       0       0       12861249  <-. Keep
      TX: bytes  packets  errors  dropped carrier collsns     |  increasing
      1027834    11951    0       0       0       0         <-'   rapidly

This is because llc_rcv() drops all packets in non-root netns and BPDU is dropped.

Let's show an error when enabling STP in netns.

  # unshare -n
  # ip link add br0 type bridge
  # ip link set br0 type bridge stp_state 1
  Error: bridge: STP can't be enabled in non-root netns.
Quoted 5 lines

Note this commit will be reverted later when we namespacify the whole LLC infra.

Fixes e730c15519d0 ("[NET]: Make packet reception network namespace safe")

I'm not sure that's accurate. I read his response in the link below and he says "I'd rather be warned than blocked" and "But better warned and awaiting a fix than blocked", which I agree with. The patch has the potential to cause a lot of regressions, but without actually fixing the problem.

How about simply removing the error [1]? Since iproute2 commit 844c37b42373 ("libnetlink: Handle extack messages for non-error case"), it can print extack warnings and not only errors. With the diff below:

 # unshare -n 
 # ip link add name br0 type bridge
 # ip link set dev br0 type bridge stp_state 1
 Warning: bridge: STP can't be enabled in non-root netns.
 # echo $?
 0

[1]

net/bridge/br_stp_if.c +1 -3
index a807996ac56b..b5143de37938 100644
@@ -201,10 +201,8 @@ int br_stp_set_enabled(struct net_bridge *br, unsigned long val,
 {
        ASSERT_RTNL();
 
-       if (!net_eq(dev_net(br->dev), &init_net)) {
+       if (!net_eq(dev_net(br->dev), &init_net))
                NL_SET_ERR_MSG_MOD(extack, "STP can't be enabled in non-root netns");
-               return -EINVAL;
-       }
 
        if (br_mrp_enabled(br)) {
                NL_SET_ERR_MSG_MOD(extack,
Quoted 26 lines
---
 net/bridge/br_stp_if.c | 5 +++++
 1 file changed, 5 insertions(+)
net/bridge/br_stp_if.c +5 -0
index 75204d36d7f9..a807996ac56b 100644
@@ -201,6 +201,11 @@ int br_stp_set_enabled(struct net_bridge *br, unsigned long val,
 {
 	ASSERT_RTNL();
 
+	if (!net_eq(dev_net(br->dev), &init_net)) {
+		NL_SET_ERR_MSG_MOD(extack, "STP can't be enabled in non-root netns");
+		return -EINVAL;
+	}
+
 	if (br_mrp_enabled(br)) {
 		NL_SET_ERR_MSG_MOD(extack,
 				   "STP can't be enabled if MRP is already enabled");
Signature · 1 line
2.30.2
#3 lore raw
Quoted 61 lines · Ido Schimmel
Quoted 29 lines · Kuniyuki Iwashima

When we create an L2 loop on a bridge in netns, we will see packets storm even if STP is enabled.

  # unshare -n
  # ip link add br0 type bridge
  # ip link add veth0 type veth peer name veth1
  # ip link set veth0 master br0 up
  # ip link set veth1 master br0 up
  # ip link set br0 type bridge stp_state 1
  # ip link set br0 up
  # sleep 30
  # ip -s link show br0
  2: br0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP mode DEFAULT group default qlen 1000
      link/ether b6:61:98:1c:1c:b5 brd ff:ff:ff:ff:ff:ff
      RX: bytes  packets  errors  dropped missed  mcast
      956553768  12861249 0       0       0       12861249  <-. Keep
      TX: bytes  packets  errors  dropped carrier collsns     |  increasing
      1027834    11951    0       0       0       0         <-'   rapidly

This is because llc_rcv() drops all packets in non-root netns and BPDU is dropped.

Let's show an error when enabling STP in netns.

  # unshare -n
  # ip link add br0 type bridge
  # ip link set br0 type bridge stp_state 1
  Error: bridge: STP can't be enabled in non-root netns.
Quoted 5 lines

Note this commit will be reverted later when we namespacify the whole LLC infra.

Fixes e730c15519d0 ("[NET]: Make packet reception network namespace safe")

I'm not sure that's accurate. I read his response in the link below and he says "I'd rather be warned than blocked" and "But better warned and awaiting a fix than blocked", which I agree with. The patch has the potential to cause a lot of regressions, but without actually fixing the problem.

How about simply removing the error [1]? Since iproute2 commit 844c37b42373 ("libnetlink: Handle extack messages for non-error case"), it can print extack warnings and not only errors. With the diff below:

 # unshare -n 
 # ip link add name br0 type bridge
 # ip link set dev br0 type bridge stp_state 1
 Warning: bridge: STP can't be enabled in non-root netns.
 # echo $?
 0

[1]

net/bridge/br_stp_if.c +0 -0
index a807996ac56b..b5143de37938 100644
@@ -201,10 +201,8 @@ int br_stp_set_enabled(struct net_bridge *br, unsigned long val,
 {

net/bridge/br_stp_if.c int br_stp_set_enabled(struct net_bridge *br, unsigned long val, · line 208

Quoted 10 lines
net/bridge/br_stp_if.c +1 -3
        ASSERT_RTNL();
 
-       if (!net_eq(dev_net(br->dev), &init_net)) {
+       if (!net_eq(dev_net(br->dev), &init_net))
                NL_SET_ERR_MSG_MOD(extack, "STP can't be enabled in non-root netns");
-               return -EINVAL;
-       }
 
        if (br_mrp_enabled(br)) {
                NL_SET_ERR_MSG_MOD(extack,

I'd prefer this approach to changing user-visible behaviour and potential regressions. Just change the warning message.

Thanks,
Nik

#4 lore raw
Quoted 2 lines · Nikolay Aleksandrov

I'd prefer this approach to changing user-visible behaviour and potential regressions. Just change the warning message.

Yea, I noticed after sending that the message no longer fits :)

#5 lore raw
In reply to Nikolay Aleksandrov
Quoted 68 lines · Nikolay Aleksandrov
Quoted 67 lines · Ido Schimmel
Quoted 29 lines · Kuniyuki Iwashima

When we create an L2 loop on a bridge in netns, we will see packets storm even if STP is enabled.

   # unshare -n
   # ip link add br0 type bridge
   # ip link add veth0 type veth peer name veth1
   # ip link set veth0 master br0 up
   # ip link set veth1 master br0 up
   # ip link set br0 type bridge stp_state 1
   # ip link set br0 up
   # sleep 30
   # ip -s link show br0
   2: br0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP mode DEFAULT group default qlen 1000
       link/ether b6:61:98:1c:1c:b5 brd ff:ff:ff:ff:ff:ff
       RX: bytes  packets  errors  dropped missed  mcast
       956553768  12861249 0       0       0       12861249  <-. Keep
       TX: bytes  packets  errors  dropped carrier collsns     |  increasing
       1027834    11951    0       0       0       0         <-'   rapidly

This is because llc_rcv() drops all packets in non-root netns and BPDU is dropped.

Let's show an error when enabling STP in netns.

   # unshare -n
   # ip link add br0 type bridge
   # ip link set br0 type bridge stp_state 1
   Error: bridge: STP can't be enabled in non-root netns.
Quoted 5 lines

Note this commit will be reverted later when we namespacify the whole LLC infra.

Fixes e730c15519d0 ("[NET]: Make packet reception network namespace safe")

I'm not sure that's accurate. I read his response in the link below and he says "I'd rather be warned than blocked" and "But better warned and awaiting a fix than blocked", which I agree with. The patch has the potential to cause a lot of regressions, but without actually fixing the problem.

How about simply removing the error [1]? Since iproute2 commit 844c37b42373 ("libnetlink: Handle extack messages for non-error case"), it can print extack warnings and not only errors. With the diff below:

  # unshare -n
  # ip link add name br0 type bridge
  # ip link set dev br0 type bridge stp_state 1
  Warning: bridge: STP can't be enabled in non-root netns.
  # echo $?
  0

[1]

net/bridge/br_stp_if.c +1 -3
index a807996ac56b..b5143de37938 100644
@@ -201,10 +201,8 @@ int br_stp_set_enabled(struct net_bridge *br, unsigned long val,
  {
         ASSERT_RTNL();
 
-       if (!net_eq(dev_net(br->dev), &init_net)) {
+       if (!net_eq(dev_net(br->dev), &init_net))
                 NL_SET_ERR_MSG_MOD(extack, "STP can't be enabled in non-root netns");
-               return -EINVAL;
-       }
 
Quoted 8 lines

net/bridge/br_stp_if.c int br_stp_set_enabled(struct net_bridge *br, unsigned long val, · line 208

Quoted 3 lines
net/bridge/br_stp_if.c +0 -0
         if (br_mrp_enabled(br)) {
                 NL_SET_ERR_MSG_MOD(extack,

I'd prefer this approach to changing user-visible behaviour and potential regressions. Just change the warning message.

Thanks,
Nik

Remember, the only way it's honest to 'warn but not block' STP in netns is trust in the Kuniyuki's assertion that the llc will be 'namespacified' in a near term frame.   As STP is not only non-functional in a netns, but will in fact bring down every connected system in a packet storm should a L2 loop exist the situation is much worse than a merely inaccessible extra feature. This as the only reason STP exists is to avoid crashing sites owing to packet storms arising from L2 loops.    I think as this bug is a potential 'site killer' (which in fact happened to me!) The Linux dev community has an obligation to either hard block this or commit to a fix time frame and merely warn.

Thanks

Harry Coin

#6 lore raw
In reply to Ido Schimmel

From: Ido Schimmel <[email protected]>
Date: Wed, 12 Jul 2023 17:48:20 +0300

Quoted 42 lines · Kuniyuki Iwashima
Quoted 29 lines

When we create an L2 loop on a bridge in netns, we will see packets storm even if STP is enabled.

  # unshare -n
  # ip link add br0 type bridge
  # ip link add veth0 type veth peer name veth1
  # ip link set veth0 master br0 up
  # ip link set veth1 master br0 up
  # ip link set br0 type bridge stp_state 1
  # ip link set br0 up
  # sleep 30
  # ip -s link show br0
  2: br0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP mode DEFAULT group default qlen 1000
      link/ether b6:61:98:1c:1c:b5 brd ff:ff:ff:ff:ff:ff
      RX: bytes  packets  errors  dropped missed  mcast
      956553768  12861249 0       0       0       12861249  <-. Keep
      TX: bytes  packets  errors  dropped carrier collsns     |  increasing
      1027834    11951    0       0       0       0         <-'   rapidly

This is because llc_rcv() drops all packets in non-root netns and BPDU is dropped.

Let's show an error when enabling STP in netns.

  # unshare -n
  # ip link add br0 type bridge
  # ip link set br0 type bridge stp_state 1
  Error: bridge: STP can't be enabled in non-root netns.
Quoted 5 lines

Note this commit will be reverted later when we namespacify the whole LLC infra.

Fixes e730c15519d0 ("[NET]: Make packet reception network namespace safe")

I'm not sure that's accurate. I read his response in the link below and he says "I'd rather be warned than blocked" and "But better warned and awaiting a fix than blocked", which I agree with. The patch has the potential to cause a lot of regressions, but without actually fixing the problem.

Quoted 3 lines

How about simply removing the error [1]? Since iproute2 commit 844c37b42373 ("libnetlink: Handle extack messages for non-error case"), it can print extack warnings and not only errors. With the diff below:

This is good to know and I also prefer this approach! I'll post v2.

Thanks!

Quoted 50 lines
 # unshare -n 
 # ip link add name br0 type bridge
 # ip link set dev br0 type bridge stp_state 1
 Warning: bridge: STP can't be enabled in non-root netns.
 # echo $?
 0

[1]

net/bridge/br_stp_if.c +1 -3
index a807996ac56b..b5143de37938 100644
@@ -201,10 +201,8 @@ int br_stp_set_enabled(struct net_bridge *br, unsigned long val,
 {
        ASSERT_RTNL();
 
-       if (!net_eq(dev_net(br->dev), &init_net)) {
+       if (!net_eq(dev_net(br->dev), &init_net))
                NL_SET_ERR_MSG_MOD(extack, "STP can't be enabled in non-root netns");
-               return -EINVAL;
-       }
 
        if (br_mrp_enabled(br)) {
                NL_SET_ERR_MSG_MOD(extack,
Quoted 25 lines
---
 net/bridge/br_stp_if.c | 5 +++++
 1 file changed, 5 insertions(+)
net/bridge/br_stp_if.c +5 -0
index 75204d36d7f9..a807996ac56b 100644
@@ -201,6 +201,11 @@ int br_stp_set_enabled(struct net_bridge *br, unsigned long val,
 {
 	ASSERT_RTNL();
 
+	if (!net_eq(dev_net(br->dev), &init_net)) {
+		NL_SET_ERR_MSG_MOD(extack, "STP can't be enabled in non-root netns");
+		return -EINVAL;
+	}
+
 	if (br_mrp_enabled(br)) {
 		NL_SET_ERR_MSG_MOD(extack,
 				   "STP can't be enabled if MRP is already enabled");
Signature · 1 line
2.30.2