From patchwork Mon Feb 1 08:17:49 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?eWFvYWlsaSBb5LmI54ix5YipXQ==?= X-Patchwork-Id: 12058353 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-14.2 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,HK_RANDOM_FROM,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_SANE_2 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7050DC433E0 for ; Mon, 1 Feb 2021 08:18:05 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id C119464E33 for ; Mon, 1 Feb 2021 08:18:03 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C119464E33 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=kingsoft.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id C130E6B0006; Mon, 1 Feb 2021 03:18:02 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id BC34D6B006C; Mon, 1 Feb 2021 03:18:02 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id AB4666B006E; Mon, 1 Feb 2021 03:18:02 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0195.hostedemail.com [216.40.44.195]) by kanga.kvack.org (Postfix) with ESMTP id 95E266B0006 for ; Mon, 1 Feb 2021 03:18:02 -0500 (EST) Received: from smtpin08.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 6181C180AD822 for ; Mon, 1 Feb 2021 08:18:02 +0000 (UTC) X-FDA: 77768996004.08.grain82_1f13ed9275c0 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin08.hostedemail.com (Postfix) with ESMTP id 41D431819E773 for ; Mon, 1 Feb 2021 08:18:02 +0000 (UTC) X-HE-Tag: grain82_1f13ed9275c0 X-Filterd-Recvd-Size: 6603 Received: from mail.kingsoft.com (unknown [114.255.44.146]) by imf48.hostedemail.com (Postfix) with ESMTP for ; Mon, 1 Feb 2021 08:17:59 +0000 (UTC) X-AuditID: 0a580155-6fbff700000550c6-51-6017b2da19fb Received: from mail.kingsoft.com (localhost [10.88.1.32]) (using TLS with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client did not present a certificate) by mail.kingsoft.com (SMG-2-NODE-85) with SMTP id 64.A0.20678.AD2B7106; Mon, 1 Feb 2021 15:50:50 +0800 (HKT) Received: from aili-OptiPlex-7020 (172.16.253.254) by KSBJMAIL2.kingsoft.cn (10.88.1.32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1979.3; Mon, 1 Feb 2021 16:17:49 +0800 Date: Mon, 1 Feb 2021 16:17:49 +0800 From: Aili Yao To: , , , , , , , , , , CC: , , Subject: [PATCH v2] x86/fault: Send a SIGBUS to user process always for hwpoison page access. Message-ID: <20210201161749.0e8dc212.yaoaili@kingsoft.com> Organization: Kingsoft X-Mailer: Claws Mail 3.17.5 (GTK+ 2.24.32; x86_64-pc-linux-gnu) MIME-Version: 1.0 X-Originating-IP: [172.16.253.254] X-ClientProxiedBy: KSBJMAIL1.kingsoft.cn (10.88.1.31) To KSBJMAIL2.kingsoft.cn (10.88.1.32) X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrLLMWRmVeSWpSXmKPExsXCFcGooHtrk3iCwcNl8hafN/xjs3ixoZ3R YtpGcYvLu+awWdxb85/V4vyutawWlw4sYLK42HiA0eJ47wEmi82bpjJbvLlwj8Xix4bHrA48 Ht9b+1g8Nq/Q8li85yWTx6ZVnWwemz5NYvd4d+4cu8e8k4EeL65uZPF4v+8qm8fnTXIeJ1q+ sAZwR3HZpKTmZJalFunbJXBldC+azV6wSK5i+ZWLrA2MiyW6GDk5JARMJGbsvcDWxcjFISQw nUlix9JvTBDOc0aJWZf/sXcxcnCwCKhILHiTB9LAJqAqseveLFaQGhGBT4wSXxs+MYEkmAVC JO7MPswOYgsLxEt0zLnEAmLzClhJnDh6mQ1kDr+AmMSrBmOIxfYSz/+eZYYoEZQ4OfMJC8QY HYkTq44xQ9jyEtvfzgGzhQQUJQ4v+cUO0askcaR7BhuEHSuxbN4r1gmMgrOQjJqFZNQsJKMW MDKvYmQpzk032sQIiaHQHYwzmj7qHWJk4mA8xCjBwawkwntqkliCEG9KYmVValF+fFFpTmrx IUZpDhYlcd5yB74EIYH0xJLU7NTUgtQimCwTB6dUA1Oiinvx6tXSz2fdLJ5d9uzxguuf4344 PvwX41zxe7aBdPC/RYHb7n4U7s/7zNbL2nd74sfcfa+nJ36SZr+5JHTm7IdzHt3beKTBNn7C spfmDrcyfrzeKXsutf5/VP/MA2Eu0zOu2AQXZthuMe7tje3Le9YWNv2y6832S5LrVMsVeKL1 bmRrBBxyE5ItWeh9eYFwiljQjKcrm+tesHw+MLH1uZbJNoU3Pr+XWnBkRLirrWLKWOX4lf2n 3LwdMxnTrqpZfuTOzdMx6flVy3Uu9VKKl9tTvd7w/Wb9v5qShCel/V7G8PQ74zG10/6zedaq 8YVciU6MvuR9ty9cpbvVstzgicb52IKpDc5uArXvTJRYijMSDbWYi4oTAbtrBnoQAwAA X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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 Signed-off-by: Aili Yao --- 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; }