Skip to content

bpf, xdp: clean adjust_{head,meta} memory when offset < 0

Jiayuan Chen bpf linux-kselftest lkml netdev 1 version In review

Get series with b4
b4 am [email protected]

Versions newest first

  1. v2 Latest2 patches 8 repliesIn review

Patches in v2 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/2bpf, xdp: clean head/meta when expanding itinclude/uapi/linux/bpf.h net/core/filter.c tools/include/uapi/linux/bpf.h+13 -66 replies
2/2selftests/bpf: add perf test for adjust_{head,meta}tools/testing/selftests/bpf/prog_tests/xdp_perf.c tools/testing/selftests/bpf/progs/xdp_dummy.c+59 -72 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v2 yet.

Read the v2 thread

Cover letter [PATCH bpf v2 0/2] bpf, xdp: clean adjust_{head,meta} memory when offset < 0

This patchset originates from my attempt to resolve a KMSAN warning that has existed for over 3 years:
https://syzkaller.appspot.com/bug?extid=0e6ddb1ef80986bdfe64

Previously, we had a brief discussion in this thread about whether we can simply perform memset in adjust_{head,meta}:
https://lore.kernel.org/netdev/[email protected]/T/#t

Unfortunately, I couldn't find a similar topic in the mail list, but I did find a similar security-related commit:
commit 6dfb970d3dbd ("xdp: avoid leaking info stored in frame data on page reuse")

I just create a new topic here and make subject more clear, we can discuss this here.

Meanwhile, I also discovered a related issue that led to a CVE,specifically the Facebook Katran vulnerability (https://vuldb.com/?id.246309).

Currently, even with unprivileged functionality disabled, a user can load a BPF program using CAP_BPF and CAP_NET_ADMIN, which I believe we should avoid exposing kernel memory directly to users now.

Regarding performance considerations, I added corresponding results to the selftest, testing common MAC headers and IP headers of various sizes.

Compared to not using memset, the execution time increased by 2ns, but I think this is negligible considering the entire net stack.

Jiayuan Chen (2):
bpf, xdp: clean head/meta when expanding it selftests/bpf: add perf test for adjust_{head,meta}

 include/uapi/linux/bpf.h                      |  8 +--
 net/core/filter.c                             |  5 +-
 tools/include/uapi/linux/bpf.h                |  6 ++-
 .../selftests/bpf/prog_tests/xdp_perf.c       | 52 ++++++++++++++++---
 tools/testing/selftests/bpf/progs/xdp_dummy.c | 14 +++++
 5 files changed, 72 insertions(+), 13 deletions(-)
Signature · 1 line
2.47.1