[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20250923164144.1573636-1-listout@listout.xyz>
Date: Tue, 23 Sep 2025 22:11:44 +0530
From: Brahmajit Das <listout@...tout.xyz>
To: syzbot+d36d5ae81e1b0a53ef58@...kaller.appspotmail.com
Cc: listout@...tout.xyz,
andrii@...nel.org,
ast@...nel.org,
bpf@...r.kernel.org,
daniel@...earbox.net,
eddyz87@...il.com,
haoluo@...gle.com,
john.fastabend@...il.com,
jolsa@...nel.org,
kpsingh@...nel.org,
linux-kernel@...r.kernel.org,
martin.lau@...ux.dev,
sdf@...ichev.me,
song@...nel.org,
syzkaller-bugs@...glegroups.com,
yonghong.song@...ux.dev
Subject: [PATCH 1/1] bpf: fix NULL pointer dereference in print_reg_state()
Syzkaller reported a general protection fault due to a NULL pointer
dereference in print_reg_state() when accessing reg->map_ptr without
checking if it is NULL.
The existing code assumes reg->map_ptr is always valid before
dereferencing reg->map_ptr->name, reg->map_ptr->key_size, and
reg->map_ptr->value_size.
Fix this by adding explicit NULL checks before accessing reg->map_ptr
and its members. This prevents crashes when reg->map_ptr is NULL,
improving the robustness of the BPF verifier's verbose logging.
Reported-by: syzbot+d36d5ae81e1b0a53ef58@...kaller.appspotmail.com
Signed-off-by: Brahmajit Das <listout@...tout.xyz>
---
kernel/bpf/log.c | 10 ++++++----
1 file changed, 6 insertions(+), 4 deletions(-)
diff --git a/kernel/bpf/log.c b/kernel/bpf/log.c
index 38050f4ee400..a2368b21486a 100644
--- a/kernel/bpf/log.c
+++ b/kernel/bpf/log.c
@@ -3,6 +3,7 @@
* Copyright (c) 2016 Facebook
* Copyright (c) 2018 Covalent IO, Inc. http://covalent.io
*/
+#include "linux/printk.h"
#include <uapi/linux/btf.h>
#include <linux/kernel.h>
#include <linux/types.h>
@@ -716,11 +717,12 @@ static void print_reg_state(struct bpf_verifier_env *env,
if (type_is_non_owning_ref(reg->type))
verbose_a("%s", "non_own_ref");
if (type_is_map_ptr(t)) {
- if (reg->map_ptr->name[0])
+ if (reg->map_ptr != NULL && reg->map_ptr->name[0] != '\0')
verbose_a("map=%s", reg->map_ptr->name);
- verbose_a("ks=%d,vs=%d",
- reg->map_ptr->key_size,
- reg->map_ptr->value_size);
+ if (reg->map_ptr != NULL)
+ verbose_a("ks=%d,vs=%d",
+ reg->map_ptr->key_size,
+ reg->map_ptr->value_size);
}
if (t != SCALAR_VALUE && reg->off) {
verbose_a("off=");
--
2.51.0
Powered by blists - more mailing lists