bridge: clean the nf_bridge status when forwarding the skb
Subsystems (4)
PATCH 1/1 bridge: clean the nf_bridge status when forwarding the skb
From: Antonio Quartulli <[email protected]>
Even if it is forbidden to enslave a bridge interface into another one, it is still possible to create a chain of virtual interfaces including two distinct bridges.
In this case, the skb entering the second bridge could have the nf_bridge field already set due to a previous operation and consequently lead to wrong a processing of the packet itself.
To prevent this behaviour release and set to NULL the nf_bridge field of the skb when forwarding the packet.
---
I know that not using "extern" when declaring the prototype is not consistent with the surrounding code, but checkpatch complaints about using "extern" in .h file and I prefer to not do something "wrong" even if stylistically ugly.
Cheers,
net/bridge/br_forward.c | 2 ++ net/bridge/br_netfilter.c | 10 ++++++++++ net/bridge/br_private.h | 2 ++ 3 files changed, 14 insertions(+)
net/bridge/br_forward.c +2 -0
@@ -49,6 +49,8 @@ int br_dev_queue_push_xmit(struct sk_buff *skb) }else {skb_push (skb,ETH_HLEN );br_drop_fake_rtable (skb); +br_netfilter_skb_free (skb); +dev_queue_xmit (skb); }
net/bridge/br_netfilter.c +10 -0
@@ -1086,3 +1086,13 @@ void br_netfilter_fini(void)#endif dst_entries_destroy (&fake_dst_ops); } + +/** +* br_netfilter_skb_free - clean the NF bridge data in an skb +* @skb: the skb which the data to free belongs to +*/ +void br_netfilter_skb_free (struct sk_buff *skb) +{ +nf_bridge_put (skb->nf_bridge); + skb->nf_bridge =NULL ; +}
net/bridge/br_private.h +2 -0
@@ -730,10 +730,12 @@ static inline u16 br_get_pvid(const struct net_port_vlans *v)extern int br_netfilter_init (void );extern void br_netfilter_fini (void );extern void br_netfilter_rtable_init (struct net_bridge *); +void br_netfilter_skb_free (struct sk_buff *skb);#else #define br_netfilter_init () (0)#define br_netfilter_fini () do { } while(0)#define br_netfilter_rtable_init (x) +#define br_netfilter_skb_free (x)#endif /* br_stp.c */
Signature · 1 line
1.8.3.2
Pablo Neira Ayuso
maintainerHi,
Quoted 51 lines · Antonio Quartulli
From: Antonio Quartulli <[email protected]>
Even if it is forbidden to enslave a bridge interface into another one, it is still possible to create a chain of virtual interfaces including two distinct bridges.
In this case, the skb entering the second bridge could have the
nf_bridgefield already set due to a previous operation and consequently lead to wrong a processing of the packet itself.To prevent this behaviour release and set to NULL the
nf_bridgefield of the skb when forwarding the packet.Cc Stephen Hemminger <[email protected]>Signed-off-by Antonio Quartulli <[email protected]>---
I know that not using "extern" when declaring the prototype is not consistent with the surrounding code, but checkpatch complaints about using "extern" in .h file and I prefer to not do something "wrong" even if stylistically ugly.
Cheers,
net/bridge/br_forward.c | 2 ++ net/bridge/br_netfilter.c | 10 ++++++++++ net/bridge/br_private.h | 2 ++ 3 files changed, 14 insertions(+)net/bridge/br_forward.c +2
-0@@ -49,6 +49,8 @@ int br_dev_queue_push_xmit(struct sk_buff *skb) }else {skb_push (skb,ETH_HLEN );br_drop_fake_rtable (skb); +br_netfilter_skb_free (skb); +dev_queue_xmit (skb); }net/bridge/br_netfilter.c +0
-0@@ -1086,3 +1086,13 @@ void br_netfilter_fini(void)#endif dst_entries_destroy (&fake_dst_ops); }
net/bridge/br_netfilter.c void br_netfilter_fini(void) · line 1098
Quoted 10 lines
net/bridge/br_netfilter.c +10
-0+ +/** +* br_netfilter_skb_free - clean the NF bridge data in an skb +* @skb: the skb which the data to free belongs to +*/ +void br_netfilter_skb_free (struct sk_buff *skb) +{ +nf_bridge_put (skb->nf_bridge); + skb->nf_bridge =NULL ; +}
This should be nf_reset.
Quoted 13 lines · Pablo Neira Ayuso
Hi,
net/bridge/br_netfilter.c void br_netfilter_fini(void) · line 1098
Quoted 10 lines
net/bridge/br_netfilter.c +10
-0+ +/** +* br_netfilter_skb_free - clean the NF bridge data in an skb +* @skb: the skb which the data to free belongs to +*/ +void br_netfilter_skb_free (struct sk_buff *skb) +{ +nf_bridge_put (skb->nf_bridge); + skb->nf_bridge =NULL ; +}This should be
nf_reset.
You think I should directly use nf_reset instead of this function?
I see that nf_reset() cleans up the conntrack part too: does it also become useless once the packet exits the bridge interface?
Cheers,
Signature · 1 line
Antonio Quartulli
Pablo Neira Ayuso
maintainerQuoted 15 lines · Antonio Quartulli
Quoted 13 lines · Pablo Neira Ayuso
Hi,
net/bridge/br_netfilter.c void br_netfilter_fini(void) · line 1098
Quoted 10 lines
net/bridge/br_netfilter.c +10
-0+ +/** +* br_netfilter_skb_free - clean the NF bridge data in an skb +* @skb: the skb which the data to free belongs to +*/ +void br_netfilter_skb_free (struct sk_buff *skb) +{ +nf_bridge_put (skb->nf_bridge); + skb->nf_bridge =NULL ; +}This should be
nf_reset.
Quoted 4 lines
You think I should directly use
nf_resetinstead of this function?I see that
nf_reset()cleans up the conntrack part too: does it also become useless once the packet exits the bridge interface?
The conntrack should not attached if it's forwarded to another netif, see dev_forward_skb.
But I'm not sure what scenario you're trying to handle with this change, if you could please elaborate.
Perhaps your fix is more conservative to avoid breaking strange setups that have been relying on this behaviour. I know of people deploying strange configurations using netfilter bridge.
Quoted 18 lines · Pablo Neira Ayuso
Quoted 17 lines · Antonio Quartulli
Quoted 13 lines · Pablo Neira Ayuso
Hi,
net/bridge/br_netfilter.c void br_netfilter_fini(void) · line 1098
Quoted 10 lines
net/bridge/br_netfilter.c +10
-0+ +/** +* br_netfilter_skb_free - clean the NF bridge data in an skb +* @skb: the skb which the data to free belongs to +*/ +void br_netfilter_skb_free (struct sk_buff *skb) +{ +nf_bridge_put (skb->nf_bridge); + skb->nf_bridge =NULL ; +}This should be
nf_reset.You think I should directly use
nf_resetinstead of this function?
Quoted 8 lines
Quoted 2 lines
I see that
nf_reset()cleans up the conntrack part too: does it also become useless once the packet exits the bridge interface?The conntrack should not attached if it's forwarded to another netif, see
dev_forward_skb.But I'm not sure what scenario you're trying to handle with this change, if you could please elaborate.
This is a sample scenario (nf bridge is on):
[eth0] ---> [br0] ---> [bat0] ---> [br1]
where the relation '[a] ---> [b]' means 'a is enslaved in b' (bat0 is a batman-adv virtual interface..in this situation it should not matter: it just removs an header from an incoming skb and delivers it).
The problem I was having was due to an skb entering br0 first and br1 later. When reaching br1 skb->nf_bridge was != NULL because of the previous processing in br0.
To clarify, the packet arriving on eth0 is 'delivered' to br0. It is not forwarded to another port of the bridge. Therefore I am not sure that we should clean the conntrack part too.
Quoted 5 lines
Perhaps your fix is more conservative to avoid breaking strange setups that have been relying on this behaviour. I know of people deploying strange configurations using netfilter bridge.
could be.
Cheers,
Signature · 1 line
Antonio Quartulli
Quoted 25 lines · Antonio Quartulli
Quoted 24 lines · Pablo Neira Ayuso
Quoted 15 lines · Antonio Quartulli
Quoted 13 lines · Pablo Neira Ayuso
Hi,
net/bridge/br_netfilter.c void br_netfilter_fini(void) · line 1098
Quoted 10 lines
net/bridge/br_netfilter.c +10
-0+ +/** +* br_netfilter_skb_free - clean the NF bridge data in an skb +* @skb: the skb which the data to free belongs to +*/ +void br_netfilter_skb_free (struct sk_buff *skb) +{ +nf_bridge_put (skb->nf_bridge); + skb->nf_bridge =NULL ; +}This should be
nf_reset.Quoted 4 lines
You think I should directly use
nf_resetinstead of this function?I see that
nf_reset()cleans up the conntrack part too: does it also become useless once the packet exits the bridge interface?The conntrack should not attached if it's forwarded to another netif, see
dev_forward_skb.
Quoted 8 lines
Quoted 2 lines
But I'm not sure what scenario you're trying to handle with this change, if you could please elaborate.
This is a sample scenario (nf bridge is on):
[eth0] ---> [br0] ---> [bat0] ---> [br1]
Another possible config that is out in the wild is
[eth0] ---> [br0] ---> [vlanX] ----> [br1]
Quoted 8 lines
where the relation '[a] ---> [b]' means 'a is enslaved in b' (bat0 is a batman-adv virtual interface..in this situation it should not matter: it just removs an header from an incoming skb and delivers it).
The problem I was having was due to an skb entering br0 first and br1 later. When reaching br1
skb->nf_bridgewas != NULL because of the previous processing in br0.
Doesn't br_nf_pre_routing already take care of this for you? It will drop the ref on the current nf_bridge and allocate a new one. Is that not sufficient?
-vlad
Quoted 14 lines
To clarify, the packet arriving on eth0 is 'delivered' to br0. It is not forwarded to another port of the bridge. Therefore I am not sure that we should clean the conntrack part too.
Quoted 5 lines
Perhaps your fix is more conservative to avoid breaking strange setups that have been relying on this behaviour. I know of people deploying strange configurations using netfilter bridge.
could be.
Cheers,
Quoted 4 lines · Vlad Yasevich
Quoted 3 lines · Antonio Quartulli
Quoted 2 lines · Pablo Neira Ayuso
Quoted 1 line · Antonio Quartulli
On Thu, Oct 17, 2013 at 04:28:57AM -0700, Pablo Neira Ayuso wrote:
[...]
Quoted 9 lines
Quoted 5 lines
The problem I was having was due to an skb entering br0 first and br1 later. When reaching br1
skb->nf_bridgewas != NULL because of the previous processing in br0.Doesn't
br_nf_pre_routingalready take care of this for you? It will drop the ref on the currentnf_bridgeand allocate a new one. Is that not sufficient?
In my case that line is not reached because
700 if (!IS_IP(skb) && !IS_VLAN_IP(skb) && !IS_PPPOE_IP(skb))
is always true: the packet getting analysed is a batman-adv encapsulated packet, which does not match any of the three above.
Cheers,
Signature · 1 line
Antonio Quartulli
Quoted 18 lines · Antonio Quartulli
Quoted 4 lines · Vlad Yasevich
Quoted 3 lines · Antonio Quartulli
Quoted 2 lines · Pablo Neira Ayuso
Quoted 1 line · Antonio Quartulli
On Thu, Oct 17, 2013 at 04:28:57AM -0700, Pablo Neira Ayuso wrote:
[...]
Quoted 9 lines
Quoted 5 lines
The problem I was having was due to an skb entering br0 first and br1 later. When reaching br1
skb->nf_bridgewas != NULL because of the previous processing in br0.Doesn't
br_nf_pre_routingalready take care of this for you? It will drop the ref on the currentnf_bridgeand allocate a new one. Is that not sufficient?
Quoted 9 lines
In my case that line is not reached because
700 if (!IS_IP(skb) && !IS_VLAN_IP(skb) && !IS_PPPOE_IP(skb))is always true: the packet getting analysed is a batman-adv encapsulated packet, which does not match any of the three above.
Cheers,
Looking at other encapsulators (PPP, iptunnel, VXLAN), they do nf_reset() on input. Would that be appropriate for batman as well?
-vlad
Quoted 23 lines · Vlad Yasevich
Quoted 22 lines · Antonio Quartulli
Quoted 4 lines · Vlad Yasevich
Quoted 3 lines · Antonio Quartulli
Quoted 2 lines · Pablo Neira Ayuso
Quoted 1 line · Antonio Quartulli
On Thu, Oct 17, 2013 at 04:28:57AM -0700, Pablo Neira Ayuso wrote:
[...]
Quoted 9 lines
Quoted 5 lines
The problem I was having was due to an skb entering br0 first and br1 later. When reaching br1
skb->nf_bridgewas != NULL because of the previous processing in br0.Doesn't
br_nf_pre_routingalready take care of this for you? It will drop the ref on the currentnf_bridgeand allocate a new one. Is that not sufficient?In my case that line is not reached because
700 if (!IS_IP(skb) && !IS_VLAN_IP(skb) && !IS_PPPOE_IP(skb))
Quoted 8 lines
Quoted 5 lines
is always true: the packet getting analysed is a batman-adv encapsulated packet, which does not match any of the three above.
Cheers,
Looking at other encapsulators (PPP, iptunnel, VXLAN), they do
nf_reset()on input. Would that be appropriate for batman as well?
I thought that too.
But at this point, wouldn't it be better to do a reset here and remove the other resets from any other encapsulation module?
Maybe this operation is supposed to not happen if no encapsulation is involved? I thought that polishing the nf state when exiting the nf related path was a clean and easy solution.
Moreover we avoid that any newly implemented tunneling module hit this problem again.
Cheers,
Signature · 1 line
Antonio Quartulli
Quoted 33 lines · Antonio Quartulli
Quoted 23 lines · Vlad Yasevich
Quoted 22 lines · Antonio Quartulli
Quoted 4 lines · Vlad Yasevich
Quoted 3 lines · Antonio Quartulli
Quoted 2 lines · Pablo Neira Ayuso
Quoted 1 line · Antonio Quartulli
On Thu, Oct 17, 2013 at 04:28:57AM -0700, Pablo Neira Ayuso wrote:
[...]
Quoted 9 lines
Quoted 5 lines
The problem I was having was due to an skb entering br0 first and br1 later. When reaching br1
skb->nf_bridgewas != NULL because of the previous processing in br0.Doesn't
br_nf_pre_routingalready take care of this for you? It will drop the ref on the currentnf_bridgeand allocate a new one. Is that not sufficient?In my case that line is not reached because
700 if (!IS_IP(skb) && !IS_VLAN_IP(skb) && !IS_PPPOE_IP(skb))Quoted 8 lines
Quoted 5 lines
is always true: the packet getting analysed is a batman-adv encapsulated packet, which does not match any of the three above.
Cheers,
Looking at other encapsulators (PPP, iptunnel, VXLAN), they do
nf_reset()on input. Would that be appropriate for batman as well?
Quoted 6 lines
I thought that too.
But at this point, wouldn't it be better to do a reset here and remove the other resets from any other encapsulation module?
Maybe this operation is supposed to not happen if no encapsulation is involved?
This is exactly right. The reset happens much later if there is no encapsulation. However, if there is an encapsuation that changes the hader values that are used to filter, then nf_reset has to happen. That is why nf_reset happens input to the encapsulation layer instead
of always on output from bridge.
-vlad
Quoted 8 lines
I thought that polishing the nf state when exiting the nf related path was a clean and easy solution.
Moreover we avoid that any newly implemented tunneling module hit this problem again.
Cheers,
Quoted 9 lines · Vlad Yasevich
Quoted 9 lines
Quoted 3 lines
Looking at other encapsulators (PPP, iptunnel, VXLAN), they do
nf_reset()on input. Would that be appropriate for batman as well?I thought that too.
But at this point, wouldn't it be better to do a reset here and remove the other resets from any other encapsulation module?
Quoted 7 lines
Quoted 1 line
Maybe this operation is supposed to not happen if no encapsulation is involved?
This is exactly right. The reset happens much later if there is no encapsulation. However, if there is an encapsuation that changes the hader values that are used to filter, then
nf_resethas to happen. That is whynf_resethappens input to the encapsulation layer instead of always on output from bridge.
I see.
Then I think that this patch can be dropped.
I will provide another patch to batman-adv so that it can reset the nf state before extracting the payload packet.
Thanks a lot for your feedback!
Regards,
Signature · 1 line
Antonio Quartulli