Skip to content

bpf: Do not follow __iomem pointers

Kumar Kartikeya Dwivedi bpf lkml 1 version In review

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 Latest3 patches 1 replyIn review

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/3compiler_types: Emit a BTF type tag for __iomeminclude/linux/compiler_types.h+1 -10 replies
2/3bpf: Treat __iomem pointers as scalarskernel/bpf/btf.c+15 -01 reply
3/3selftests/bpf: Test loads through __iomem pointerstools/testing/selftests/bpf/prog_tests/btf_tag.c tools/testing/selftests/bpf/progs/btf_type_tag_iomem.c tools/testing/selftests/bpf/test_kmods/bpf_testmod.c+119 -00 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v1 yet.

Read the v1 thread

Cover letter [PATCH bpf-next v1 0/3] bpf: Do not follow __iomem pointers

A BPF tracing program can read a device register with a plain field walk, for example mdev->common->device_status through a
struct virtio_pci_common_cfg __iomem *. The load is a PROBE_MEM load of a mapped address, so it does not fault and reads the register. Such a read can have side effects. This came up in the discussion of [1].

Patch 1 gives __iomem a BTF type tag, as __user, __percpu and __rcu have. Patch 2 makes the verifier hand out a scalar for a struct member, function argument or return value with that tag, so a program cannot load through it. Patch 3 adds selftests.

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

Kumar Kartikeya Dwivedi (3):
compiler_types: Emit a BTF type tag for __iomem
bpf: Treat __iomem pointers as scalars selftests/bpf: Test loads through __iomem pointers

 include/linux/compiler_types.h                |  2 +-
 kernel/bpf/btf.c                              | 15 +++++
 .../selftests/bpf/prog_tests/btf_tag.c        | 55 +++++++++++++++++++
 .../selftests/bpf/progs/btf_type_tag_iomem.c  | 49 +++++++++++++++++
 .../selftests/bpf/test_kmods/bpf_testmod.c    | 15 +++++
 5 files changed, 135 insertions(+), 1 deletion(-)
 create mode 100644 tools/testing/selftests/bpf/progs/btf_type_tag_iomem.c

base-commit: 71ad211eb086d0f8fc7ae595a37943bed58cad6f

Signature · 1 line
2.53.1-Meta