All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Daniel Borkmann" <daniel@iogearbox.net>
Cc: bpf@vger.kernel.org
Subject: Re: [PATCH bpf v2 2/4] bpf: Require CAP_PERFMON for kfuncs reading memory
Date: Thu, 10 Sep 2026 21:45:16 +0000	[thread overview]
Message-ID: <20260910214517.594141F000FF@smtp.kernel.org> (raw)
In-Reply-To: <20260910213510.49358-2-daniel@iogearbox.net>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:

Pre-existing issues:
- [High] Missing bounds check for negative enum values in `bpf_mem_cgroup_memory_events` kfunc.
--

commit cdc4306f1568d5f9112eea54321dd73200076861
Author: Daniel Borkmann <daniel@iogearbox.net>

bpf: Require CAP_PERFMON for kfuncs reading memory

This commit restricts several memory-reading and fault-safe probe BPF kernel
functions (kfuncs) by marking them with the KF_PERFMON flag. It ensures that
these functions, such as bpf_rdonly_cast and bpf_get_kmem_cache, now require
CAP_PERFMON privileges to prevent unprivileged memory access.

> diff --git a/kernel/bpf/helpers.c b/kernel/bpf/helpers.c
[ ... ]

While reviewing the BPF kfuncs context, I noticed a related concern in
bpf_mem_cgroup_memory_events() located in mm/bpf_memcontrol.c.

[Severity: High]
This isn't a bug introduced by this patch, but is it possible for a negative
enum value to bypass the bounds check here?

mm/bpf_memcontrol.c:bpf_mem_cgroup_memory_events() {
        ...
        if (unlikely(event >= MEMCG_NR_MEMORY_EVENTS))
                return (unsigned long)-1;

        return atomic_long_read(&memcg->memory_events[event]);
}

The BPF verifier allows unconstrained scalar arguments for enums and does
not enforce enum bounds internally. If a BPF program passes a negative
integer as the event parameter (such as -1), the >= check evaluates to
false because enums are treated as signed integers.

Could this lead to an out-of-bounds read of kernel memory when the negative
event index is used to access the memory_events array?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260910213510.49358-1-daniel@iogearbox.net?part=2

  reply	other threads:[~2026-09-10 21:45 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-10 21:35 [PATCH bpf v2 1/4] bpf: Add KF_PERFMON kfunc flag Daniel Borkmann
2026-09-10 21:35 ` [PATCH bpf v2 2/4] bpf: Require CAP_PERFMON for kfuncs reading memory Daniel Borkmann
2026-09-10 21:45   ` sashiko-bot [this message]
2026-09-10 22:33   ` bot+bpf-ci
2026-09-10 21:35 ` [PATCH bpf v2 3/4] bpf: Require CAP_PERFMON for untrusted read-only memory reads Daniel Borkmann
2026-09-10 22:33   ` bot+bpf-ci
2026-09-10 21:35 ` [PATCH bpf v2 4/4] selftests/bpf: Add tests for the KF_PERFMON gates Daniel Borkmann
2026-09-10 22:33   ` bot+bpf-ci
2026-09-11  0:00 ` [PATCH bpf v2 1/4] bpf: Add KF_PERFMON kfunc flag patchwork-bot+netdevbpf

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=20260910214517.594141F000FF@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=sashiko-reviews@lists.linux.dev \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.