linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Roman Gushchin <roman.gushchin@linux.dev>
To: bot+bpf-ci@kernel.org
Cc: bpf@vger.kernel.org, linux-mm@kvack.org,
	linux-kernel@vger.kernel.org, inwardvessel@gmail.com,
	ast@kernel.org, daniel@iogearbox.net, shakeel.butt@linux.dev,
	mhocko@kernel.org, hannes@cmpxchg.org, mhocko@suse.com,
	andrii@kernel.org, martin.lau@kernel.org, eddyz87@gmail.com,
	yonghong.song@linux.dev, clm@meta.com, ihor.solodrai@linux.dev
Subject: Re: [PATCH bpf-next v2 4/7] mm: introduce BPF kfuncs to access memcg statistics and events
Date: Fri, 19 Dec 2025 20:39:39 -0800	[thread overview]
Message-ID: <873455n4vo.fsf@linux.dev> (raw)
In-Reply-To: <1b78506003b674f5e66bc7ac61f279a363f5cacc8d2fcb615d06abb0316ef00c@mail.kernel.org> (bot's message of "Sat, 20 Dec 2025 04:29:43 +0000 (UTC)")

bot+bpf-ci@kernel.org writes:

>> diff --git a/mm/bpf_memcontrol.c b/mm/bpf_memcontrol.c
>> index 2d518ad2ad3f..d84fe6f3ed43 100644
>> --- a/mm/bpf_memcontrol.c
>> +++ b/mm/bpf_memcontrol.c
>> @@ -78,6 +78,57 @@ __bpf_kfunc void bpf_put_mem_cgroup(struct mem_cgroup *memcg)
>>  	css_put(&memcg->css);
>>  }
>>
>> +/**
>> + * bpf_mem_cgroup_vm_events - Read memory cgroup's vm event counter
>> + * @memcg: memory cgroup
>> + * @event: event id
>> + *
>> + * Allows to read memory cgroup event counters.
>> + */
>> +__bpf_kfunc unsigned long bpf_mem_cgroup_vm_events(struct mem_cgroup *memcg,
>> +						enum vm_event_item event)
>> +{
>> +	return memcg_events(memcg, event);
>> +}
>
> Should this function validate the event parameter before passing it to
> memcg_events()?
>
> The call chain bpf_mem_cgroup_vm_events()->memcg_events()->memcg_events_index()
> reaches an array access in memcg_events_index():
>
>     static inline int memcg_events_index(enum vm_event_item idx)
>     {
>         return mem_cgroup_events_index[idx];
>     }
>
> The array mem_cgroup_events_index is declared with size NR_VM_EVENT_ITEMS.
> If a BPF program passes an event value >= NR_VM_EVENT_ITEMS, this would
> cause an out-of-bounds array read.
>
> For comparison, bpf_mem_cgroup_page_state() below validates its idx
> parameter before calling memcg_page_state_output(). A similar check here
> would prevent the potential out-of-bounds access:
>
>     if (event < 0 || event >= NR_VM_EVENT_ITEMS)
>         return (unsigned long)-1;

No, it's a false positive, as explained in a reply to the similar comment
to v1.

  reply	other threads:[~2025-12-20  4:39 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-12-20  4:12 [PATCH bpf-next v2 0/7] mm: bpf kfuncs to access memcg data Roman Gushchin
2025-12-20  4:12 ` [PATCH bpf-next v2 1/7] mm: declare memcg_page_state_output() in memcontrol.h Roman Gushchin
2025-12-20  4:12 ` [PATCH bpf-next v2 2/7] mm: introduce BPF kfuncs to deal with memcg pointers Roman Gushchin
2025-12-20  5:20   ` Shakeel Butt
2025-12-22  0:39   ` Alexei Starovoitov
2025-12-20  4:12 ` [PATCH bpf-next v2 3/7] mm: introduce bpf_get_root_mem_cgroup() BPF kfunc Roman Gushchin
2025-12-20  5:21   ` Shakeel Butt
2025-12-20  4:12 ` [PATCH bpf-next v2 4/7] mm: introduce BPF kfuncs to access memcg statistics and events Roman Gushchin
2025-12-20  4:29   ` bot+bpf-ci
2025-12-20  4:39     ` Roman Gushchin [this message]
2025-12-20  5:22   ` Shakeel Butt
2025-12-20  4:12 ` [PATCH bpf-next v2 5/7] mm: introduce BPF kfunc to access memory events Roman Gushchin
2025-12-20  4:29   ` bot+bpf-ci
2025-12-20  4:41     ` Roman Gushchin
2025-12-20 13:19       ` Chris Mason
2025-12-20 18:43         ` Roman Gushchin
2025-12-20 19:59           ` Chris Mason
2025-12-22 22:23             ` Roman Gushchin
2025-12-23 14:09               ` Chris Mason
2025-12-22  0:49   ` Alexei Starovoitov
2025-12-22  0:51     ` Alexei Starovoitov
2025-12-20  4:12 ` [PATCH bpf-next v2 6/7] bpf: selftests: selftests for memcg stat kfuncs Roman Gushchin
2025-12-20  5:23   ` Shakeel Butt
2025-12-20  4:12 ` [PATCH bpf-next v2 7/7] MAINTAINERS: add an entry for MM BPF extensions Roman Gushchin
2025-12-20  5:26   ` Shakeel Butt

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=873455n4vo.fsf@linux.dev \
    --to=roman.gushchin@linux.dev \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bot+bpf-ci@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=clm@meta.com \
    --cc=daniel@iogearbox.net \
    --cc=eddyz87@gmail.com \
    --cc=hannes@cmpxchg.org \
    --cc=ihor.solodrai@linux.dev \
    --cc=inwardvessel@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=martin.lau@kernel.org \
    --cc=mhocko@kernel.org \
    --cc=mhocko@suse.com \
    --cc=shakeel.butt@linux.dev \
    --cc=yonghong.song@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).