RISC-V: Avoid dereferening NULL regs in die()
PATCH 1/1 RISC-V: Avoid dereferening NULL regs in die()
I don't think we can actually die() without a regs pointer, but the compiler was warning about a NULL check after a dereference. It seems prudent to just avoid the possibly-NULL dereference, given that when die()ing the system is already toast so who knows how we got there.
--- arch/riscv/kernel/traps.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)
arch/riscv/kernel/traps.c +6 -3
@@ -33,6 +33,7 @@ void die(struct pt_regs *regs, const char *str) {static int die_counter;int ret; +long cause;oops_enter ();
@@ -42,11 +43,13 @@ void die(struct pt_regs *regs, const char *str)pr_emerg ("%s [#%d]\n" , str, ++die_counter);print_modules (); -show_regs (regs); +if (regs) +show_regs (regs); - ret =notify_die (DIE_OOPS , str, regs,0 , regs->cause,SIGSEGV ); + cause = regs ? regs->cause :-1 ; + ret =notify_die (DIE_OOPS , str, regs,0 , cause,SIGSEGV ); -if (regs &&kexec_should_crash (current)) +if (kexec_should_crash (current))crash_kexec (regs);bust_spinlocks (0 );
Signature · 7 lines
2.34.1 _______________________________________________ linux-riscv mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-riscv
Quoted 8 lines · Palmer Dabbelt
I don't think we can actually
die()without a regs pointer, but the compiler was warning about a NULL check after a dereference. It seems prudent to just avoid the possibly-NULL dereference, given that when die()ing the system is already toast so who knows how we got there.Reported-by kernel test robot <[email protected]>Reported-by Dan Carpenter <[email protected]>Signed-off-by Palmer Dabbelt <[email protected]>
I excitedly tried this in the hopes that I was actually hitting this somehow with the crash-during-boot-with-no-splat that I am currently bisecting, but sadly it was not the solution.
Either way it looks like a sane change so we at least can get something out in an edge failure case.
Quoted 21 lines
--- arch/riscv/kernel/traps.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)arch/riscv/kernel/traps.c +1
-1@@ -33,6 +33,7 @@ void die(struct pt_regs *regs, const char *str) {static int die_counter;int ret; +long cause;oops_enter ();@@ -42,11 +43,13 @@ void die(struct pt_regs *regs, const char *str)pr_emerg ("%s [#%d]\n" , str, ++die_counter);print_modules (); -show_regs (regs);
arch/riscv/kernel/traps.c void die(struct pt_regs *regs, const char *str) · line 53
Quoted 10 lines
arch/riscv/kernel/traps.c +5
-2+if (regs) +show_regs (regs); - ret =notify_die (DIE_OOPS , str, regs,0 , regs->cause,SIGSEGV ); + cause = regs ? regs->cause :-1 ; + ret =notify_die (DIE_OOPS , str, regs,0 , cause,SIGSEGV ); -if (regs &&kexec_should_crash (current)) +if (kexec_should_crash (current))crash_kexec (regs);
Had to go down the rabbit hole to see that there is an if(regs) around the eventual user of this, so:
Quoted 10 lines
arch/riscv/kernel/traps.c +0
-0bust_spinlocks (0 );Signature · 7 lines
2.34.1 _______________________________________________ linux-riscv mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-riscv
_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv
Palmer Dabbelt
AppliedQuoted 6 lines · Palmer Dabbelt
I don't think we can actually
die()without a regs pointer, but the compiler was warning about a NULL check after a dereference. It seems prudent to just avoid the possibly-NULL dereference, given that when die()ing the system is already toast so who knows how we got there.
Applied, thanks!
[1/1] RISC-V: Avoid dereferening NULL regs in die()
https://git.kernel.org/palmer/c/f2913d006fcd
Best regards,
Signature · 6 lines
Palmer Dabbelt <[email protected]> _______________________________________________ linux-riscv mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-riscv