BPF List
 help / color / mirror / Atom feed
* [PATCH v2 1/2] bpf: Tighten cgroup storage cookie checks for prog arrays
@ 2026-06-02  7:35 Lin Ma
  2026-06-02  7:35 ` [PATCH v2 2/2] selftests/bpf: Cover tail-call cgroup storage prog-array checks Lin Ma
  2026-06-02  8:15 ` [PATCH v2 1/2] bpf: Tighten cgroup storage cookie checks for prog arrays bot+bpf-ci
  0 siblings, 2 replies; 8+ messages in thread
From: Lin Ma @ 2026-06-02  7:35 UTC (permalink / raw)
  To: Alexei Starovoitov, Daniel Borkmann, bpf
  Cc: Andrii Nakryiko, John Fastabend, Martin KaFai Lau,
	Eduard Zingerman, Kumar Kartikeya Dwivedi, Song Liu,
	Yonghong Song, Jiri Olsa, YiFei Zhu, Shuah Khan, linux-kselftest,
	linux-kernel, Amery Hung, Lin Ma, Rongzhen Cui, Jingguo Tan,
	cenxianlong, chenzhe

The recent KCTF-reported cgroup local storage issue assigned
CVE-2025-38502 was fixed by commit abad3d0bad72 ("bpf: Fix oob access
in cgroup local storage").

However, the previous fixes are still incomplete. The current prog-array
compatibility check treats a program with no cgroup storage as
compatible with any stored storage cookie. This allows a storage-less
program to bridge a tail-call chain between an entry program and a
storage-using callee even though runtime cgroup local storage still
follows the caller context.

Require exact per-type storage_cookie equality when checking prog-array
compatibility. This blocks zero-storage bridge programs from joining a
prog-array owned by a storage-using program and closes the residual
A -> B(no storage) -> C(storage) path.

This also aligns with Amery Hung's earlier NULL-storage tail-call fix by
requiring storage use to match consistently across prog-array users.

Cc: stable@vger.kernel.org
Fixes: 7d9c3427894f ("bpf: Make cgroup storages shared between programs on the same cgroup")
Tested-by: Amery Hung <ameryhung@gmail.com>
Signed-off-by: Lin Ma <malin89@huawei.com>
Signed-off-by: Rongzhen Cui <cuirongzhen@huawei.com>
Signed-off-by: Jingguo Tan <tanjingguo@huawei.com>
---
v1: https://lore.kernel.org/bpf/20260601095158.1186318-1-malin89@huawei.com/
v1 -> v2:
 - refine the commit message and mention the relation to Amery Hung's
   NULL-storage tail-call fix
 - add patch 2/2 selftests for tail-call cgroup storage prog-array
   checks

 kernel/bpf/core.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/kernel/bpf/core.c b/kernel/bpf/core.c
index 6aa2a8b24030..f0b61b10f30e 100644
--- a/kernel/bpf/core.c
+++ b/kernel/bpf/core.c
@@ -2470,8 +2470,12 @@ static bool __bpf_prog_map_compatible(struct bpf_map *map,
 				break;
 			cookie = aux->cgroup_storage[i] ?
 				 aux->cgroup_storage[i]->cookie : 0;
-			ret = map->owner->storage_cookie[i] == cookie ||
-			      !cookie;
+			/*
+			 * Tail calls keep using the caller cgroup storage
+			 * context, so prog-array members must use the same
+			 * storage cookie.
+			 */
+			ret = map->owner->storage_cookie[i] == cookie;
 		}
 		if (ret &&
 		    map->owner->attach_func_proto != aux->attach_func_proto) {
-- 
2.53.0

^ permalink raw reply related	[flat|nested] 8+ messages in thread
* Re: [PATCH v2 2/2] selftests/bpf: Cover tail-call cgroup storage prog-array checks
@ 2026-06-04  1:52 malin (R)
  0 siblings, 0 replies; 8+ messages in thread
From: malin (R) @ 2026-06-04  1:52 UTC (permalink / raw)
  To: Leon Hwang
  Cc: Alexei Starovoitov, Daniel Borkmann, bpf@vger.kernel.org,
	Andrii Nakryiko, John Fastabend, Martin KaFai Lau,
	Eduard Zingerman, Kumar Kartikeya Dwivedi, Song Liu,
	Yonghong Song, Jiri Olsa, YiFei Zhu, Shuah Khan,
	linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org,
	Amery Hung, cuirongzhen, tanjingguo, cenxianlong, Chenzhe

Hello Leon,

> These new ones should stay at the tail of test_tailcalls().

My bad, just found this reply.

Will fix that in the next version.

Thanks
Lin

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2026-06-04  1:52 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-06-02  7:35 [PATCH v2 1/2] bpf: Tighten cgroup storage cookie checks for prog arrays Lin Ma
2026-06-02  7:35 ` [PATCH v2 2/2] selftests/bpf: Cover tail-call cgroup storage prog-array checks Lin Ma
2026-06-02  8:15   ` bot+bpf-ci
2026-06-02 16:41   ` Yonghong Song
2026-06-03 15:01   ` Leon Hwang
2026-06-02  8:15 ` [PATCH v2 1/2] bpf: Tighten cgroup storage cookie checks for prog arrays bot+bpf-ci
2026-06-02 15:14   ` Yonghong Song
  -- strict thread matches above, loose matches on Subject: below --
2026-06-04  1:52 [PATCH v2 2/2] selftests/bpf: Cover tail-call cgroup storage prog-array checks malin (R)

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox