mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Andy Lutomirski" <luto@kernel.org>
To: "Kumar Kartikeya Dwivedi" <memxor@gmail.com>, bpf@vger.kernel.org
Cc: "Alexei Starovoitov" <ast@kernel.org>,
	"Andrii Nakryiko" <andrii@kernel.org>,
	"Daniel Borkmann" <daniel@iogearbox.net>,
	"Eduard Zingerman" <eddyz87@gmail.com>,
	"Emil Tsalapatis" <emil@etsalapatis.com>,
	"Ihor Solodrai" <ihor.solodrai@linux.dev>,
	kkd@meta.com, kernel-team@meta.com,
	"Dave Hansen" <dave.hansen@linux.intel.com>,
	"Peter Zijlstra (Intel)" <peterz@infradead.org>,
	"Thomas Gleixner" <tglx@kernel.org>,
	"Ingo Molnar" <mingo@redhat.com>,
	"Borislav Petkov" <bp@alien8.de>,
	"Puranjay Mohan" <puranjay@kernel.org>,
	"the arch/x86 maintainers" <x86@kernel.org>,
	"Linux Kernel Mailing List" <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH bpf-next v1 2/3] bpf: Treat __iomem pointers as scalars
Date: Mon, 30 Nov 2026 17:51:38 -0800	[thread overview]
Message-ID: <a8747fad-07ba-47a5-8ae2-98a51b6c5a53@app.fastmail.com> (raw)
In-Reply-To: <52249df7401e63679e1ec5c416ef9b12d3ad318c.1795834380.git.memxor@gmail.com>



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

  reply	other threads:[~2026-12-01  1:52 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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-12-01  1:51   ` Andy Lutomirski [this message]
2026-11-28  2:53 ` [PATCH bpf-next v1 3/3] selftests/bpf: Test loads through __iomem pointers Kumar Kartikeya Dwivedi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=a8747fad-07ba-47a5-8ae2-98a51b6c5a53@app.fastmail.com \
    --to=luto@kernel.org \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bp@alien8.de \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=dave.hansen@linux.intel.com \
    --cc=eddyz87@gmail.com \
    --cc=emil@etsalapatis.com \
    --cc=ihor.solodrai@linux.dev \
    --cc=kernel-team@meta.com \
    --cc=kkd@meta.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=memxor@gmail.com \
    --cc=mingo@redhat.com \
    --cc=peterz@infradead.org \
    --cc=puranjay@kernel.org \
    --cc=tglx@kernel.org \
    --cc=x86@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®