Skip to content

Commit 29b22ba

Browse files
yanzhai-cfborkmann
authored andcommitted
lwt: Fix return values of BPF xmit ops
BPF encap ops can return different types of positive values, such like NET_RX_DROP, NET_XMIT_CN, NETDEV_TX_BUSY, and so on, from function skb_do_redirect and bpf_lwt_xmit_reroute. At the xmit hook, such return values would be treated implicitly as LWTUNNEL_XMIT_CONTINUE in ip(6)_finish_output2. When this happens, skbs that have been freed would continue to the neighbor subsystem, causing use-after-free bug and kernel crashes. To fix the incorrect behavior, skb_do_redirect return values can be simply discarded, the same as tc-egress behavior. On the other hand, bpf_lwt_xmit_reroute returns useful errors to local senders, e.g. PMTU information. Thus convert its return values to avoid the conflict with LWTUNNEL_XMIT_CONTINUE. Fixes: 3a0af8f ("bpf: BPF for lightweight tunnel infrastructure") Reported-by: Jordan Griege <jgriege@cloudflare.com> Suggested-by: Martin KaFai Lau <martin.lau@linux.dev> Suggested-by: Stanislav Fomichev <sdf@google.com> Signed-off-by: Yan Zhai <yan@cloudflare.com> Signed-off-by: Daniel Borkmann <daniel@iogearbox.net> Link: https://lore.kernel.org/bpf/0d2b878186cfe215fec6b45769c1cd0591d3628d.1692326837.git.yan@cloudflare.com
1 parent 5f6395f commit 29b22ba

1 file changed

Lines changed: 3 additions & 4 deletions

File tree

net/core/lwt_bpf.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,8 @@ static int run_lwt_bpf(struct sk_buff *skb, struct bpf_lwt_prog *lwt,
6060
ret = BPF_OK;
6161
} else {
6262
skb_reset_mac_header(skb);
63-
ret = skb_do_redirect(skb);
64-
if (ret == 0)
65-
ret = BPF_REDIRECT;
63+
skb_do_redirect(skb);
64+
ret = BPF_REDIRECT;
6665
}
6766
break;
6867

@@ -255,7 +254,7 @@ static int bpf_lwt_xmit_reroute(struct sk_buff *skb)
255254

256255
err = dst_output(dev_net(skb_dst(skb)->dev), skb->sk, skb);
257256
if (unlikely(err))
258-
return err;
257+
return net_xmit_errno(err);
259258

260259
/* ip[6]_finish_output2 understand LWTUNNEL_XMIT_DONE */
261260
return LWTUNNEL_XMIT_DONE;

0 commit comments

Comments
 (0)