summaryrefslogtreecommitdiffstats
path: root/kernel/bpf
diff options
context:
space:
mode:
authorAlexei Starovoitov <ast@kernel.org>2023-04-12 19:12:52 +0200
committerAndrii Nakryiko <andrii@kernel.org>2023-04-12 19:27:50 +0200
commit10fd5f70c397782a97f411f25bfb312ea92b55bc (patch)
tree8335b40df812119d6636e096da5d0ff359981f16 /kernel/bpf
parentselftests/bpf: Add test to access u32 ptr argument in tracing program (diff)
downloadlinux-10fd5f70c397782a97f411f25bfb312ea92b55bc.tar.xz
linux-10fd5f70c397782a97f411f25bfb312ea92b55bc.zip
bpf: Handle NULL in bpf_local_storage_free.
During OOM bpf_local_storage_alloc() may fail to allocate 'storage' and call to bpf_local_storage_free() with NULL pointer will cause a crash like: [ 271718.917646] BUG: kernel NULL pointer dereference, address: 00000000000000a0 [ 271719.019620] RIP: 0010:call_rcu+0x2d/0x240 [ 271719.216274] bpf_local_storage_alloc+0x19e/0x1e0 [ 271719.250121] bpf_local_storage_update+0x33b/0x740 Fixes: 7e30a8477b0b ("bpf: Add bpf_local_storage_free()") Signed-off-by: Alexei Starovoitov <ast@kernel.org> Signed-off-by: Andrii Nakryiko <andrii@kernel.org> Link: https://lore.kernel.org/bpf/20230412171252.15635-1-alexei.starovoitov@gmail.com
Diffstat (limited to 'kernel/bpf')
-rw-r--r--kernel/bpf/bpf_local_storage.c3
1 files changed, 3 insertions, 0 deletions
diff --git a/kernel/bpf/bpf_local_storage.c b/kernel/bpf/bpf_local_storage.c
index dab2ff4c99d9..47d9948d768f 100644
--- a/kernel/bpf/bpf_local_storage.c
+++ b/kernel/bpf/bpf_local_storage.c
@@ -157,6 +157,9 @@ static void bpf_local_storage_free(struct bpf_local_storage *local_storage,
struct bpf_local_storage_map *smap,
bool bpf_ma, bool reuse_now)
{
+ if (!local_storage)
+ return;
+
if (!bpf_ma) {
__bpf_local_storage_free(local_storage, reuse_now);
return;