mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Kumar Kartikeya Dwivedi <memxor@gmail.com>
To: 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>,
	Andy Lutomirski <luto@kernel.org>,
	Peter Zijlstra <peterz@infradead.org>,
	Thomas Gleixner <tglx@kernel.org>, Ingo Molnar <mingo@redhat.com>,
	Borislav Petkov <bp@alien8.de>,
	Puranjay Mohan <puranjay@kernel.org>,
	x86@kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH bpf-next v1 0/3] bpf: Do not follow __iomem pointers
Date: Sat, 28 Nov 2026 03:53:14 +0100	[thread overview]
Message-ID: <cover.1795834380.git.memxor@gmail.com> (raw)

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


             reply	other threads:[~2026-11-28  2:53 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-28  2:53 Kumar Kartikeya Dwivedi [this message]
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

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=cover.1795834380.git.memxor@gmail.com \
    --to=memxor@gmail.com \
    --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=luto@kernel.org \
    --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®