Skip to content

Allow variable offsets for syscall PTR_TO_CTX

Kumar Kartikeya Dwivedi 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 Latest7 patches 1 replyApplied 7/7
  2. v47 patches 5 repliesSuperseded
  3. v33 patches 13 repliesSuperseded
Earlier versions · 2
VersionPostedPatchesRepliesStatus
v23 patches0 repliesSuperseded
v14 patches5 repliesSuperseded

Changes in v5 from the cover letter

v4: https://lore.kernel.org/bpf/[email protected]

* Use is_var_ctx_off_allowed() consistently.
* Add acks. (Emil)

Patches in v5 All 7 applied

#Subject and filesSizeRepliesApplied
1/7bpf: Support variable offsets for syscall PTR_TO_CTXkernel/bpf/verifier.c tools/testing/selftests/bpf/progs/verifier_ctx.c tools/testing/selftests/bpf/progs/verifier_global_subprogs.c+65 -400 repliesApplied
2/7bpf: Enable unaligned accesses for syscall ctxkernel/bpf/syscall.c+1 -20 repliesApplied
3/7selftests/bpf: Convert ctx tests from ASM to Ctools/testing/selftests/bpf/prog_tests/verifier.c tools/testing/selftests/bpf/progs/verifier_ctx.c+35 -450 repliesApplied
4/7selftests/bpf: Add syscall ctx variable offset teststools/testing/selftests/bpf/progs/verifier_ctx.c tools/testing/selftests/bpf/test_kmods/bpf_testmod.c+267 -60 repliesApplied
5/7selftests/bpf: Test modified syscall ctx for ARG_PTR_TO_CTXtools/testing/selftests/bpf/progs/verifier_global_subprogs.c+94 -00 repliesApplied
6/7selftests/bpf: Add tests for unaligned syscall ctx accessestools/testing/selftests/bpf/progs/verifier_ctx.c+133 -00 repliesApplied
7/7selftests/bpf: Add tests for syscall ctx accesses beyond U16_MAXtools/testing/selftests/bpf/progs/verifier_ctx.c+108 -01 replyApplied

Reviews trailers per patch

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

PatchEmil TsalapatisPuranjay MohanMykyta Yatsenko
1/7R-b A-b A-b
2/7R-b
3/7R-b
4/7R-b A-b A-b
5/7R-b A-b A-b
6/7R-b
7/7R-b

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes. Scroll the table sideways for all 3 reviewers.

Read the v5 thread

Cover letter [PATCH bpf-next v5 0/7] Allow variable offsets for syscall PTR_TO_CTX

Enable pointer modification with variable offsets accumulated in the register for PTR_TO_CTX for syscall programs where it won't be rewritten, and the context is user-supplied and checked against the max offset. See patches for details. Fixed offset support landed in [0].

By combining this set with [0], examples like the one below should succeed verification now.

SEC("syscall")

  int prog(void *ctx) {
	int *arr = ctx;
	int i;

	bpf_for(i, 0, 100)
		arr[i] *= i;

	return 0;

}

[0]: https://lore.kernel.org/bpf/[email protected]

Changelog:
----------
v4 -> v5
v4: https://lore.kernel.org/bpf/[email protected]

* Use is_var_ctx_off_allowed() consistently.
* Add acks. (Emil)

v3 -> v4
v3: https://lore.kernel.org/bpf/[email protected]

* Drop comment around describing choice of fixed or variable offsets. (Eduard)
* Simplify offset adjustment for different cases. (Eduard)
* Add PTR_TO_CTX case in __check_mem_access(). (Eduard)
* Drop aligned access constraint from syscall_prog_is_valid_access().
* Wrap naked checks for BPF_PROG_TYPE_SYSCALL in a utility function. (Eduard)
* Split tests into separate clean up and addition patches. (Eduard)
* Remove CAP_SYS_ADMIN changes. (Eduard)
* Enable unaligned access to syscall ctx, add tests.
* Add more tests for various corner cases.
* Add acks. (Puranjay, Mykyta)

v2 -> v3
v2: https://lore.kernel.org/bpf/[email protected]

* Prevent arg_type for KF_ARG_PTR_TO_CTX from applying to other cases due to preceding fallthrough. (Gemini/Sashiko)

v1 -> v2
v1: https://lore.kernel.org/bpf/[email protected]

* Harden check_func_arg_reg_off check with ARG_PTR_TO_CTX.
* Add tests for unmodified ctx into tail calls.
* Squash unmodified ctx change into base commit.
* Add Reviewed-by's from Emil.

Kumar Kartikeya Dwivedi (7):
bpf: Support variable offsets for syscall PTR_TO_CTX
bpf: Enable unaligned accesses for syscall ctx selftests/bpf: Convert ctx tests from ASM to C selftests/bpf: Add syscall ctx variable offset tests selftests/bpf: Test modified syscall ctx for ARG_PTR_TO_CTX selftests/bpf: Add tests for unaligned syscall ctx accesses selftests/bpf: Add tests for syscall ctx accesses beyond U16_MAX

 kernel/bpf/syscall.c                          |   3 +-
 kernel/bpf/verifier.c                         | 103 +--
 .../selftests/bpf/prog_tests/verifier.c       |   2 +-
 .../selftests/bpf/progs/verifier_ctx.c        | 591 ++++++++++++++++--
 .../bpf/progs/verifier_global_subprogs.c      |  95 ++-
 .../selftests/bpf/test_kmods/bpf_testmod.c    |   2 +-
 6 files changed, 703 insertions(+), 93 deletions(-)

base-commit: a1aa9ef47c299c5bbc30594d3c2f0589edf908e6

Signature · 1 line
2.52.0