linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: bot+bpf-ci@kernel.org
To: roman.gushchin@linux.dev,bpf@vger.kernel.org,linux-mm@kvack.org,linux-kernel@vger.kernel.org
Cc: inwardvessel@gmail.com,ast@kernel.org,daniel@iogearbox.net,shakeel.butt@linux.dev,mhocko@kernel.org,hannes@cmpxchg.org,ast@kernel.org,andrii@kernel.org,daniel@iogearbox.net,martin.lau@kernel.org,eddyz87@gmail.com,yonghong.song@linux.dev,clm@meta.com,ihor.solodrai@linux.dev
Subject: Re: [PATCH bpf-next v1 5/6] mm: introduce BPF kfunc to access memory events
Date: Fri, 19 Dec 2025 02:21:40 +0000 (UTC)	[thread overview]
Message-ID: <cf8d48e8bcdba2515366bc8b6c85f581ca3d18ead24db9cb3ba9b98db252e0b9@mail.kernel.org> (raw)
In-Reply-To: <20251219015750.23732-6-roman.gushchin@linux.dev>

[-- Attachment #1: Type: text/plain, Size: 1256 bytes --]

> diff --git a/mm/bpf_memcontrol.c b/mm/bpf_memcontrol.c
> index 4d9d7d909f6c..75076d682f75 100644
> --- a/mm/bpf_memcontrol.c
> +++ b/mm/bpf_memcontrol.c

[ ... ]

> +__bpf_kfunc unsigned long bpf_mem_cgroup_memory_events(struct mem_cgroup *memcg,
> +						enum memcg_memory_event event)
> +{
> +	if (event >= MEMCG_NR_MEMORY_EVENTS)
> +		return (unsigned long)-1;
> +
> +	return atomic_long_read(&memcg->memory_events[event]);
> +}

Could this cause an out-of-bounds access if a BPF program passes a negative
value for event? The enum type is signed, so if event is -1, the check
"event >= MEMCG_NR_MEMORY_EVENTS" would evaluate to false (-1 >= 10 is
false), allowing access to memcg->memory_events[-1].

The existing bpf_mem_cgroup_page_state() in the same file uses both lower
and upper bound checks:

    if (idx < 0 || idx >= MEMCG_NR_STAT)
        return (unsigned long)-1;

Should bpf_mem_cgroup_memory_events() follow the same pattern with:

    if (event < 0 || event >= MEMCG_NR_MEMORY_EVENTS)

[ ... ]


---
AI reviewed your patch. Please fix the bug or email reply why it's not a bug.
See: https://github.com/kernel-patches/vmtest/blob/master/ci/claude/README.md

CI run summary: https://github.com/kernel-patches/bpf/actions/runs/20357445962

  reply	other threads:[~2025-12-19  2:21 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-12-19  1:57 [PATCH bpf-next v1 0/6] mm: bpf kfuncs to access memcg data Roman Gushchin
2025-12-19  1:57 ` [PATCH bpf-next v1 1/6] mm: declare memcg_page_state_output() in memcontrol.h Roman Gushchin
2025-12-19 21:35   ` Shakeel Butt
2025-12-19  1:57 ` [PATCH bpf-next v1 2/6] mm: introduce BPF kfuncs to deal with memcg pointers Roman Gushchin
2025-12-19 21:51   ` Shakeel Butt
2025-12-19 22:42     ` Roman Gushchin
2025-12-19  1:57 ` [PATCH bpf-next v1 3/6] mm: introduce bpf_get_root_mem_cgroup() BPF kfunc Roman Gushchin
2025-12-19 22:10   ` Shakeel Butt
2025-12-19  1:57 ` [PATCH bpf-next v1 4/6] mm: introduce BPF kfuncs to access memcg statistics and events Roman Gushchin
2025-12-19  2:15   ` bot+bpf-ci
2025-12-19  2:49     ` Roman Gushchin
2025-12-19 22:45   ` Shakeel Butt
2025-12-19  1:57 ` [PATCH bpf-next v1 5/6] mm: introduce BPF kfunc to access memory events Roman Gushchin
2025-12-19  2:21   ` bot+bpf-ci [this message]
2025-12-19  2:51     ` Roman Gushchin
2025-12-19 22:46   ` Shakeel Butt
2025-12-19  1:57 ` [PATCH bpf-next v1 6/6] bpf: selftests: selftests for memcg stat kfuncs Roman Gushchin
2025-12-19 23:07   ` Shakeel Butt
2025-12-20  3:20     ` Roman Gushchin

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=cf8d48e8bcdba2515366bc8b6c85f581ca3d18ead24db9cb3ba9b98db252e0b9@mail.kernel.org \
    --to=bot+bpf-ci@kernel.org \
    --cc=andrii@kernel.org \
    --cc=ast@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=roman.gushchin@linux.dev \
    --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