Skip to contentSkip to conversation

selinux: don't label bridged packets in selinux_ip_forward()

PATCH Applied Joas Antonio dos Santos 4 participants 4 messages Oct 16 – Nov 9

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

PATCH 1/1 selinux: don't label bridged packets in selinux_ip_forward()

With br_netfilter and bridge-nf-call-ip{,6}tables enabled, bridged IP packets go through the NF_INET_FORWARD hook, where selinux_ip_forward() calls selinux_netlbl_skbuff_setsid() and NetLabel may add or remove a CIPSO or CALIPSO option. cipso_v4_skbuff_setattr(), calipso_skbuff_setattr() and calipso_skbuff_delattr() move the IP header and reset the network header, but the Ethernet header stays where it was; when the bridge pushes it back in front of the packet it picks up stale bytes and the frame goes out with a garbage destination MAC and EtherType.

Labeling a bridged packet based on its IP addresses is not what we want here anyway, so leave bridged packets alone. Add a stub of nf_bridge_info_exists() for CONFIG_BRIDGE_NETFILTER=n.

Tested with QEMU, two veths enslaved to a bridge with br_netfilter in the middle, SELinux and a NetLabel DOI 16 configuration, 5 UDP packets per case:

  case                                        before        after
  CALIPSO packet, unlabeled destination       MAC garbage   5/5
  unlabeled IPv6, CALIPSO destination         MAC garbage   5/5
  unlabeled IPv4, CIPSO destination           MAC garbage   5/5

Routed packets are still labeled (an unlabeled packet forwarded towards a CALIPSO destination gets the option, 5/5).

Fixes 948bf85c1bc9 ("netlabel: Add functionality to set the security attributes of a packet")
Assisted-by Claude:claude-opus-5-5
---
 include/linux/netfilter_bridge.h |  5 +++++
 security/selinux/hooks.c         | 13 ++++++++-----
 2 files changed, 13 insertions(+), 5 deletions(-)
include/linux/netfilter_bridge.h +5 -0
index 743475ca7..c1f7c3cb2 100644
@@ -79,6 +79,11 @@ static inline bool nf_bridge_in_prerouting(const struct sk_buff *skb)
 }
 #else
 #define br_drop_fake_rtable(skb)	        do { } while (0)
+static inline bool nf_bridge_info_exists(const struct sk_buff *skb)
+{
+	return false;
+}
+
 static inline bool nf_bridge_in_prerouting(const struct sk_buff *skb)
 {
 	return false;
security/selinux/hooks.c +8 -5
index 30776b010..1e4f02f99 100644
@@ -49,6 +49,7 @@
 #include <linux/fs_parser.h>
 #include <linux/netfilter_ipv4.h>
 #include <linux/netfilter_ipv6.h>
+#include <linux/netfilter_bridge.h>
 #include <linux/tty.h>
 #include <net/icmp.h>
 #include <net/ip.h>		/* for local_port_range[] */
@@ -6145,11 +6146,13 @@ static unsigned int selinux_ip_forward(void *priv, struct sk_buff *skb,
 				 SECCLASS_PACKET, PACKET__FORWARD_IN, &ad))
 			return NF_DROP;
 
-	if (netlbl_enabled())
-		/* we do this in the FORWARD path and not the POST_ROUTING
-		 * path because we want to make sure we apply the necessary
-		 * labeling before IPsec is applied so we can leverage AH
-		 * protection */
+	/* we do this in the FORWARD path and not the POST_ROUTING path
+	 * because we want to make sure we apply the necessary labeling
+	 * before IPsec is applied so we can leverage AH protection; bridged
+	 * packets are skipped as changing their IP options would leave the
+	 * Ethernet header behind
+	 */
+	if (netlbl_enabled() && !nf_bridge_info_exists(skb))
 		if (selinux_netlbl_skbuff_setsid(skb, family, peer_sid) != 0)
 			return NF_DROP;
 
Signature · 1 line
2.43.0
maintainer Acked-by on v1 1/1
#1 lore raw
Quoted 24 lines · Joas Antonio dos Santos

With br_netfilter and bridge-nf-call-ip{,6}tables enabled, bridged IP packets go through the NF_INET_FORWARD hook, where selinux_ip_forward() calls selinux_netlbl_skbuff_setsid() and NetLabel may add or remove a CIPSO or CALIPSO option. cipso_v4_skbuff_setattr(), calipso_skbuff_setattr() and calipso_skbuff_delattr() move the IP header and reset the network header, but the Ethernet header stays where it was; when the bridge pushes it back in front of the packet it picks up stale bytes and the frame goes out with a garbage destination MAC and EtherType.

Labeling a bridged packet based on its IP addresses is not what we want here anyway, so leave bridged packets alone. Add a stub of nf_bridge_info_exists() for CONFIG_BRIDGE_NETFILTER=n.

Tested with QEMU, two veths enslaved to a bridge with br_netfilter in the middle, SELinux and a NetLabel DOI 16 configuration, 5 UDP packets per case:

  case                                        before        after
  CALIPSO packet, unlabeled destination       MAC garbage   5/5
  unlabeled IPv6, CALIPSO destination         MAC garbage   5/5
  unlabeled IPv4, CIPSO destination           MAC garbage   5/5
