BPF List
 help / color / mirror / Atom feed
* [PATCH bpf v3 1/2] bpf: Make sure all tail call callers use cgroup storage if the owner does
@ 2025-12-03 19:50 Amery Hung
  2025-12-03 19:50 ` [PATCH bpf v3 2/2] selftests/bpf: Test tail call when cgroup storage is used Amery Hung
  2026-01-24  2:59 ` [PATCH bpf v3 1/2] bpf: Make sure all tail call callers use cgroup storage if the owner does Pu Lehui
  0 siblings, 2 replies; 4+ messages in thread
From: Amery Hung @ 2025-12-03 19:50 UTC (permalink / raw)
  To: bpf
  Cc: alexei.starovoitov, andrii, daniel, martin.lau, eddyz87,
	ameryhung, kernel-team

Mitigate a possible NULL pointer dereference in bpf_get_local_storage()
by requiring all callers to use cgroup storage if the owner does.

Cgroup storage is allocated lazily when attaching a cgroup bpf program.
With tail call, it is possible for a callee BPF program to see a NULL
storage pointer if the caller prorgam does not use cgroup storage.

Reported-by: Yinhao Hu <dddddd@hust.edu.cn>
Reported-by: Kaiyan Mei <M202472210@hust.edu.cn>
Reported-by: Dongliang Mu <dzm91@hust.edu.cn>
Closes: https://lore.kernel.org/bpf/c9ac63d7-73be-49c5-a4ac-eb07f7521adb@hust.edu.cn/
Signed-off-by: Amery Hung <ameryhung@gmail.com>
---
 kernel/bpf/core.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/kernel/bpf/core.c b/kernel/bpf/core.c
index c8ae6ab31651..e249ea98f55d 100644
--- a/kernel/bpf/core.c
+++ b/kernel/bpf/core.c
@@ -2403,8 +2403,7 @@ 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;
+			ret = map->owner->storage_cookie[i] == cookie;
 		}
 		if (ret &&
 		    map->owner->attach_func_proto != aux->attach_func_proto) {
-- 
2.47.3


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

end of thread, other threads:[~2026-01-24  2:59 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-12-03 19:50 [PATCH bpf v3 1/2] bpf: Make sure all tail call callers use cgroup storage if the owner does Amery Hung
2025-12-03 19:50 ` [PATCH bpf v3 2/2] selftests/bpf: Test tail call when cgroup storage is used Amery Hung
2025-12-03 22:36   ` Amery Hung
2026-01-24  2:59 ` [PATCH bpf v3 1/2] bpf: Make sure all tail call callers use cgroup storage if the owner does Pu Lehui

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