blob: 64c96fafcf8d0fc6b2b366036e3382a155ae6c28 [file] [log] [blame]
From 739c5b5ceeef7e38c4bcb5d3165d4ed8e4829a4f Mon Sep 17 00:00:00 2001
From: Andrii Nakryiko <>
Date: Mon, 9 Mar 2020 15:27:55 -0700
Subject: [PATCH] bpf: Initialize storage pointers to NULL to prevent freeing
garbage pointer
commit 62039c30c19dcab96621e074aeeb90da7100def7 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: 8bad74f9840f ("bpf: extend cgroup bpf core to allow multiple cgroup storage types")
Signed-off-by: Andrii Nakryiko <>
Signed-off-by: Alexei Starovoitov <>
Signed-off-by: Paul Gortmaker <>
diff --git a/kernel/bpf/cgroup.c b/kernel/bpf/cgroup.c
index 9c073a88374f..b6ad8cb50efc 100644
--- a/kernel/bpf/cgroup.c
+++ b/kernel/bpf/cgroup.c
@@ -239,8 +239,8 @@ int __cgroup_bpf_attach(struct cgroup *cgrp, struct bpf_prog *prog,
struct list_head *progs = &cgrp->bpf.progs[type];
struct bpf_prog *old_prog = NULL;
- struct bpf_cgroup_storage *storage[MAX_BPF_CGROUP_STORAGE_TYPE],
+ struct bpf_cgroup_storage *storage[MAX_BPF_CGROUP_STORAGE_TYPE] = {};
+ struct bpf_cgroup_storage *old_storage[MAX_BPF_CGROUP_STORAGE_TYPE] = {};
enum bpf_cgroup_storage_type stype;
struct bpf_prog_list *pl;
bool pl_was_allocated;