public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH bpf-next v1 0/2] bpf: Fix panic in bpf_get_local_storage
@ 2025-04-17  4:40 Jiayuan Chen
  2025-04-17  4:40 ` [PATCH bpf-next v1 1/2] bpf: Create cgroup storage if needed when updating link Jiayuan Chen
  2025-04-17  4:40 ` [PATCH bpf-next v1 2/2] selftests/bpf: Add link update test for cgroup_storage Jiayuan Chen
  0 siblings, 2 replies; 7+ messages in thread
From: Jiayuan Chen @ 2025-04-17  4:40 UTC (permalink / raw)
  To: andrii, martin.lau, bpf
  Cc: alexis.lothore, mrpre, Jiayuan Chen, Alexei Starovoitov,
	Daniel Borkmann, Eduard Zingerman, Song Liu, Yonghong Song,
	John Fastabend, KP Singh, Stanislav Fomichev, Hao Luo, Jiri Olsa,
	Mykola Lysenko, Shuah Khan, Alan Maguire, linux-kernel,
	linux-kselftest

The selftest I provided can reproduce a panic:
'./test_progs -a cgroup_storage_update'

When we attach a program to cgroup and if prog->aux->cgroup_storage
exists, which means the cgroup_storage map is used in the program, we
will then allocate storage by bpf_cgroup_storages_alloc() and assign it
to pl->storage.

At the end, pl->storage will be assigned to
cgrp->bpf.effective[atype]->cgroup_storage by xxx_effective_progs().

But when we attach a program without the cgroup_storage map being used
(prog->aux->cgroup_storage is empty), the cgroup_storage in struct
bpf_prog_array_item is empty.

Then, if we use BPF_LINK_UPDATE to replace the old program with a new one
that uses the cgroup_storage map, we miss the cgroup_storage being
initialized.

This causes a panic when accessing storage in bpf_get_local_storage.

Jiayuan Chen (2):
  bpf: Create cgroup storage if needed when updating link
  selftests/bpf: Add link update test for cgroup_storage

 kernel/bpf/cgroup.c                           | 24 +++++++---
 .../selftests/bpf/prog_tests/cgroup_storage.c | 45 +++++++++++++++++++
 .../selftests/bpf/progs/cgroup_storage.c      |  6 +++
 3 files changed, 70 insertions(+), 5 deletions(-)

-- 
2.47.1


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

end of thread, other threads:[~2025-04-23 21:08 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-04-17  4:40 [PATCH bpf-next v1 0/2] bpf: Fix panic in bpf_get_local_storage Jiayuan Chen
2025-04-17  4:40 ` [PATCH bpf-next v1 1/2] bpf: Create cgroup storage if needed when updating link Jiayuan Chen
2025-04-23  0:13   ` Martin KaFai Lau
2025-04-23  2:21     ` Jiayuan Chen
2025-04-23 21:07       ` Martin KaFai Lau
2025-04-23  8:45   ` [PATCH bpf-next " Markus Elfring
2025-04-17  4:40 ` [PATCH bpf-next v1 2/2] selftests/bpf: Add link update test for cgroup_storage Jiayuan Chen

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