Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

netfilter: bridge: reset skb->pkt_type after NF_INET_POST_ROUTING traversal

Netfilter changes PACKET_OTHERHOST to PACKET_HOST before invoking the
hooks as, while it's an expected value for a bridge, routing expects
PACKET_HOST. The change is undone later on after hook traversal. This
can be seen with pairs of functions updating skb>pkt_type and then
reverting it to its original value:

For hook NF_INET_PRE_ROUTING:
setup_pre_routing / br_nf_pre_routing_finish

For hook NF_INET_FORWARD:
br_nf_forward_ip / br_nf_forward_finish

But the third case where netfilter does this, for hook
NF_INET_POST_ROUTING, the packet type is changed in br_nf_post_routing
but never reverted. A comment says:

/* We assume any code from br_dev_queue_push_xmit onwards doesn't care
* about the value of skb->pkt_type. */

But when having a tunnel (say vxlan) attached to a bridge we have the
following call trace:

br_nf_pre_routing
br_nf_pre_routing_ipv6
br_nf_pre_routing_finish
br_nf_forward_ip
br_nf_forward_finish
br_nf_post_routing <- pkt_type is updated to PACKET_HOST
br_nf_dev_queue_xmit <- but not reverted to its original value
vxlan_xmit
vxlan_xmit_one
skb_tunnel_check_pmtu <- a check on pkt_type is performed

In this specific case, this creates issues such as when an ICMPv6 PTB
should be sent back. When CONFIG_BRIDGE_NETFILTER is enabled, the PTB
isn't sent (as skb_tunnel_check_pmtu checks if pkt_type is PACKET_HOST
and returns early).

If the comment is right and no one cares about the value of
skb->pkt_type after br_dev_queue_push_xmit (which isn't true), resetting
it to its original value should be safe.

Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
Signed-off-by: Antoine Tenart <atenart@kernel.org>
Reviewed-by: Florian Westphal <fw@strlen.de>
Link: https://lore.kernel.org/r/20201123174902.622102-1-atenart@kernel.org
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

authored by

Antoine Tenart and committed by
Jakub Kicinski
44f64f23 c84e1efa

+5 -2
+5 -2
net/bridge/br_netfilter_hooks.c
··· 735 735 mtu_reserved = nf_bridge_mtu_reduction(skb); 736 736 mtu = skb->dev->mtu; 737 737 738 + if (nf_bridge->pkt_otherhost) { 739 + skb->pkt_type = PACKET_OTHERHOST; 740 + nf_bridge->pkt_otherhost = false; 741 + } 742 + 738 743 if (nf_bridge->frag_max_size && nf_bridge->frag_max_size < mtu) 739 744 mtu = nf_bridge->frag_max_size; 740 745 ··· 840 835 else 841 836 return NF_ACCEPT; 842 837 843 - /* We assume any code from br_dev_queue_push_xmit onwards doesn't care 844 - * about the value of skb->pkt_type. */ 845 838 if (skb->pkt_type == PACKET_OTHERHOST) { 846 839 skb->pkt_type = PACKET_HOST; 847 840 nf_bridge->pkt_otherhost = true;