[rh7] x86, mm, perf: Allow recursive faults from interrupts

Submitted by Andrey Ryabinin on Jan. 24, 2019, 3:44 p.m.

Details

Message ID 20190124154410.26637-1-aryabinin@virtuozzo.com
State New
Series "x86, mm, perf: Allow recursive faults from interrupts"
Headers show

Commit Message

Andrey Ryabinin Jan. 24, 2019, 3:44 p.m.
From: Peter Zijlstra <peterz@infradead.org>

Waiman managed to trigger a PMI while in a emulate_vsyscall() fault,
the PMI in turn managed to trigger a fault while obtaining a stack
trace. This triggered the sig_on_uaccess_error recursive fault logic
and killed the process dead.

Fix this by explicitly excluding interrupts from the recursive fault
logic.

Reported-and-Tested-by: Waiman Long <waiman.long@hp.com>
Fixes: e00b12e64be9 ("perf/x86: Further optimize copy_from_user_nmi()")
Cc: Aswin Chandramouleeswaran <aswin@hp.com>
Cc: Scott J Norton <scott.norton@hp.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Andy Lutomirski <luto@amacapital.net>
Cc: Arnaldo Carvalho de Melo <acme@ghostprotocols.net>
Cc: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Peter Zijlstra <peterz@infradead.org>
Link: http://lkml.kernel.org/r/20140110200603.GJ7572@laptop.programming.kicks-ass.net
Signed-off-by: Ingo Molnar <mingo@kernel.org>
(cherry picked from commit c026b3591e4f2a4993df773183704bb31634e0bd)
Signed-off-by: Andrey Ryabinin <aryabinin@virtuozzo.com>
---
 arch/x86/mm/fault.c | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

Patch hide | download patch | download mbox

diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c
index 0e41582126a9..5a8f2cf83164 100644
--- a/arch/x86/mm/fault.c
+++ b/arch/x86/mm/fault.c
@@ -687,6 +687,20 @@  no_context(struct pt_regs *regs, unsigned long error_code,
 
 	/* Are we prepared to handle this kernel fault? */
 	if (fixup_exception(regs)) {
+		/*
+		 * Any interrupt that takes a fault gets the fixup. This makes
+		 * the below recursive fault logic only apply to a faults from
+		 * task context.
+		 */
+		if (in_interrupt())
+			return;
+
+		/*
+		 * Per the above we're !in_interrupt(), aka. task context.
+		 *
+		 * In this case we need to make sure we're not recursively
+		 * faulting through the emulate_vsyscall() logic.
+		 */
 		if (current_thread_info()->sig_on_uaccess_error && signal) {
 			tsk->thread.trap_nr = X86_TRAP_PF;
 			tsk->thread.error_code = error_code | X86_PF_USER;
@@ -696,6 +710,10 @@  no_context(struct pt_regs *regs, unsigned long error_code,
 			force_sig_info_fault(signal, si_code, address,
 					     tsk, vma, 0);
 		}
+
+		/*
+		 * Barring that, we can do the fixup and be happy.
+		 */
 		return;
 	}
 

Comments

Andrey Ryabinin Jan. 24, 2019, 3:45 p.m.
This is RK-worthy, please consider.


On 1/24/19 6:44 PM, Andrey Ryabinin wrote:
> From: Peter Zijlstra <peterz@infradead.org>
> 
> Waiman managed to trigger a PMI while in a emulate_vsyscall() fault,
> the PMI in turn managed to trigger a fault while obtaining a stack
> trace. This triggered the sig_on_uaccess_error recursive fault logic
> and killed the process dead.
> 
> Fix this by explicitly excluding interrupts from the recursive fault
> logic.
> 
> Reported-and-Tested-by: Waiman Long <waiman.long@hp.com>
> Fixes: e00b12e64be9 ("perf/x86: Further optimize copy_from_user_nmi()")
> Cc: Aswin Chandramouleeswaran <aswin@hp.com>
> Cc: Scott J Norton <scott.norton@hp.com>
> Cc: Linus Torvalds <torvalds@linux-foundation.org>
> Cc: Andy Lutomirski <luto@amacapital.net>
> Cc: Arnaldo Carvalho de Melo <acme@ghostprotocols.net>
> Cc: Andrew Morton <akpm@linux-foundation.org>
> Signed-off-by: Peter Zijlstra <peterz@infradead.org>
> Link: http://lkml.kernel.org/r/20140110200603.GJ7572@laptop.programming.kicks-ass.net
> Signed-off-by: Ingo Molnar <mingo@kernel.org>
> (cherry picked from commit c026b3591e4f2a4993df773183704bb31634e0bd)
> Signed-off-by: Andrey Ryabinin <aryabinin@virtuozzo.com>
> ---
>  arch/x86/mm/fault.c | 18 ++++++++++++++++++
>  1 file changed, 18 insertions(+)
> 
> diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c
> index 0e41582126a9..5a8f2cf83164 100644
> --- a/arch/x86/mm/fault.c
> +++ b/arch/x86/mm/fault.c
> @@ -687,6 +687,20 @@ no_context(struct pt_regs *regs, unsigned long error_code,
>  
>  	/* Are we prepared to handle this kernel fault? */
>  	if (fixup_exception(regs)) {
> +		/*
> +		 * Any interrupt that takes a fault gets the fixup. This makes
> +		 * the below recursive fault logic only apply to a faults from
> +		 * task context.
> +		 */
> +		if (in_interrupt())
> +			return;
> +
> +		/*
> +		 * Per the above we're !in_interrupt(), aka. task context.
> +		 *
> +		 * In this case we need to make sure we're not recursively
> +		 * faulting through the emulate_vsyscall() logic.
> +		 */
>  		if (current_thread_info()->sig_on_uaccess_error && signal) {
>  			tsk->thread.trap_nr = X86_TRAP_PF;
>  			tsk->thread.error_code = error_code | X86_PF_USER;
> @@ -696,6 +710,10 @@ no_context(struct pt_regs *regs, unsigned long error_code,
>  			force_sig_info_fault(signal, si_code, address,
>  					     tsk, vma, 0);
>  		}
> +
> +		/*
> +		 * Barring that, we can do the fixup and be happy.
> +		 */
>  		return;
>  	}
>  
>
Andrey Ryabinin Jan. 24, 2019, 3:45 p.m.
On 1/24/19 6:44 PM, Andrey Ryabinin wrote:
> From: Peter Zijlstra <peterz@infradead.org>
> 
> Waiman managed to trigger a PMI while in a emulate_vsyscall() fault,
> the PMI in turn managed to trigger a fault while obtaining a stack
> trace. This triggered the sig_on_uaccess_error recursive fault logic
> and killed the process dead.
> 
> Fix this by explicitly excluding interrupts from the recursive fault
> logic.
> 
> Reported-and-Tested-by: Waiman Long <waiman.long@hp.com>
> Fixes: e00b12e64be9 ("perf/x86: Further optimize copy_from_user_nmi()")
> Cc: Aswin Chandramouleeswaran <aswin@hp.com>
> Cc: Scott J Norton <scott.norton@hp.com>
> Cc: Linus Torvalds <torvalds@linux-foundation.org>
> Cc: Andy Lutomirski <luto@amacapital.net>
> Cc: Arnaldo Carvalho de Melo <acme@ghostprotocols.net>
> Cc: Andrew Morton <akpm@linux-foundation.org>
> Signed-off-by: Peter Zijlstra <peterz@infradead.org>
> Link: http://lkml.kernel.org/r/20140110200603.GJ7572@laptop.programming.kicks-ass.net
> Signed-off-by: Ingo Molnar <mingo@kernel.org>

https://jira.sw.ru/browse/PSBM-91181

> (cherry picked from commit c026b3591e4f2a4993df773183704bb31634e0bd)
> Signed-off-by: Andrey Ryabinin <aryabinin@virtuozzo.com>
> ---