Re: [PATCH v2] x86/dumpstack: Fix misleading instruction pointer error message
From: Oleg Nesterov
Date: Tue Nov 03 2020 - 07:50:48 EST
On 10/02, Mark Mossberg wrote:
>
> Printing "Bad RIP value" if copy_code() fails can be misleading for
> userspace pointers, since copy_code() can fail if the instruction
> pointer is valid, but the code is paged out.
Another problem is that show_opcodes() makes no sense if user_mode(regs)
and tsk is not current. Try "echo t > /proc/sysrq-trigger".
In this case copy_from_user_nmi() will either fail, or (worse) it will
read the "random" memory from current->mm.
Perhaps we can add something like
if (user_mode(regs) && regs != task_pt_regs(current))
return;
at the start of show_opcodes() ?
> --- a/arch/x86/kernel/dumpstack.c
> +++ b/arch/x86/kernel/dumpstack.c
> @@ -115,7 +115,8 @@ void show_opcodes(struct pt_regs *regs, const char *loglvl)
> unsigned long prologue = regs->ip - PROLOGUE_SIZE;
>
> if (copy_code(regs, opcodes, prologue, sizeof(opcodes))) {
> - printk("%sCode: Bad RIP value.\n", loglvl);
> + printk("%sCode: Unable to access opcode bytes at RIP 0x%lx.\n",
> + loglvl, prologue);
> } else {
> printk("%sCode: %" __stringify(PROLOGUE_SIZE) "ph <%02x> %"
> __stringify(EPILOGUE_SIZE) "ph\n", loglvl, opcodes,
> --
> 2.25.1
>