Skip to content

Commit

Permalink
lwt: Check LWTUNNEL_XMIT_CONTINUE strictly
Browse files Browse the repository at this point in the history
[ Upstream commit a171fbe ]

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
Signed-off-by: Sasha Levin <sashal@kernel.org>
  • Loading branch information
Yan Zhai authored and gregkh committed Sep 13, 2023
1 parent 065d5f1 commit a485a4b
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
5 changes: 4 additions & 1 deletion include/net/lwtunnel.h
Expand Up @@ -16,9 +16,12 @@
#define LWTUNNEL_STATE_INPUT_REDIRECT BIT(1)
#define LWTUNNEL_STATE_XMIT_REDIRECT BIT(2)

/* LWTUNNEL_XMIT_CONTINUE should be distinguishable from dst_output return
* values (NET_XMIT_xxx and NETDEV_TX_xxx in linux/netdevice.h) for safety.
*/
enum {
LWTUNNEL_XMIT_DONE,
LWTUNNEL_XMIT_CONTINUE,
LWTUNNEL_XMIT_CONTINUE = 0x100,
};


Expand Down
2 changes: 1 addition & 1 deletion net/ipv4/ip_output.c
Expand Up @@ -214,7 +214,7 @@ static int ip_finish_output2(struct net *net, struct sock *sk, struct sk_buff *s
if (lwtunnel_xmit_redirect(dst->lwtstate)) {
int res = lwtunnel_xmit(skb);

if (res < 0 || res == LWTUNNEL_XMIT_DONE)
if (res != LWTUNNEL_XMIT_CONTINUE)
return res;
}

Expand Down
2 changes: 1 addition & 1 deletion net/ipv6/ip6_output.c
Expand Up @@ -112,7 +112,7 @@ static int ip6_finish_output2(struct net *net, struct sock *sk, struct sk_buff *
if (lwtunnel_xmit_redirect(dst->lwtstate)) {
int res = lwtunnel_xmit(skb);

if (res < 0 || res == LWTUNNEL_XMIT_DONE)
if (res != LWTUNNEL_XMIT_CONTINUE)
return res;
}

Expand Down

0 comments on commit a485a4b

Please sign in to comment.