Skip to content

Commit e7a608a

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 e7a608a

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

kernel/bpf/log.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -705,11 +705,12 @@ static void print_reg_state(struct bpf_verifier_env *env,
705705
if (type_is_non_owning_ref(reg->type))
706706
verbose_a("%s", "non_own_ref");
707707
if (type_is_map_ptr(t)) {
708-
if (reg->map_ptr->name[0])
708+
if (reg->map_ptr != NULL && reg->map_ptr->name[0] != '\0')
709709
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);
710+
if (reg->map_ptr != NULL)
711+
verbose_a("ks=%d,vs=%d",
712+
reg->map_ptr->key_size,
713+
reg->map_ptr->value_size);
713714
}
714715
if (t != SCALAR_VALUE && reg->off) {
715716
verbose_a("off=");

0 commit comments

Comments
 (0)