Re: [PATCH 1/1] bpf: fix NULL pointer dereference in print_reg_state()
From: Alexei Starovoitov
Date: Tue Sep 23 2025 - 14:52:39 EST
On Tue, Sep 23, 2025 at 9:44 AM Brahmajit Das <listout@xxxxxxxxxxx> wrote:
>
> 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@xxxxxxxxxxxxxxxxxxxxxxxxx
> Signed-off-by: Brahmajit Das <listout@xxxxxxxxxxx>
> ---
> kernel/bpf/log.c | 9 +++++----
> 1 file changed, 5 insertions(+), 4 deletions(-)
>
> diff --git a/kernel/bpf/log.c b/kernel/bpf/log.c
> index 38050f4ee400..b38efbbf22cf 100644
> --- a/kernel/bpf/log.c
> +++ b/kernel/bpf/log.c
> @@ -716,11 +716,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);
Looks like you're bandaiding a symptome instead of fixing
underlying issue. For map types map_ptr should always be set.
pw-bot: cr