Skip to content

Fix bpf_skb_load_bytes_relative for cgroup_skb/egress

YiFei Zhu bpf 2 versions – Applied

Status from this message: Applied, thanks!

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v2 Latest2 patches 1 replyApplied
  2. v12 patches 2 repliesSuperseded

Patches in v2 Applied

#Subject and filesSizeRepliesApplied
1/2net/filter: Permit reading NET in load_bytes_relative when MAC not setnet/core/filter.c+9 -70 replies
2/2selftests/bpf: Add cgroup_skb/egress test for load_bytes_relativetools/testing/selftests/bpf/prog_tests/load_bytes_relative.c tools/testing/selftests/bpf/progs/load_bytes_relative.c+119 -00 replies

Reviews trailers per patch

All 2 patches have a Reviewed-by or Acked-by.

PatchStanislav Fomichev
1/2R-b
2/2R-b

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v2 thread

Cover letter [PATCH bpf v2 0/2] Fix bpf_skb_load_bytes_relative for cgroup_skb/egress

When cgroup_skb/egress triggers the MAC header is not set. On the other hand, load_bytes_relative unconditionally calls skb_mac_header which, when MC not set, returns a pointer after the tail pointer, breaking the logic even if the caller requested the NET header.

Fix is to conditionally use skb_mac_header or skb_network_header depending on the requested header, -EFAULT when the header is not set. Added a test that asserts during cgroup_skb/egress request for MAC header returns -EFAULT and request for NET header succeeds.

Updates since v1:
* Reverted the bound condition check to account for bad offset parameter larger than data length.
* Add test asssertion for failure return code on the condition above.

YiFei Zhu (2):
net/filter: Permit reading NET in load_bytes_relative when MAC not set selftests/bpf: Add cgroup_skb/egress test for load_bytes_relative

 net/core/filter.c                             | 16 +++--
 .../bpf/prog_tests/load_bytes_relative.c      | 71 +++++++++++++++++++
 .../selftests/bpf/progs/load_bytes_relative.c | 48 +++++++++++++
 3 files changed, 128 insertions(+), 7 deletions(-)
 create mode 100644 tools/testing/selftests/bpf/prog_tests/load_bytes_relative.c
 create mode 100644 tools/testing/selftests/bpf/progs/load_bytes_relative.c

--
2.27.0