Skip to contentSkip to conversation

bridge: netfilter: orphan skb before invoking ip netfilter hooks

PATCH In review Florian Westphal 3 participants 4 messages Oct 24, 2013 – Oct 27, 2013

Subsystems (3)
lore
Share & tools
lore

Florian Westphal

author maintainer
#0 lore raw

PATCH 1/1 bridge: netfilter: orphan skb before invoking ip netfilter hooks

Pekka Pietikäinen reports xt_socket behavioural change after commit 00028aa37098o (netfilter: xt_socket: use IP early demux).

Reason is xt_socket now no longer does an unconditional sk lookup - it re-uses existing skb->sk if possible, assuming ->sk was set by tcp early demux.

However, when netfilter is invoked via bridge, this can cause 'bogus' sockets to be examined by the match, e.g. a 'tun' device socket.

bridge netfilter should orphan the skb just like the routing path before invoking ipv4/ipv6 netfilter hooks to avoid this.

---

net/bridge/br_netfilter.c +2 -0
index 878f008..80cad2c 100644
@@ -559,6 +559,8 @@ static struct net_device *setup_pre_routing(struct sk_buff *skb)
 	else if (skb->protocol == htons(ETH_P_PPP_SES))
 		nf_bridge->mask |= BRNF_PPPoE;
 
+	/* Must drop socket now because of tproxy. */
+	skb_orphan(skb);
 	return skb->dev;
 }
 
Signature · 6 lines
1.8.1.5

--
To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Acked-by on v1 1/1
#1 lore raw
Quoted 1 line · Florian Westphal

Pekka Pietikäinen reports xt_socket behavioural change after commit

behavioral maybe ? ;)

Quoted 5 lines

00028aa37098o (netfilter: xt_socket: use IP early demux).

Reason is xt_socket now no longer does an unconditional sk lookup - it re-uses existing skb->sk if possible, assuming ->sk was set by tcp early demux.

s/tcp/ip/ since it also can work for UDP sockets in net-next

Quoted 15 lines

However, when netfilter is invoked via bridge, this can cause 'bogus' sockets to be examined by the match, e.g. a 'tun' device socket.

bridge netfilter should orphan the skb just like the routing path before invoking ipv4/ipv6 netfilter hooks to avoid this.

---

net/bridge/br_netfilter.c +0 -0
index 878f008..80cad2c 100644

net/bridge/br_netfilter.c static struct net_device *setup_pre_routing(struct sk_buff *skb) · line 566

Quoted 8 lines
net/bridge/br_netfilter.c +2 -0
@@ -559,6 +559,8 @@ static struct net_device *setup_pre_routing(struct sk_buff *skb)
 	else if (skb->protocol == htons(ETH_P_PPP_SES))
 		nf_bridge->mask |= BRNF_PPPoE;
 
+	/* Must drop socket now because of tproxy. */
+	skb_orphan(skb);
 	return skb->dev;
 }
 

This was a nice one, thanks Florian !

--
To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

author maintainer
#2 lore raw
Quoted 4 lines · Eric Dumazet
Quoted 1 line · Florian Westphal

Pekka Pietikäinen reports xt_socket behavioural change after commit

behavioral maybe ? ;)

AE vs. BE i guess. I grep'd /usr/share/dict/* before, i swear ;)

Quoted 7 lines
Quoted 5 lines

00028aa37098o (netfilter: xt_socket: use IP early demux).

Reason is xt_socket now no longer does an unconditional sk lookup - it re-uses existing skb->sk if possible, assuming ->sk was set by tcp early demux.

s/tcp/ip/ since it also can work for UDP sockets in net-next

True. Pablo, could you amend this bit if you decide to apply this to -next tree (i guess -next is fine)?

Thanks for reviewing this Eric!
--
To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#3 lore raw
Quoted 1 line · Florian Westphal

Eric Dumazet <[email protected]> wrote:

[...]

Quoted 7 lines
Quoted 4 lines
Quoted 2 lines

it re-uses existing skb->sk if possible, assuming ->sk was set by tcp early demux.

s/tcp/ip/ since it also can work for UDP sockets in net-next

True. Pablo, could you amend this bit if you decide to apply this to -next tree (i guess -next is fine)?

Amended and applied, thanks Florian!