BPF List
 help / color / mirror / Atom feed
* [PATCH bpf-next v1 0/3] bpf: Do not follow __iomem pointers
@ 2026-11-28  2:53 Kumar Kartikeya Dwivedi
  2026-11-28  2:53 ` [PATCH bpf-next v1 1/3] compiler_types: Emit a BTF type tag for __iomem Kumar Kartikeya Dwivedi
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Kumar Kartikeya Dwivedi @ 2026-11-28  2:53 UTC (permalink / raw)
  To: bpf
  Cc: Alexei Starovoitov, Andrii Nakryiko, Daniel Borkmann,
	Eduard Zingerman, Emil Tsalapatis, Ihor Solodrai, kkd,
	kernel-team, Dave Hansen, Andy Lutomirski, Peter Zijlstra,
	Thomas Gleixner, Ingo Molnar, Borislav Petkov, Puranjay Mohan,
	x86, linux-kernel

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/DN6GS9V7A3HS.1COD0JUQQDHQ@gmail.com/

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
-- 
2.53.1-Meta


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-11-28  2:53 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-28  2:53 [PATCH bpf-next v1 0/3] bpf: Do not follow __iomem pointers Kumar Kartikeya Dwivedi
2026-11-28  2:53 ` [PATCH bpf-next v1 1/3] compiler_types: Emit a BTF type tag for __iomem Kumar Kartikeya Dwivedi
2026-11-28  2:53 ` [PATCH bpf-next v1 2/3] bpf: Treat __iomem pointers as scalars Kumar Kartikeya Dwivedi
2026-11-28  2:53 ` [PATCH bpf-next v1 3/3] selftests/bpf: Test loads through __iomem pointers Kumar Kartikeya Dwivedi

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox