From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out-182.mta0.migadu.com (out-182.mta0.migadu.com [91.218.175.182]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 271F11D6187 for ; Fri, 19 Dec 2025 02:49:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.182 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766112584; cv=none; b=qxlK451lutbQR3zSI/r1z/2/ocB5L/trKsWFV4X/wXOQfV/E6+FpjXJDQuqfzhnkQYQzVd7YY5oSewQKcJW6EP3KpIqGZrr3vlRvBPtS6Jfqq2GmVGLh5gDhUlLzJ6PkQF6YhC0MjgMMpIs7xfCe1zdwA7n6nZad85r08pS82nc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766112584; c=relaxed/simple; bh=9FvASLSTjwxknBjCG4rdJsjMOWtZIKeboVSpxEUCHj0=; h=From:To:Cc:Subject:In-Reply-To:References:Date:Message-ID: MIME-Version:Content-Type; b=HZhe8pS0vHJt41B1Z/AK86YBp6RERUIMqKrLK0gkNBEJjLLxAwg6GCDYlMui31RzoGTMfFiibAEz6lFlFIwOLpaOW8mqvtjNMkVA7040pdJi2sH34BVMS3hCSsKk8yixIfutluZr/mPo6UZYXoaz+9EBmj5EFqns0PrZgI2+rdM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=pI4nKNEv; arc=none smtp.client-ip=91.218.175.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="pI4nKNEv" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1766112576; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=abd/44gPrDqvBL/2LyNnB1pB9d9gpdKplEObPG4utUA=; b=pI4nKNEv57QpGkjms+FO+OVqvN/dvP3YiYsx0xarnEsiCnH4BErdFjMIC9Pe/5Z8eWZ+zv hmJofNw0nk7tikxTe/wsF8R16TfIFQmAvU/5WGTCVz8J0VCQiq5uL7Di6bdR/twt3OIc+a hFzrgZV0SJJtPpec9hJMioiFImoD1Go= From: Roman Gushchin 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 v1 4/6] mm: introduce BPF kfuncs to access memcg statistics and events In-Reply-To: (bot's message of "Fri, 19 Dec 2025 02:15:11 +0000 (UTC)") References: <20251219015750.23732-5-roman.gushchin@linux.dev> Date: Thu, 18 Dec 2025 18:49:29 -0800 Message-ID: <87bjjvb2yu.fsf@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain X-Migadu-Flow: FLOW_OUT bot+bpf-ci@kernel.org writes: >> diff --git a/mm/bpf_memcontrol.c b/mm/bpf_memcontrol.c >> index 6d0d73bf0dd1..4d9d7d909f6c 100644 >> --- a/mm/bpf_memcontrol.c >> +++ b/mm/bpf_memcontrol.c > > [ ... ] > >> +/** >> + * 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 bpf_mem_cgroup_vm_events() validate the event parameter before > passing it to memcg_events()? The call chain is: > > bpf_mem_cgroup_vm_events() -> memcg_events() -> memcg_events_index() > > And memcg_events_index() does: > > return mem_cgroup_events_index[idx]; > > where mem_cgroup_events_index is an array of size NR_VM_EVENT_ITEMS. If a > BPF program passes event >= NR_VM_EVENT_ITEMS, this would be an > out-of-bounds array read. > > The sister function bpf_mem_cgroup_page_state() below validates its idx > parameter before calling its callee: It's a false positive: the check is enforced by the bpf verifier based on type information. > >> +/** >> + * bpf_mem_cgroup_page_state - Read memory cgroup's page state counter >> + * @memcg: memory cgroup >> + * @idx: counter idx >> + * >> + * Allows to read memory cgroup statistics. The output is in bytes. >> + */ >> +__bpf_kfunc unsigned long bpf_mem_cgroup_page_state(struct mem_cgroup *memcg, int idx) >> +{ >> + if (idx < 0 || idx >= MEMCG_NR_STAT) >> + return (unsigned long)-1; >> + >> + return memcg_page_state_output(memcg, idx); >> +} > > Should bpf_mem_cgroup_vm_events() have a similar bounds check, perhaps: > > if (event >= NR_VM_EVENT_ITEMS) > return (unsigned long)-1; > > before calling memcg_events()? No. Here is required because idx is a simple int.