linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] x86/fault: Send a SIGBUS to user process always for hwpoison page access.
@ 2021-02-01  8:17 Aili Yao
  2021-02-01 16:58 ` Andy Lutomirski
  2021-02-04  7:25 ` HORIGUCHI NAOYA(堀口 直也)
  0 siblings, 2 replies; 31+ messages in thread
From: Aili Yao @ 2021-02-01  8:17 UTC (permalink / raw)
  To: tony.luck, dave.hansen, luto, peterz, tglx, mingo, bp,
	naoya.horiguchi, hpa, x86, hpa
  Cc: YANGFENG1, linux-mm, linux-kernel

When one page is already hwpoisoned by AO action, process may not be
killed, the process mapping this page may make a syscall include this
page and result to trigger a VM_FAULT_HWPOISON fault, if it's in kernel
mode it may be fixed by fixup_exception. Current code will just return
error code to user process.

This is not sufficient, we should send a SIGBUS to the process and log
the info to console, as we can't trust the process will handle the error
correctly.

Suggested-by: Feng Yang <yangfeng1@kingsoft.com>
Signed-off-by: Aili Yao <yaoaili@kingsoft.com>
---
 arch/x86/mm/fault.c | 34 +++++++++++++++++++++++++++-------
 1 file changed, 27 insertions(+), 7 deletions(-)

diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c
index f1f1b5a0956a..23095b94cf42 100644
--- a/arch/x86/mm/fault.c
+++ b/arch/x86/mm/fault.c
@@ -631,7 +631,7 @@ static void set_signal_archinfo(unsigned long address,
 
 static noinline void
 no_context(struct pt_regs *regs, unsigned long error_code,
-	   unsigned long address, int signal, int si_code)
+	   unsigned long address, int signal, int si_code, vm_fault_t fault)
 {
 	struct task_struct *tsk = current;
 	unsigned long flags;
@@ -662,12 +662,32 @@ no_context(struct pt_regs *regs, unsigned long error_code,
 		 * In this case we need to make sure we're not recursively
 		 * faulting through the emulate_vsyscall() logic.
 		 */
+
+		if (IS_ENABLED(CONFIG_MEMORY_FAILURE) &&
+		    fault & (VM_FAULT_HWPOISON|VM_FAULT_HWPOISON_LARGE)) {
+			unsigned int lsb = 0;
+
+			pr_err("MCE: Killing %s:%d due to hardware memory corruption fault at %lx\n",
+				current->comm, current->pid, address);
+
+			sanitize_error_code(address, &error_code);
+			set_signal_archinfo(address, error_code);
+
+			if (fault & VM_FAULT_HWPOISON_LARGE)
+				lsb = hstate_index_to_shift(VM_FAULT_GET_HINDEX(fault));
+			if (fault & VM_FAULT_HWPOISON)
+				lsb = PAGE_SHIFT;
+
+			force_sig_mceerr(BUS_MCEERR_AR, (void __user *)address, lsb);
+
+			return;
+		}
+
 		if (current->thread.sig_on_uaccess_err && signal) {
 			sanitize_error_code(address, &error_code);
 
 			set_signal_archinfo(address, error_code);
 
-			/* XXX: hwpoison faults will set the wrong code. */
 			force_sig_fault(signal, si_code, (void __user *)address);
 		}
 
@@ -836,7 +856,7 @@ __bad_area_nosemaphore(struct pt_regs *regs, unsigned long error_code,
 	if (is_f00f_bug(regs, address))
 		return;
 
-	no_context(regs, error_code, address, SIGSEGV, si_code);
+	no_context(regs, error_code, address, SIGSEGV, si_code, 0);
 }
 
 static noinline void
@@ -927,7 +947,7 @@ do_sigbus(struct pt_regs *regs, unsigned long error_code, unsigned long address,
 {
 	/* Kernel mode? Handle exceptions or die: */
 	if (!(error_code & X86_PF_USER)) {
-		no_context(regs, error_code, address, SIGBUS, BUS_ADRERR);
+		no_context(regs, error_code, address, SIGBUS, BUS_ADRERR, fault);
 		return;
 	}
 
@@ -966,7 +986,7 @@ mm_fault_error(struct pt_regs *regs, unsigned long error_code,
 	       unsigned long address, vm_fault_t fault)
 {
 	if (fatal_signal_pending(current) && !(error_code & X86_PF_USER)) {
-		no_context(regs, error_code, address, 0, 0);
+		no_context(regs, error_code, address, 0, 0, 0);
 		return;
 	}
 
@@ -974,7 +994,7 @@ mm_fault_error(struct pt_regs *regs, unsigned long error_code,
 		/* Kernel mode? Handle exceptions or die: */
 		if (!(error_code & X86_PF_USER)) {
 			no_context(regs, error_code, address,
-				   SIGSEGV, SEGV_MAPERR);
+				   SIGSEGV, SEGV_MAPERR, 0);
 			return;
 		}
 
@@ -1396,7 +1416,7 @@ void do_user_addr_fault(struct pt_regs *regs,
 	if (fault_signal_pending(fault, regs)) {
 		if (!user_mode(regs))
 			no_context(regs, hw_error_code, address, SIGBUS,
-				   BUS_ADRERR);
+				   BUS_ADRERR, 0);
 		return;
 	}
 
-- 
2.25.1



^ permalink raw reply related	[flat|nested] 31+ messages in thread

end of thread, other threads:[~2021-03-11 16:57 UTC | newest]

Thread overview: 31+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-02-01  8:17 [PATCH v2] x86/fault: Send a SIGBUS to user process always for hwpoison page access Aili Yao
2021-02-01 16:58 ` Andy Lutomirski
2021-02-01 21:10   ` Luck, Tony
2021-02-01 22:09     ` Andy Lutomirski
2021-02-02  6:42   ` Aili Yao
2021-02-04  7:25 ` HORIGUCHI NAOYA(堀口 直也)
2021-02-05  5:06   ` Aili Yao
2021-02-05  9:01   ` [PATCH v3] " Aili Yao
2021-02-23 12:44     ` Aili Yao
2021-02-23 15:33       ` Andy Lutomirski
2021-02-23 16:42         ` Luck, Tony
2021-02-25  4:47           ` Aili Yao
2021-02-27  3:40             ` Andy Lutomirski
2021-03-01  7:57               ` Aili Yao
2021-03-01 18:12                 ` Luck, Tony
2021-03-01 19:02               ` Luck, Tony
2021-03-01 19:09                 ` Andy Lutomirski
2021-03-03 12:24                   ` Aili Yao
2021-03-03 12:51                     ` Aili Yao
2021-03-07 19:16                       ` Andy Lutomirski
2021-03-08  9:49                         ` Aili Yao
2021-03-08 18:14                           ` Andy Lutomirski
2021-03-08 18:31                             ` Luck, Tony
2021-03-08 19:00                               ` Andy Lutomirski
2021-03-11  1:19                                 ` Aili Yao
2021-03-11  1:28                                   ` Andy Lutomirski
2021-03-11  2:01                                     ` Aili Yao
2021-03-11 16:52                                     ` Luck, Tony
2021-03-11 16:56                                       ` Peter Zijlstra
2021-03-09  2:14                               ` Aili Yao
2021-03-09  2:25                                 ` Aili Yao

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).