From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out-185.mta0.migadu.com (out-185.mta0.migadu.com [91.218.175.185]) (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 D88252741A6 for ; Fri, 19 Dec 2025 02:51:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.185 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766112697; cv=none; b=m3FEvpbnieCrQ7+0cmZbnYVJG3/+IxsJ6mwOAzBxLTMFcVuyN3a813UhR7NF0PGXj8WTPkUHXMtKtQ7RZOT9t/MqLqer7lZweF5VtPP6MOEJgoi27fUVuJ1YVS3LNOXMZbAzlP1EqwgycH4HLYOMjvEHwJ61UQ1hyHAXML478lw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766112697; c=relaxed/simple; bh=jAOIueH1laJyi3b5aKBHyRqK/3PeRooLBsh0b6GIZ0Y=; h=From:To:Cc:Subject:In-Reply-To:References:Date:Message-ID: MIME-Version:Content-Type; b=gZgmvevAh8F3+/z+Ti45AkgOUK2MC5WXlGTqWBe0kS/al2SBkIvPt88ZiobI7qV6d/iRfeKefC9dCCVk/4xnOu5u9LJeD6QJxGcWIAnEsjJCbhibeUieruWghEHsiWDB7Vb8lghuQ3lQU0iAgVSIaaVDdmKnyl+DHDLrmonr0Tw= 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=lXUnWFOj; arc=none smtp.client-ip=91.218.175.185 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="lXUnWFOj" 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=1766112689; 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=ZX9EdKmymQBf6dTDpGNXCbWaUIzPPXzTY2GtSXhpfr4=; b=lXUnWFOjmasnyhi98G8wHqdqJ411bv16T/4L+YoejiUdO0fpW3TqnCGHIdx3f8yFsRwk8p YlyVWZh6UBZJZbW+pajOOEUocfoYU0Gh4BzANXLTw1MDAeXqTw393pirs7nOpCh/RPGfw+ 2sxUkLngcYgWoIOn9ZZa0Qsu0+18rZg= 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, 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 5/6] mm: introduce BPF kfunc to access memory events In-Reply-To: (bot's message of "Fri, 19 Dec 2025 02:21:40 +0000 (UTC)") References: <20251219015750.23732-6-roman.gushchin@linux.dev> Date: Thu, 18 Dec 2025 18:51:23 -0800 Message-ID: <873457b2vo.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 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) Same here: the check is enforced by the bpf verifier based on the type information. Not a real issue.