Skip to content

Commit dbd63e8

Browse files
listoutKernel Patches Daemon
authored andcommitted
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: [email protected] Signed-off-by: Brahmajit Das <[email protected]>
1 parent f2c71e8 commit dbd63e8

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

kernel/bpf/log.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* Copyright (c) 2016 Facebook
44
* Copyright (c) 2018 Covalent IO, Inc. http://covalent.io
55
*/
6+
#include "linux/printk.h"
67
#include <uapi/linux/btf.h>
78
#include <linux/kernel.h>
89
#include <linux/types.h>
@@ -705,11 +706,12 @@ static void print_reg_state(struct bpf_verifier_env *env,
705706
if (type_is_non_owning_ref(reg->type))
706707
verbose_a("%s", "non_own_ref");
707708
if (type_is_map_ptr(t)) {
708-
if (reg->map_ptr->name[0])
709+
if (reg->map_ptr != NULL && reg->map_ptr->name[0] != '\0')
709710
verbose_a("map=%s", reg->map_ptr->name);
710-
verbose_a("ks=%d,vs=%d",
711-
reg->map_ptr->key_size,
712-
reg->map_ptr->value_size);
711+
if (reg->map_ptr != NULL)
712+
verbose_a("ks=%d,vs=%d",
713+
reg->map_ptr->key_size,
714+
reg->map_ptr->value_size);
713715
}
714716
if (t != SCALAR_VALUE && reg->off) {
715717
verbose_a("off=");

0 commit comments

Comments
 (0)