diff options
| author | Maxim Skokov <skokovmaksimevg@gmail.com> | 2026-10-09 20:47:47 +0300 |
|---|---|---|
| committer | Alexei Starovoitov <ast@kernel.org> | 2026-10-10 15:01:15 +0000 |
| commit | 36edb1c7738dade8ed83ec4e0aef000e538b2095 (patch) | |
| tree | 6adb4399407799638c914e51a0d44e15fc1497b0 /include/linux/start_kernel.h | |
| parent | 15b578b1715d9a318c804350d98af87c203672bc (diff) | |
| download | linux-next-36edb1c7738dade8ed83ec4e0aef000e538b2095.tar.gz linux-next-36edb1c7738dade8ed83ec4e0aef000e538b2095.zip | |
bpf: test_run: Fix false -EBADMSG after skb leaves CHECKSUM_COMPLETE
With BPF_F_TEST_SKB_CHECKSUM_COMPLETE, bpf_prog_test_run_skb() computes
skb->csum over the packet from the network header to the end and marks
the skb CHECKSUM_COMPLETE. After the program has run, it recomputes the
checksum and returns -EBADMSG if it does not match skb->csum.
bpf_skb_change_tail() resizes the skb with __skb_trim_rcsum() and
__skb_grow_rcsum(), which move a CHECKSUM_COMPLETE skb to CHECKSUM_NONE
and leave skb->csum as it is. The post-run check still compares against
that stale value, so a correct program fails with -EBADMSG. After a
trim, skb->csum still covers the removed bytes. After a grow, later
writes cannot update skb->csum, even with BPF_F_RECOMPUTE_CSUM, because
skb->csum is only adjusted for CHECKSUM_COMPLETE skbs.
skb->csum only holds the packet checksum while ip_summed is
CHECKSUM_COMPLETE. With CHECKSUM_NONE the stack does not rely on it and
validates the packet in software, so there is nothing to compare. Only
do the check if the skb is still CHECKSUM_COMPLETE after the run. A
program that keeps the skb CHECKSUM_COMPLETE but leaves skb->csum stale
still gets -EBADMSG.
Dropping the checksum offload is documented behaviour of
bpf_skb_change_tail() ("implicitly linearizes, unclones and drops
offloads"), and the stack does the same in other places, for example
skb_forward_csum(). The test harness has to accept CHECKSUM_NONE either
way, whether or not the helper is later taught to keep
CHECKSUM_COMPLETE.
Fixes: a3cfe84cca28 ("bpf: Add CHECKSUM_COMPLETE to bpf test progs")
Signed-off-by: Maxim Skokov <skokovmaksimevg@gmail.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Link: https://patch.msgid.link/20261009174755.22026-2-skokovmaksimevg@gmail.com
Diffstat (limited to 'include/linux/start_kernel.h')
0 files changed, 0 insertions, 0 deletions
