NIC card driver does not set `xdp->frame_sz` properly in `bpf_xdp_adjust_tail`

Open
#4,948 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
35/100
Issue type
Bug
Clarity
Needs clarification
Activity status
Stale
Tech stack
c, linux
Domain
networking

Research direction

Start with the bpf_xdp_adjust_tail check in net/core/filter.c and trace which NIC driver supplies the xdp_buff. Reproduce the failure with the described XDP program and inspect whether the driver updates xdp->frame_sz. Done means shrinking the frame no longer returns -EINVAL on the Raspberry Pi interface and the relevant behavior is covered by a regression test.

Written by the indexing model from the issue text.

Description

Describe the bug

Calling bpf_xdp_adjust_tail in XDP always fails with -EINVAL, even when shrinking the frame, because xdp->frame_sz > PAGE_SIZE returns false since xdp->frame_sz is over 30000 but PAGE_SIZE is 4096.

Steps to reproduce the behaviour
  • Write a XDP program to call bpf_xdp_adjust_tail in it, log the return value
  • Modify the kernel to printk in bpf_xdp_adjust_tail to track which check fails
  • Compile the XDP program to eBPF executable and load it to a network interface
  • Send some network traffic on the interface
  • cat /sys/kernel/debug/tracing/trace_pipe to get log from XDP program, which tells bpf_xdp_adjust_tail failed with -22 = -EINVAL
  • dmesg to get log from kernel, which tells xdp->frame_sz > PAGE_SIZE returns false and causes the failure
Device (s)

Raspberry Pi 3 Mod. B+

System
  • Which OS and version (cat /etc/rpi-issue)?

Raspberry Pi OS (64-bit)

Raspberry Pi reference 2022-01-28
Generated using pi-gen, https://github.com/RPi-Distro/pi-gen, fbe448ccdc995d295d24c7596e5f0ef62cc2488f, stage2
  • Which firmware version (vcgencmd version)?
Jan 20 2022 13:58:22 
Copyright (c) 2012 Broadcom
version bd88f66f8952d34e4e0613a85c7a6d3da49e13e2 (clean) (release) (start)
  • Which kernel version (uname -a)?

Self built on recent latest commit

Linux pi 5.15.28-v8+ #6 SMP PREEMPT Thu Mar 17 18:20:21 CST 2022 aarch64 GNU/Linux
Logs

No response

Additional context

According to the description from the author:

The idea is to catch drivers that forgot to update xdp_buff->frame_sz,
by doing some sanity checks on this uninit value. If I correctly
updated all XDP drivers in this patchset, then these checks should be
unnecessary, but will this be valuable for driver developers converting
new drivers to XDP to have these WARN checks?

So it should be the problem of the NIC card driver

I am not sure whether XDP is considered supported in Raspberry Pi, but since the feature is enabled:

modprobe configs
zgrep -E "(BPF|XDP)" /proc/config.gz
CONFIG_BPF=y
CONFIG_HAVE_EBPF_JIT=y
CONFIG_ARCH_WANT_DEFAULT_BPF_JIT=y
# BPF subsystem
CONFIG_BPF_SYSCALL=y
# CONFIG_BPF_JIT is not set
# CONFIG_BPF_UNPRIV_DEFAULT_OFF is not set
# CONFIG_BPF_PRELOAD is not set
# end of BPF subsystem
CONFIG_CGROUP_BPF=y
# CONFIG_XDP_SOCKETS is not set
CONFIG_NETFILTER_XT_MATCH_BPF=m
# CONFIG_BPFILTER is not set
# CONFIG_NET_CLS_BPF is not set
# CONFIG_NET_ACT_BPF is not set
# CONFIG_BPF_STREAM_PARSER is not set
CONFIG_LWTUNNEL_BPF=y
CONFIG_BPF_LIRC_MODE2=y
CONFIG_BPF_EVENTS=y
# CONFIG_BPF_KPROBE_OVERRIDE is not set
# CONFIG_TEST_BPF is not set

and other simple things just work, the failure of bpf_xdp_adjust_tail should be unexpected

Dominant language
C
Stars
13.2k
Forks
5.5k
Avg merge
2d 21h
Merged PRs (30d)
21

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from raspberrypi/linux

All issues in raspberrypi/linux

Similar issues

More C issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.