]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob - releases/2.6.37.5/x86-mm-handle-mm_fault_error-in-kernel-space.patch
fixes for 4.19
[thirdparty/kernel/stable-queue.git] / releases / 2.6.37.5 / x86-mm-handle-mm_fault_error-in-kernel-space.patch
1 From f86268549f424f83b9eb0963989270e14fbfc3de Mon Sep 17 00:00:00 2001
2 From: Andrey Vagin <avagin@openvz.org>
3 Date: Wed, 9 Mar 2011 15:22:23 -0800
4 Subject: x86/mm: Handle mm_fault_error() in kernel space
5
6 From: Andrey Vagin <avagin@openvz.org>
7
8 commit f86268549f424f83b9eb0963989270e14fbfc3de upstream.
9
10 mm_fault_error() should not execute oom-killer, if page fault
11 occurs in kernel space. E.g. in copy_from_user()/copy_to_user().
12
13 This would happen if we find ourselves in OOM on a
14 copy_to_user(), or a copy_from_user() which faults.
15
16 Without this patch, the kernels hangs up in copy_from_user(),
17 because OOM killer sends SIG_KILL to current process, but it
18 can't handle a signal while in syscall, then the kernel returns
19 to copy_from_user(), reexcute current command and provokes
20 page_fault again.
21
22 With this patch the kernel return -EFAULT from copy_from_user().
23
24 The code, which checks that page fault occurred in kernel space,
25 has been copied from do_sigbus().
26
27 This situation is handled by the same way on powerpc, xtensa,
28 tile, ...
29
30 Signed-off-by: Andrey Vagin <avagin@openvz.org>
31 Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
32 Cc: "H. Peter Anvin" <hpa@zytor.com>
33 Cc: Linus Torvalds <torvalds@linux-foundation.org>
34 LKML-Reference: <201103092322.p29NMNPH001682@imap1.linux-foundation.org>
35 Signed-off-by: Ingo Molnar <mingo@elte.hu>
36 Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
37
38 ---
39 arch/x86/mm/fault.c | 7 +++++++
40 1 file changed, 7 insertions(+)
41
42 --- a/arch/x86/mm/fault.c
43 +++ b/arch/x86/mm/fault.c
44 @@ -827,6 +827,13 @@ mm_fault_error(struct pt_regs *regs, uns
45 unsigned long address, unsigned int fault)
46 {
47 if (fault & VM_FAULT_OOM) {
48 + /* Kernel mode? Handle exceptions or die: */
49 + if (!(error_code & PF_USER)) {
50 + up_read(&current->mm->mmap_sem);
51 + no_context(regs, error_code, address);
52 + return;
53 + }
54 +
55 out_of_memory(regs, error_code, address);
56 } else {
57 if (fault & (VM_FAULT_SIGBUS|VM_FAULT_HWPOISON|