Re: [PATCH bpf-next v1 2/3] bpf: Treat __iomem pointers as scalars

From: Andy Lutomirski

Date: Mon Nov 30 2026 - 20:52:03 EST




On Fri, Nov 27, 2026, at 6:53 PM, Kumar Kartikeya Dwivedi wrote:
> A BPF program can read a device register with a plain field walk. Given
>
> struct virtio_pci_modern_device {
> struct virtio_pci_common_cfg __iomem *common;
> void __iomem *device;
> ...
> u8 __iomem *isr;
>
> all of mdev->common->device_status, *mdev->isr and
> *(u8 *)(mdev->device + 4) load today. The verifier turns the first pointer
> into a pointer to the struct and the other two into untrusted memory, and
> each load becomes a PROBE_MEM load. The address is mapped, so the load does
> not fault and reads the register. Such a read can have side effects: the
> virtio ISR above is cleared by reading it.
>
> These pointers now have the "iomem" BTF type tag. When a struct member, a
> function argument or a return value has it, give the program a scalar. A
> scalar cannot be followed, so the three loads above are rejected with
> "R1 invalid mem access 'scalar'". The value of the pointer can still be
> read.
>
> Programs that load through such a pointer today stop loading.

This looks entirely reasonable, with the caveat that it should reject a reasonably large class of problematic programs but does not reject *all* problematic programs. I don't think it can be the basis of a sound static is-a-pointer-in-bounds verification.

--Andy