Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp4908723pxv; Tue, 6 Jul 2021 12:07:46 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxUkxwwcJjKGBDJEtwyLKa1WBcV39y6vBkjYuOkCwy12Pb5bsNb2uUY6bgR6mMqx5/px8GB X-Received: by 2002:a17:907:161e:: with SMTP id hb30mr8651626ejc.222.1625598466415; Tue, 06 Jul 2021 12:07:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1625598466; cv=none; d=google.com; s=arc-20160816; b=sZ7VPCQCF4xi7c2Z+r6Z/Qm3M53ZjbzhEab3m6V9084MAi8nhSmaSSnEbbe0+dA+Jt G/eSuSYJWdPfGRnqjQC2NECo8RC6e7h9iB658UFvEk2NOjGhBY4QyfxBUdYPcbzhf1LM vlarSAhdieYPsi03o/UmqdhIQCILf+0paYsHDdBy+Q/WjHBJ8whMJJVxru9Y67hr5uLa WVQesz5FM0saJOdcqX9EnhwQ7p6Qhikcu1vbdpXZGODbnQTGijfMe4ED0dwXOY6F3bn4 bRn6u5u7rsgtRJ2sTalwAxSxOZLSj/Q3mWr8D3YERR8kKlMZaEbbSX2bZ4sEd+p+NXNh +I3g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=CEIpJuHifNtsxrP5bRoN395BKxnWJjVXvQrpzMUtHMw=; b=SKrpAU7Y7FEGRTZCRSyXGFp4ne04pU//9bVg85Tji1IOVBlhypy6qQitMgwzarVkNS uDEFvV/Op8l2OcnEVguufTKdYyS7M7sYyAKWx2QCeGBxM0ZpYRCzpO7+9soBdLh3sTlM hTydNbnJcMHOc1db8Pl8LqksMs0kYUm+vKqgThOpKSGNHw2OlxpHXfULruEkLcMbHJYB BqPSWi75dt2HBE/yX8Zj0mHPSm58Cn992r+rzUkmYIX3zSa4p8SZYlDLAPE2M61Uqpxe leZ0bJ+B/gwlnyVChzvl4eXz2vU8Fn123Jjx9eRh/3X40u5AQ+Svw796addFs+tZljpN jCmg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id p8si18911103edj.74.2021.07.06.12.07.21; Tue, 06 Jul 2021 12:07:46 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231698AbhGFTJI (ORCPT + 99 others); Tue, 6 Jul 2021 15:09:08 -0400 Received: from mga11.intel.com ([192.55.52.93]:6713 "EHLO mga11.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230071AbhGFTJH (ORCPT ); Tue, 6 Jul 2021 15:09:07 -0400 X-IronPort-AV: E=McAfee;i="6200,9189,10037"; a="206166879" X-IronPort-AV: E=Sophos;i="5.83,329,1616482800"; d="scan'208";a="206166879" Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Jul 2021 12:06:27 -0700 X-IronPort-AV: E=Sophos;i="5.83,329,1616482800"; d="scan'208";a="427687576" Received: from agluck-desk2.sc.intel.com ([10.3.52.146]) by orsmga002-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Jul 2021 12:06:26 -0700 From: Tony Luck To: Borislav Petkov Cc: Tony Luck , Ding Hui , naoya.horiguchi@nec.com, osalvador@suse.de, Youquan Song , huangcun@sangfor.com.cn, x86@kernel.org, linux-edac@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 1/3] x86/mce: Change to not send SIGBUS error during copy from user Date: Tue, 6 Jul 2021 12:06:18 -0700 Message-Id: <20210706190620.1290391-2-tony.luck@intel.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210706190620.1290391-1-tony.luck@intel.com> References: <20210706190620.1290391-1-tony.luck@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Sending a SIGBUS for a copy from user is not the correct semantic. System calls should return -EFAULT (or a short count for write(2)). Signed-off-by: Tony Luck --- arch/x86/kernel/cpu/mce/core.c | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/arch/x86/kernel/cpu/mce/core.c b/arch/x86/kernel/cpu/mce/core.c index 22791aadc085..dd03971e5ad5 100644 --- a/arch/x86/kernel/cpu/mce/core.c +++ b/arch/x86/kernel/cpu/mce/core.c @@ -1265,7 +1265,7 @@ static void kill_me_maybe(struct callback_head *cb) flags |= MF_MUST_KILL; ret = memory_failure(p->mce_addr >> PAGE_SHIFT, flags); - if (!ret && !(p->mce_kflags & MCE_IN_KERNEL_COPYIN)) { + if (!ret) { set_mce_nospec(p->mce_addr >> PAGE_SHIFT, p->mce_whole_page); sync_core(); return; @@ -1279,25 +1279,27 @@ static void kill_me_maybe(struct callback_head *cb) if (ret == -EHWPOISON) return; - if (p->mce_vaddr != (void __user *)-1l) { - force_sig_mceerr(BUS_MCEERR_AR, p->mce_vaddr, PAGE_SHIFT); - } else { - pr_err("Memory error not recovered"); - kill_me_now(cb); - } + pr_err("Memory error not recovered"); + kill_me_now(cb); +} + +static void kill_me_never(struct callback_head *cb) +{ + struct task_struct *p = container_of(cb, struct task_struct, mce_kill_me); + + pr_err("Kernel accessed poison in user space at %llx\n", p->mce_addr); + if (!memory_failure(p->mce_addr >> PAGE_SHIFT, 0)) + set_mce_nospec(p->mce_addr >> PAGE_SHIFT, p->mce_whole_page); } -static void queue_task_work(struct mce *m, int kill_current_task) +static void queue_task_work(struct mce *m, void (*func)(struct callback_head *)) { current->mce_addr = m->addr; current->mce_kflags = m->kflags; current->mce_ripv = !!(m->mcgstatus & MCG_STATUS_RIPV); current->mce_whole_page = whole_page(m); - if (kill_current_task) - current->mce_kill_me.func = kill_me_now; - else - current->mce_kill_me.func = kill_me_maybe; + current->mce_kill_me.func = func; task_work_add(current, ¤t->mce_kill_me, TWA_RESUME); } @@ -1435,7 +1437,10 @@ noinstr void do_machine_check(struct pt_regs *regs) /* If this triggers there is no way to recover. Die hard. */ BUG_ON(!on_thread_stack() || !user_mode(regs)); - queue_task_work(&m, kill_current_task); + if (kill_current_task) + queue_task_work(&m, kill_me_now); + else + queue_task_work(&m, kill_me_maybe); } else { /* @@ -1453,7 +1458,7 @@ noinstr void do_machine_check(struct pt_regs *regs) } if (m.kflags & MCE_IN_KERNEL_COPYIN) - queue_task_work(&m, kill_current_task); + queue_task_work(&m, kill_me_never); } out: mce_wrmsrl(MSR_IA32_MCG_STATUS, 0); -- 2.29.2