* [PATCH net-next] netfilter: bridge: reset skb->pkt_type after NF_INET_POST_ROUTING traversal
@ 2020-11-23 17:49 Antoine Tenart
2020-11-23 18:32 ` Florian Westphal
0 siblings, 1 reply; 5+ messages in thread
From: Antoine Tenart @ 2020-11-23 17:49 UTC (permalink / raw)
To: kuba, pablo, kadlec, fw, roopa, nikolay
Cc: Antoine Tenart, netdev, netfilter-devel, coreteam, sbrivio
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.
Signed-off-by: Antoine Tenart <atenart@kernel.org>
---
net/bridge/br_netfilter_hooks.c | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/net/bridge/br_netfilter_hooks.c b/net/bridge/br_netfilter_hooks.c
index 04c3f9a82650..8edfb98ae1d5 100644
--- a/net/bridge/br_netfilter_hooks.c
+++ b/net/bridge/br_netfilter_hooks.c
@@ -735,6 +735,11 @@ static int br_nf_dev_queue_xmit(struct net *net, struct sock *sk, struct sk_buff
mtu_reserved = nf_bridge_mtu_reduction(skb);
mtu = skb->dev->mtu;
+ if (nf_bridge->pkt_otherhost) {
+ skb->pkt_type = PACKET_OTHERHOST;
+ nf_bridge->pkt_otherhost = false;
+ }
+
if (nf_bridge->frag_max_size && nf_bridge->frag_max_size < mtu)
mtu = nf_bridge->frag_max_size;
@@ -835,8 +840,6 @@ static unsigned int br_nf_post_routing(void *priv,
else
return NF_ACCEPT;
- /* We assume any code from br_dev_queue_push_xmit onwards doesn't care
- * about the value of skb->pkt_type. */
if (skb->pkt_type == PACKET_OTHERHOST) {
skb->pkt_type = PACKET_HOST;
nf_bridge->pkt_otherhost = true;
--
2.28.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH net-next] netfilter: bridge: reset skb->pkt_type after NF_INET_POST_ROUTING traversal
2020-11-23 17:49 [PATCH net-next] netfilter: bridge: reset skb->pkt_type after NF_INET_POST_ROUTING traversal Antoine Tenart
@ 2020-11-23 18:32 ` Florian Westphal
2020-11-28 0:06 ` Jakub Kicinski
0 siblings, 1 reply; 5+ messages in thread
From: Florian Westphal @ 2020-11-23 18:32 UTC (permalink / raw)
To: Antoine Tenart
Cc: kuba, pablo, kadlec, fw, roopa, nikolay, netdev, netfilter-devel,
coreteam, sbrivio
Antoine Tenart <atenart@kernel.org> wrote:
> 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:
> 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.
That comment is 18 years old, safe bet noone thought of
ipv6-in-tunnel-interface-added-as-bridge-port back then.
Reviewed-by: Florian Westphal <fw@strlen.de>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH net-next] netfilter: bridge: reset skb->pkt_type after NF_INET_POST_ROUTING traversal
2020-11-23 18:32 ` Florian Westphal
@ 2020-11-28 0:06 ` Jakub Kicinski
2020-11-28 9:59 ` Florian Westphal
0 siblings, 1 reply; 5+ messages in thread
From: Jakub Kicinski @ 2020-11-28 0:06 UTC (permalink / raw)
To: Florian Westphal
Cc: Antoine Tenart, pablo, kadlec, roopa, nikolay, netdev,
netfilter-devel, coreteam, sbrivio
On Mon, 23 Nov 2020 19:32:53 +0100 Florian Westphal wrote:
> Antoine Tenart <atenart@kernel.org> wrote:
> > 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:
>
> > 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.
>
> That comment is 18 years old, safe bet noone thought of
> ipv6-in-tunnel-interface-added-as-bridge-port back then.
>
> Reviewed-by: Florian Westphal <fw@strlen.de>
Sounds like a fix. Probably hard to pin point which commit to blame,
but this should go to net, not net-next, right?
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH net-next] netfilter: bridge: reset skb->pkt_type after NF_INET_POST_ROUTING traversal
2020-11-28 0:06 ` Jakub Kicinski
@ 2020-11-28 9:59 ` Florian Westphal
2020-11-28 19:49 ` Jakub Kicinski
0 siblings, 1 reply; 5+ messages in thread
From: Florian Westphal @ 2020-11-28 9:59 UTC (permalink / raw)
To: Jakub Kicinski
Cc: Florian Westphal, Antoine Tenart, pablo, kadlec, roopa, nikolay,
netdev, netfilter-devel, coreteam, sbrivio
Jakub Kicinski <kuba@kernel.org> wrote:
> On Mon, 23 Nov 2020 19:32:53 +0100 Florian Westphal wrote:
> > That comment is 18 years old, safe bet noone thought of
> > ipv6-in-tunnel-interface-added-as-bridge-port back then.
> >
> > Reviewed-by: Florian Westphal <fw@strlen.de>
>
> Sounds like a fix. Probably hard to pin point which commit to blame,
> but this should go to net, not net-next, right?
The commit predates git history, so probably a good idea to add
Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
... and apply it to net tree.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH net-next] netfilter: bridge: reset skb->pkt_type after NF_INET_POST_ROUTING traversal
2020-11-28 9:59 ` Florian Westphal
@ 2020-11-28 19:49 ` Jakub Kicinski
0 siblings, 0 replies; 5+ messages in thread
From: Jakub Kicinski @ 2020-11-28 19:49 UTC (permalink / raw)
To: Florian Westphal
Cc: Antoine Tenart, pablo, kadlec, roopa, nikolay, netdev,
netfilter-devel, coreteam, sbrivio
On Sat, 28 Nov 2020 10:59:29 +0100 Florian Westphal wrote:
> Jakub Kicinski <kuba@kernel.org> wrote:
> > On Mon, 23 Nov 2020 19:32:53 +0100 Florian Westphal wrote:
> > > That comment is 18 years old, safe bet noone thought of
> > > ipv6-in-tunnel-interface-added-as-bridge-port back then.
> > >
> > > Reviewed-by: Florian Westphal <fw@strlen.de>
> >
> > Sounds like a fix. Probably hard to pin point which commit to blame,
> > but this should go to net, not net-next, right?
>
> The commit predates git history, so probably a good idea to add
> Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
>
> ... and apply it to net tree.
Done, thanks!
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2020-11-28 22:17 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-23 17:49 [PATCH net-next] netfilter: bridge: reset skb->pkt_type after NF_INET_POST_ROUTING traversal Antoine Tenart
2020-11-23 18:32 ` Florian Westphal
2020-11-28 0:06 ` Jakub Kicinski
2020-11-28 9:59 ` Florian Westphal
2020-11-28 19:49 ` Jakub Kicinski
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.