Skip to content

bpf: Disallow BPF_F_LOCK with mixed special fields

Leon Hwang bpf linux-kselftest lkml 2 versions – In review

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v2 Latest2 patches 3 repliesIn review
  2. v12 patches 1 replySuperseded

Changes in v2 from the cover letter

* Reject any unknown flag bits in map_flags when updating maps (per AI review).
* v1: https://lore.kernel.org/bpf/[email protected]/

Patches in v2 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/2bpf: Disallow BPF_F_LOCK with mixed special fields and centralize flag checksinclude/linux/bpf.h kernel/bpf/arraymap.c kernel/bpf/bpf_local_storage.c +3 more+17 -233 replies
2/2selftests/bpf: Add tests to verify BPF_F_LOCK restrictionstools/testing/selftests/bpf/prog_tests/map_lock.c tools/testing/selftests/bpf/progs/test_map_lock.c+100 -10 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-next v2 0/2] bpf: Disallow BPF_F_LOCK with mixed special fields

Disallow combining BPF_F_LOCK with map values that mix bpf_spin_lock and other special BTF fields, which may lead to undefined behavior. Such cases are now rejected with -EOPNOTSUPP.

Map update flag validation is centralized in bpf_map_check_op_flags() and reused across array, hash, local-storage, and task-storage update paths, with selftests added to verify the new behavior.

Changes:
v1 -> v2:
* Reject any unknown flag bits in map_flags when updating maps (per AI review).
* v1: https://lore.kernel.org/bpf/[email protected]/

Leon Hwang (2):
bpf: Disallow BPF_F_LOCK with mixed special fields and centralize flag
checks
selftests/bpf: Add tests to verify BPF_F_LOCK restrictions

 include/linux/bpf.h                           |  7 ++
 kernel/bpf/arraymap.c                         | 11 ++-
 kernel/bpf/bpf_local_storage.c                |  7 --
 kernel/bpf/bpf_task_storage.c                 |  3 -
 kernel/bpf/hashtab.c                          |  8 +--
 kernel/bpf/syscall.c                          |  4 +-
 .../selftests/bpf/prog_tests/map_lock.c       | 70 +++++++++++++++++++
 .../selftests/bpf/progs/test_map_lock.c       | 31 +++++++-
 8 files changed, 117 insertions(+), 24 deletions(-)

--
2.52.0