Skip to contentSkip to conversation

KVM: arm64: Dump instruction on hyp panic

bug report Dan Carpenter 1 participant 1 message Sep 18, 2025

lore
Share & tools
lore
#0 lore raw

Hello Mostafa Saleh,

Commit 92b7624fe052 ("KVM: arm64: Dump instruction on hyp panic") from Sep 9, 2025 (linux-next), leads to the following Smatch static checker warning:

	arch/arm64/kernel/traps.c:219 die()
	warn: variable dereferenced before check 'regs' (see line 217)

arch/arm64/kernel/traps.c

    206 void die(const char *str, struct pt_regs *regs, long err)
    207 {
    208         int ret;
    209         unsigned long flags;
    210 
    211         raw_spin_lock_irqsave(&die_lock, flags);
    212 
    213         oops_enter();
    214 
    215         console_verbose();
    216         bust_spinlocks(1);
    217         ret = __die(str, err, regs);
                                      ^^^^

Prior to this patch, Smatch used to assume that perhaps a NULL "regs" would make notify_die() return NOTIFY_STOP so maybe we didn't dereference it. But now Smatch knows the dereference is unconditional.

    218 
--> 219         if (regs && kexec_should_crash(current))
                    ^^^^

Checked too late.

    220                 crash_kexec(regs);
    221 
    222         bust_spinlocks(0);
    223         add_taint(TAINT_DIE, LOCKDEP_NOW_UNRELIABLE);
    224         oops_exit();
    225 
    226         if (in_interrupt())
    227                 panic("%s: Fatal exception in interrupt", str);
    228         if (panic_on_oops)
    229                 panic("%s: Fatal exception", str);
    230 
    231         raw_spin_unlock_irqrestore(&die_lock, flags);
    232 
    233         if (ret != NOTIFY_STOP)
    234                 make_task_dead(SIGSEGV);
    235 }

regards,
dan carpenter