Skip to content

Commit 188aae1

Browse files
anakryikogregkh
authored andcommitted
bpf: Initialize storage pointers to NULL to prevent freeing garbage pointer
commit 62039c3 upstream. Local storage array isn't initialized, so if cgroup storage allocation fails for BPF_CGROUP_STORAGE_SHARED, error handling code will attempt to free uninitialized pointer for BPF_CGROUP_STORAGE_PERCPU storage type. Avoid this by always initializing storage pointers to NULLs. Fixes: 8bad74f ("bpf: extend cgroup bpf core to allow multiple cgroup storage types") Signed-off-by: Andrii Nakryiko <[email protected]> Signed-off-by: Alexei Starovoitov <[email protected]> Link: https://lore.kernel.org/bpf/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent c68e111 commit 188aae1

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

kernel/bpf/cgroup.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -303,8 +303,8 @@ int __cgroup_bpf_attach(struct cgroup *cgrp, struct bpf_prog *prog,
303303
{
304304
struct list_head *progs = &cgrp->bpf.progs[type];
305305
struct bpf_prog *old_prog = NULL;
306-
struct bpf_cgroup_storage *storage[MAX_BPF_CGROUP_STORAGE_TYPE],
307-
*old_storage[MAX_BPF_CGROUP_STORAGE_TYPE] = {NULL};
306+
struct bpf_cgroup_storage *storage[MAX_BPF_CGROUP_STORAGE_TYPE] = {};
307+
struct bpf_cgroup_storage *old_storage[MAX_BPF_CGROUP_STORAGE_TYPE] = {};
308308
enum bpf_cgroup_storage_type stype;
309309
struct bpf_prog_list *pl;
310310
bool pl_was_allocated;

0 commit comments

Comments
 (0)