Skip to content

Commit a171fbe

Browse files
yanzhai-cfborkmann
authored andcommitted
lwt: Check LWTUNNEL_XMIT_CONTINUE strictly
LWTUNNEL_XMIT_CONTINUE is implicitly assumed in ip(6)_finish_output2, such that any positive return value from a xmit hook could cause unexpected continue behavior, despite that related skb may have been freed. This could be error-prone for future xmit hook ops. One of the possible errors is to return statuses of dst_output directly. To make the code safer, redefine LWTUNNEL_XMIT_CONTINUE value to distinguish from dst_output statuses and check the continue condition explicitly. Fixes: 3a0af8f ("bpf: BPF for lightweight tunnel infrastructure") Suggested-by: Dan Carpenter <dan.carpenter@linaro.org> Signed-off-by: Yan Zhai <yan@cloudflare.com> Signed-off-by: Daniel Borkmann <daniel@iogearbox.net> Link: https://lore.kernel.org/bpf/96b939b85eda00e8df4f7c080f770970a4c5f698.1692326837.git.yan@cloudflare.com
1 parent 29b22ba commit a171fbe

3 files changed

Lines changed: 6 additions & 3 deletions

File tree

include/net/lwtunnel.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,12 @@
1616
#define LWTUNNEL_STATE_INPUT_REDIRECT BIT(1)
1717
#define LWTUNNEL_STATE_XMIT_REDIRECT BIT(2)
1818

19+
/* LWTUNNEL_XMIT_CONTINUE should be distinguishable from dst_output return
20+
* values (NET_XMIT_xxx and NETDEV_TX_xxx in linux/netdevice.h) for safety.
21+
*/
1922
enum {
2023
LWTUNNEL_XMIT_DONE,
21-
LWTUNNEL_XMIT_CONTINUE,
24+
LWTUNNEL_XMIT_CONTINUE = 0x100,
2225
};
2326

2427

net/ipv4/ip_output.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ static int ip_finish_output2(struct net *net, struct sock *sk, struct sk_buff *s
216216
if (lwtunnel_xmit_redirect(dst->lwtstate)) {
217217
int res = lwtunnel_xmit(skb);
218218

219-
if (res < 0 || res == LWTUNNEL_XMIT_DONE)
219+
if (res != LWTUNNEL_XMIT_CONTINUE)
220220
return res;
221221
}
222222

net/ipv6/ip6_output.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ static int ip6_finish_output2(struct net *net, struct sock *sk, struct sk_buff *
113113
if (lwtunnel_xmit_redirect(dst->lwtstate)) {
114114
int res = lwtunnel_xmit(skb);
115115

116-
if (res < 0 || res == LWTUNNEL_XMIT_DONE)
116+
if (res != LWTUNNEL_XMIT_CONTINUE)
117117
return res;
118118
}
119119

0 commit comments

Comments
 (0)