netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v3 bpf 0/2] bpf: return proper error codes for lwt redirect
@ 2023-07-25  4:12 Yan Zhai
  2023-07-25  4:13 ` [PATCH v3 bpf 1/2] bpf: fix skb_do_redirect return values Yan Zhai
                   ` (2 more replies)
  0 siblings, 3 replies; 10+ messages in thread
From: Yan Zhai @ 2023-07-25  4:12 UTC (permalink / raw)
  To: bpf
  Cc: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko,
	Martin KaFai Lau, Song Liu, Yonghong Song, John Fastabend,
	KP Singh, Stanislav Fomichev, Hao Luo, Jiri Olsa, David S. Miller,
	Eric Dumazet, Jakub Kicinski, Paolo Abeni, Mykola Lysenko,
	Shuah Khan, Yan Zhai, linux-kernel, netdev, linux-kselftest,
	kernel-team, Jordan Griege

lwt xmit hook does not expect positive return values in function
ip_finish_output2 and ip6_finish_output2. However, BPF redirect programs
can return positive values such like NET_XMIT_DROP, NET_RX_DROP, and etc
as errors. Such return values can panic the kernel unexpectedly:

https://gist.github.com/zhaiyan920/8fbac245b261fe316a7ef04c9b1eba48

This patch fixes the return values from BPF redirect, so the error
handling would be consistent at xmit hook. It also adds a few test cases
to prevent future regressions.

v2: https://lore.kernel.org/netdev/ZLdY6JkWRccunvu0@debian.debian/ 
v1: https://lore.kernel.org/bpf/ZLbYdpWC8zt9EJtq@debian.debian/

changes since v2:
  * subject name changed
  * also covered redirect to ingress case
  * added selftests

changes since v1:
  * minor code style changes

Yan Zhai (2):
  bpf: fix skb_do_redirect return values
  bpf: selftests: add lwt redirect regression test cases

 net/core/filter.c                             |  12 +-
 tools/testing/selftests/bpf/Makefile          |   1 +
 .../selftests/bpf/progs/test_lwt_redirect.c   |  67 +++++++
 .../selftests/bpf/test_lwt_redirect.sh        | 165 ++++++++++++++++++
 4 files changed, 244 insertions(+), 1 deletion(-)
 create mode 100644 tools/testing/selftests/bpf/progs/test_lwt_redirect.c
 create mode 100755 tools/testing/selftests/bpf/test_lwt_redirect.sh

-- 
2.30.2


^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2023-07-25 17:07 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-07-25  4:12 [PATCH v3 bpf 0/2] bpf: return proper error codes for lwt redirect Yan Zhai
2023-07-25  4:13 ` [PATCH v3 bpf 1/2] bpf: fix skb_do_redirect return values Yan Zhai
2023-07-25  5:10   ` Markus Elfring
2023-07-25 14:40     ` Yan Zhai
2023-07-25  9:08   ` Jakub Sitnicki
2023-07-25 16:05     ` Yan Zhai
2023-07-25 17:07       ` Stanislav Fomichev
2023-07-25  4:14 ` [PATCH v3 bpf 2/2] selftests/bpf: test lwt redirect error handling Yan Zhai
2023-07-25 13:18   ` Jakub Sitnicki
2023-07-25 13:20 ` [PATCH v3 bpf 0/2] bpf: return proper error codes for lwt redirect Jakub Sitnicki

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).