Skip to content

bpf: Fix panic in bpf_get_local_storage

Jiayuan Chen bpf linux-kselftest lkml 1 version In review

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 Latest2 patches 4 repliesIn review

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/2bpf: Create cgroup storage if needed when updating linkkernel/bpf/cgroup.c+19 -54 replies
2/2selftests/bpf: Add link update test for cgroup_storagetools/testing/selftests/bpf/prog_tests/cgroup_storage.c tools/testing/selftests/bpf/progs/cgroup_storage.c+51 -00 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v1 yet.

Read the v1 thread

Cover letter [PATCH bpf-next v1 0/2] bpf: Fix panic in bpf_get_local_storage

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(-)
Signature · 1 line
2.47.1