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

From: Kumar Kartikeya Dwivedi

Date: Fri Nov 27 2026 - 21:53:33 EST


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@xxxxxxxxx/

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