netfilter: bridge: Don't sabotage nf_hook calls from an l3mdev
Subsystems (4)
PATCH 1/1 netfilter: bridge: Don't sabotage nf_hook calls from an l3mdev
From: David Ahern <[email protected]>
For starters, the bridge netfilter code registers operations that are invoked any time nh_hook is called. Specifically, ip_sabotage_in watches for nested calls for NF_INET_PRE_ROUTING when a bridge is in the stack.
Packet wise, the bridge netfilter hook runs first. br_nf_pre_routing allocates nf_bridge, sets in_prerouting to 1 and calls NF_HOOK for NF_INET_PRE_ROUTING. It's finish function, br_nf_pre_routing_finish, then resets in_prerouting flag to 0 and the packet continues up the stack. The packet eventually makes it to the VRF driver and it invokes nf_hook for NF_INET_PRE_ROUTING in case any rules have been added against the vrf device.
Because of the registered operations the call to nf_hook causes ip_sabotage_in to be invoked. That function sees the nf_bridge on the skb and that in_prerouting is not set. Thinking it is an invalid nested call it steals (drops) the packet.
Update ip_sabotage_in to recognize that the bridge or one of its upper devices (e.g., vlan) can be enslaved to a VRF (L3 master device) and allow the packet to go through the nf_hook a second time.
---
re-send adding netfilter
net/bridge/br_netfilter_hooks.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
net/bridge/br_netfilter_hooks.c +2 -1
@@ -835,7 +835,8 @@ static unsigned int ip_sabotage_in(void *priv, struct sk_buff *skb, const struct nf_hook_state *state) { -if (skb->nf_bridge && !skb->nf_bridge->in_prerouting) { +if (skb->nf_bridge && !skb->nf_bridge->in_prerouting && + !netif_is_l3_master (skb->dev)) { state->okfn (state->net, state->sk, skb);return NF_STOLEN ; }
Signature · 1 line
2.11.0
Quoted 15 lines · On Mon, Sep 17, 2018 at 08:20:36AM -0700, [email protected] wrote:
From: David Ahern <[email protected]>
For starters, the bridge netfilter code registers operations that are invoked any time
nh_hookis called. Specifically,ip_sabotage_inwatches for nested calls forNF_INET_PRE_ROUTINGwhen a bridge is in the stack.Packet wise, the bridge netfilter hook runs first.
br_nf_pre_routingallocatesnf_bridge, setsin_preroutingto 1 and callsNF_HOOKforNF_INET_PRE_ROUTING. It's finish function,br_nf_pre_routing_finish, then resetsin_preroutingflag to 0 and the packet continues up the stack. The packet eventually makes it to the VRF driver and it invokesnf_hookforNF_INET_PRE_ROUTINGin case any rules have been added against the vrf device.
Quoted 8 lines
Because of the registered operations the call to
nf_hookcausesip_sabotage_into be invoked. That function sees thenf_bridgeon the skb and thatin_preroutingis not set. Thinking it is an invalid nested call it steals (drops) the packet.Update
ip_sabotage_into recognize that the bridge or one of its upper devices (e.g., vlan) can be enslaved to a VRF (L3 master device) and allow the packet to go through thenf_hooka second time.
Applied.