Skip to content

bpf: Fix trampoline handling of 128-bit values

Yonghong Song bpf 5 versions – Applied

Status from this message: This series was applied to bpf/bpf-next.git (master)

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v5 Latest3 patches 1 replyApplied 3/3
  2. v43 patches 2 repliesSuperseded
  3. v33 patches 3 repliesSuperseded
Earlier versions · 2
VersionPostedPatchesRepliesStatus
v23 patches1 replySuperseded
v12 patches6 repliesSuperseded

Changes in v5 from the cover letter

- v4: https://lore.kernel.org/bpf/[email protected]/
- For function test_fexit_int128_ret(), guard with __x86_64__ and __aarch64__ to avoid s390x failure

Patches in v5 All 3 applied

#Subject and filesSizeRepliesApplied
1/3bpf: Reject >8 byte return values on return-reading trampoline pathskernel/bpf/bpf_struct_ops.c kernel/bpf/verifier.c+37 -00 repliesApplied
2/3bpf, x86: Fix trampoline stack size for 128-bit argumentsarch/x86/net/bpf_jit_comp.c+2 -51 replyApplied
3/3selftests/bpf: Add tests for >8 byte return value and 128-bit argumentstools/testing/selftests/bpf/prog_tests/tracing_failure.c tools/testing/selftests/bpf/prog_tests/tracing_struct.c tools/testing/selftests/bpf/progs/tracing_failure.c +2 more+112 -00 repliesApplied

Reviews trailers per patch

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

PatchLeon HwangEduard Zingerman
1/3A-b R-b
2/3A-b
3/3A-b

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

Read the v5 thread

Cover letter [PATCH bpf-next v5 0/3] bpf: Fix trampoline handling of 128-bit values

The BPF trampoline preserves only 8 bytes of a target function's return value (R0), and its register save area under-allocates space for 128-bit arguments for x86_64. These two problems lead to memory corruption or incorrect values observed by BPF programs and the real caller.

This series fixes both issues and adds two selftests, otherwise, each of them will fail if without the corresponding fix.

Changelogs:
v4 -> v5:
- v4: https://lore.kernel.org/bpf/[email protected]/
- For function test_fexit_int128_ret(), guard with __x86_64__ and __aarch64__ to avoid s390x failure
v3 -> v4:
- v3: https://lore.kernel.org/bpf/[email protected]/
- Add Ack from Leon Hwang
v2 -> v3:
- v2: https://lore.kernel.org/bpf/[email protected]/
- Align __int128 argument at even position enforced by arm64.
v1 -> v2:
- v1: https://lore.kernel.org/bpf/[email protected]/
- Also handle __int128 arguments for x86_64.

Yonghong Song (3):
bpf: Reject >8 byte return values on return-reading trampoline paths bpf, x86: Fix trampoline stack size for 128-bit arguments selftests/bpf: Add tests for >8 byte return value and 128-bit
arguments

 arch/x86/net/bpf_jit_comp.c                   |  7 ++--
 kernel/bpf/bpf_struct_ops.c                   | 12 +++++++
 kernel/bpf/verifier.c                         | 25 +++++++++++++
 .../bpf/prog_tests/tracing_failure.c          | 20 +++++++++++
 .../selftests/bpf/prog_tests/tracing_struct.c | 36 +++++++++++++++++++
 .../selftests/bpf/progs/tracing_failure.c     |  6 ++++
 .../bpf/progs/tracing_struct_int128.c         | 18 ++++++++++
 .../selftests/bpf/test_kmods/bpf_testmod.c    | 32 +++++++++++++++++
 8 files changed, 151 insertions(+), 5 deletions(-)
 create mode 100644 tools/testing/selftests/bpf/progs/tracing_struct_int128.c
Signature · 1 line
2.53.0-Meta