x86/dumpstack: Do not try to access user space code of other tasks
authorThomas Gleixner <tglx@linutronix.de>
Tue, 17 Nov 2020 20:23:34 +0000 (21:23 +0100)
committerBorislav Petkov <bp@suse.de>
Wed, 18 Nov 2020 11:56:29 +0000 (12:56 +0100)
commit860aaabac8235cfde10fe556aa82abbbe3117888
tree1550e9572d7e46d9e527512cf005891a1f50dcf9
parent1a371e67dc77125736cc56d3a0893f06b75855b6
x86/dumpstack: Do not try to access user space code of other tasks

sysrq-t ends up invoking show_opcodes() for each task which tries to access
the user space code of other processes, which is obviously bogus.

It either manages to dump where the foreign task's regs->ip points to in a
valid mapping of the current task or triggers a pagefault and prints "Code:
Bad RIP value.". Both is just wrong.

Add a safeguard in copy_code() and check whether the @regs pointer matches
currents pt_regs. If not, do not even try to access it.

While at it, add commentary why using copy_from_user_nmi() is safe in
copy_code() even if the function name suggests otherwise.

Reported-by: Oleg Nesterov <oleg@redhat.com>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Borislav Petkov <bp@suse.de>
Reviewed-by: Borislav Petkov <bp@suse.de>
Acked-by: Oleg Nesterov <oleg@redhat.com>
Tested-by: Borislav Petkov <bp@suse.de>
Link: https://lkml.kernel.org/r/20201117202753.667274723@linutronix.de
arch/x86/kernel/dumpstack.c