From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (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 6D9C3366075; Wed, 20 May 2026 17:21:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779297678; cv=none; b=T6RfYVermKObhSM59Bd2l2GG8g0GYqHkqpTHmcYCxbEOl42+Dqs6qjYO/Auv92zbhQIJeZoW7vmCFq0P49VnDI3iGdgsmYGADZs+rnvYhuYDA/u9OWl6RNwGWxENXQNE3Rb+dLFepzT2mlFmq0SMjau1HuspUdLZoEa3yXMWqSU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779297678; c=relaxed/simple; bh=9lhbT+c4LSWe1bi1PToXwgW9cYYQLkIXb/0JMd65QAs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=BNCqbB85EZSyESGJDfhsQYXSnnG76kNzwMla5e1Ux9hrU1TlWsGAI39i7cyYqZlHaABwY38pbBXTr5HQbvBBxBdFl3JeU9ujoITPPWlhk3G5z38iBFnfXSNWj0yFG05D0sCEYTHOeZGYl3Kl4HrfOLPnqx2/3mS+hICTEMmPR3c= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=WDF85ESP; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="WDF85ESP" Received: by smtp.kernel.org (Postfix) with ESMTPSA id D98011F000E9; Wed, 20 May 2026 17:21:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1779297677; bh=IbxwSl9bGVWBxIRn4smkj2Sx17vDo1yHLgdcoWGCC2Q=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=WDF85ESPvsuanSesl1+HXYbkIA3EuKiWhpM5RoH0C7ZMA9yLYe1Zvq5HBrL0HfBaR eC/5bcv285sYJ0JWSTe0bMIFONSDLZuxbW+3GU8QB7N/W4ak/SqGlc+9eL7btxQfoW j9xhV2hkjLJlHalUf/zSCqRnLHPjm/Twq1R7eV9s= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Xiang Mei , Weiming Shi , Sun Jian , Paul Chaignon , Alexei Starovoitov , Sasha Levin Subject: [PATCH 6.18 121/957] bpf: fix end-of-list detection in cgroup_storage_get_next_key() Date: Wed, 20 May 2026 18:10:04 +0200 Message-ID: <20260520162137.182960225@linuxfoundation.org> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260520162134.554764788@linuxfoundation.org> References: <20260520162134.554764788@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.18-stable review patch. If anyone has any objections, please let me know. ------------------ From: Weiming Shi [ Upstream commit 5828b9e5b272ecff7cf5d345128d3de7324117f7 ] list_next_entry() never returns NULL -- when the current element is the last entry it wraps to the list head via container_of(). The subsequent NULL check is therefore dead code and get_next_key() never returns -ENOENT for the last element, instead reading storage->key from a bogus pointer that aliases internal map fields and copying the result to userspace. Replace it with list_entry_is_head() so the function correctly returns -ENOENT when there are no more entries. Fixes: de9cbbaadba5 ("bpf: introduce cgroup storage maps") Reported-by: Xiang Mei Signed-off-by: Weiming Shi Reviewed-by: Sun Jian Acked-by: Paul Chaignon Link: https://lore.kernel.org/r/20260403132951.43533-2-bestswngs@gmail.com Signed-off-by: Alexei Starovoitov Signed-off-by: Sasha Levin --- kernel/bpf/local_storage.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kernel/bpf/local_storage.c b/kernel/bpf/local_storage.c index c93a756e035c0..b8db4fbd3bd2a 100644 --- a/kernel/bpf/local_storage.c +++ b/kernel/bpf/local_storage.c @@ -259,7 +259,7 @@ static int cgroup_storage_get_next_key(struct bpf_map *_map, void *key, goto enoent; storage = list_next_entry(storage, list_map); - if (!storage) + if (list_entry_is_head(storage, &map->list, list_map)) goto enoent; } else { storage = list_first_entry(&map->list, -- 2.53.0