Quoted 8 lines

Routed packets are still labeled (an unlabeled packet forwarded towards a CALIPSO destination gets the option, 5/5).

Fixes 948bf85c1bc9 ("netlabel: Add functionality to set the security attributes of a packet")
Assisted-by Claude:claude-opus-5-5
#2 lore raw
In reply to Joas Antonio dos Santos
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [High] selinux: NetLabel bypass for routed bridge packets in selinux_ip_forward() --

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] selinux: NetLabel bypass for routed bridge packets in selinux_ip_forward() --

commit aa9d29a0c0e705f6d7d92b6c1e12ec004af2b214
Author: Joas Antonio dos Santos <[email protected]>

selinux: don't label bridged packets in selinux_ip_forward()

This commit avoids labeling bridged IP packets in selinux_ip_forward() to prevent MAC and EtherType corruption when adding or removing CIPSO or CALIPSO options. It adds nf_bridge_info_exists() to skip bridged packets since labeling based on IP addresses is unwanted there.

Quoted 4 lines
security/selinux/hooks.c +0 -0
index 18dd28b2bb13d..735e4889bd5b7 100644

[ ... ]

Quoted 8 lines
security/selinux/hooks.c +0 -4
@@ -6021,11 +6022,13 @@ static unsigned int selinux_ip_forward(void *priv, struct sk_buff *skb,
 				 SECCLASS_PACKET, PACKET__FORWARD_IN, &ad))
 			return NF_DROP;
 
-	if (netlbl_enabled())
-		/* we do this in the FORWARD path and not the POST_ROUTING
-		 * path because we want to make sure we apply the necessary
-		 * labeling before IPsec is applied so we can leverage AH

security/selinux/hooks.c static unsigned int selinux_ip_forward(void *priv, struct sk_buff *skb, · line 6033

Quoted 10 lines
security/selinux/hooks.c +7 -1
-		 * protection */
+	/* we do this in the FORWARD path and not the POST_ROUTING path
+	 * because we want to make sure we apply the necessary labeling
+	 * before IPsec is applied so we can leverage AH protection; bridged
+	 * packets are skipped as changing their IP options would leave the
+	 * Ethernet header behind
+	 */
+	if (netlbl_enabled() && !nf_bridge_info_exists(skb))
 		if (selinux_netlbl_skbuff_setsid(skb, family, peer_sid) != 0)
 			return NF_DROP;

[Severity: High]
Does this logic inadvertently skip NetLabel tagging for packets that are legitimately routed rather than just bridged?

If a packet arrives on a bridge port, receives the SKB_EXT_BRIDGE_NF extension in br_nf_pre_routing(), and is destined for the host's MAC address, it is passed up to the local IP stack via br_pass_frame_up().

Since the bridge extension is not freed on the local input path, the packet retains it.

When the packet is subsequently L3 forwarded via ip_forward(), the NF_INET_FORWARD hook calls selinux_ip_forward().

Because nf_bridge_info_exists(skb) evaluates to true for these routed packets, it appears SELinux will erroneously skip the NetLabel tagging, potentially allowing a remote or local unprivileged attacker to bypass network security policies.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
maintainer Applied
#3 lore raw
In reply to Joas Antonio dos Santos
Quoted 33 lines · On Oct 16, 2026 Joas Antonio dos Santos <[email protected]> wrote:

With br_netfilter and bridge-nf-call-ip{,6}tables enabled, bridged IP packets go through the NF_INET_FORWARD hook, where selinux_ip_forward() calls selinux_netlbl_skbuff_setsid() and NetLabel may add or remove a CIPSO or CALIPSO option. cipso_v4_skbuff_setattr(), calipso_skbuff_setattr() and calipso_skbuff_delattr() move the IP header and reset the network header, but the Ethernet header stays where it was; when the bridge pushes it back in front of the packet it picks up stale bytes and the frame goes out with a garbage destination MAC and EtherType.

Labeling a bridged packet based on its IP addresses is not what we want here anyway, so leave bridged packets alone. Add a stub of nf_bridge_info_exists() for CONFIG_BRIDGE_NETFILTER=n.

Tested with QEMU, two veths enslaved to a bridge with br_netfilter in the middle, SELinux and a NetLabel DOI 16 configuration, 5 UDP packets per case:

  case                                        before        after
  CALIPSO packet, unlabeled destination       MAC garbage   5/5
  unlabeled IPv6, CALIPSO destination         MAC garbage   5/5
  unlabeled IPv4, CIPSO destination           MAC garbage   5/5

Routed packets are still labeled (an unlabeled packet forwarded towards a CALIPSO destination gets the option, 5/5).

Fixes 948bf85c1bc9 ("netlabel: Add functionality to set the security attributes of a packet")
Assisted-by Claude:claude-opus-5-5
Quoted 4 lines
---
 include/linux/netfilter_bridge.h |  5 +++++
 security/selinux/hooks.c         | 13 ++++++++-----
 2 files changed, 13 insertions(+), 5 deletions(-)

This looks good to me, thanks for all the work you put into this! It's been several weeks with no objections from the netdev folks about the nf_bridge_info_exists() dummy function so I'm going to assume they are okay with that; if that's not the case, please speak up soon :)

Merged into selinux/dev.

--
paul-moore.com