Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp244377pxk; Fri, 11 Sep 2020 05:53:57 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxL5EuY+viUqg10UNyjUC10GuFF1WHStbg6TTNk2LgjVCYq6/LkgZcZvZx5fyDIFYQvSp0o X-Received: by 2002:a17:906:6158:: with SMTP id p24mr1859718ejl.35.1599828837172; Fri, 11 Sep 2020 05:53:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1599828837; cv=none; d=google.com; s=arc-20160816; b=DudvrkCCNEvPOq0OfdI0wQxEQC8WCPQcI7Q5uEiR+Cy/4m4E2lU3LJ5oNelOWS4aSL WwxwnXP7Yh5+FI2K1FJjdz1EMFoAFYqgjkzwRcHufNNo0V/W/zxhK4phgQcd7q8lk/jw VoVx768mJWAOwEiKOk5rsAGVxHnxeRl4XkjJDfALLDEKdHCrJpmlqxZmrPMeDn3Dh4fu pMrlgSRESkuxoDWQb7yVOywIMLMwD0/NayER5cYor22zkY07soqKnITbzyxKYM8yjOYx utMRQ46upVG1iq9CA+/+ttJGCCWvIBMmdmWy7NVBQrO4XUqKSWrkT0nnoAX0ZXi3SNmK 3xZw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :ironport-sdr:ironport-sdr; bh=KNaeZ0++0+eI/t4oPbp7MTW/KkSMPaG3lcfgaHbPxbw=; b=oeiyyKowIOphVEFeWPagZk5S+p7SU+5qpcuwNLHB79gUfQdI6rckx0WODgPFKMQ2XY SVRpMBn9rRsI7ceBBrPh1+zKwOzkfdc6FKkOOqhF4uSFphzuyiVpvTy/HJcmtdtvbVdf 2Mt6p5SCSiUG09dhelzo8ZnUaQMrVShb781HJgLWVZfsp4BD/cJ/+l+dbMLaYTS2q5zi OfdCgd6ZsbAJIcTFTti4Mz5CLVNynHAsbFRrIxnEZV/MvCw1RFNDom6I3aSz+FwJoHkH zUp8t30D5Qv7WloOWyU+XkEQhozuXE52HYlvhd4iN3VJdJc/0jDuxOQcR7uKYyA/9lJK y5Lg== 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 c8si1366382edn.87.2020.09.11.05.53.32; Fri, 11 Sep 2020 05:53:57 -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 S1726013AbgIKMtq (ORCPT + 99 others); Fri, 11 Sep 2020 08:49:46 -0400 Received: from mga12.intel.com ([192.55.52.136]:22783 "EHLO mga12.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725958AbgIKMss (ORCPT ); Fri, 11 Sep 2020 08:48:48 -0400 IronPort-SDR: y1ETna1DXP89RkmEsXwuqlxMZmAVEGHGIMexfzw1Dfusf/ZBdzo1zH3BGat76z3i40TwXXvc1H +LUHDXrzc5kA== X-IronPort-AV: E=McAfee;i="6000,8403,9740"; a="138262313" X-IronPort-AV: E=Sophos;i="5.76,415,1592895600"; d="scan'208";a="138262313" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Sep 2020 05:45:32 -0700 IronPort-SDR: qt+8dQq45LlzbEqSOT1InL5mKdeBLBLj8/mgXZ2s50Ar9VQYXAlgNqCbonGXdxnwAamq5a0c/9 ynMFQTPFkk+g== X-IronPort-AV: E=Sophos;i="5.76,415,1592895600"; d="scan'208";a="286885816" Received: from amaksymi-mobl.ger.corp.intel.com (HELO localhost) ([10.252.60.247]) by fmsmga008-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Sep 2020 05:45:20 -0700 From: Jarkko Sakkinen To: x86@kernel.org, linux-sgx@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Sean Christopherson , Jethro Beekman , Jarkko Sakkinen , akpm@linux-foundation.org, andriy.shevchenko@linux.intel.com, asapek@google.com, bp@alien8.de, cedric.xing@intel.com, chenalexchen@google.com, conradparker@google.com, cyhanish@google.com, dave.hansen@intel.com, haitao.huang@intel.com, josh@joshtriplett.org, kai.huang@intel.com, kai.svahn@intel.com, kmoy@google.com, ludloff@google.com, luto@kernel.org, nhorman@redhat.com, npmccallum@redhat.com, puiterwijk@redhat.com, rientjes@google.com, tglx@linutronix.de, yaozhangx@google.com Subject: [PATCH v37 19/24] x86/fault: Add helper function to sanitize error code Date: Fri, 11 Sep 2020 15:40:14 +0300 Message-Id: <20200911124019.42178-20-jarkko.sakkinen@linux.intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200911124019.42178-1-jarkko.sakkinen@linux.intel.com> References: <20200911124019.42178-1-jarkko.sakkinen@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Sean Christopherson Add helper function to sanitize error code to prepare for vDSO exception fixup, which will expose the error code to userspace and runs before set_signal_archinfo(), i.e. suppresses the signal when fixup is successful. Acked-by: Jethro Beekman Signed-off-by: Sean Christopherson Signed-off-by: Jarkko Sakkinen --- arch/x86/mm/fault.c | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c index 1a7cc6d3281a..9e5ec861aba0 100644 --- a/arch/x86/mm/fault.c +++ b/arch/x86/mm/fault.c @@ -555,6 +555,18 @@ pgtable_bad(struct pt_regs *regs, unsigned long error_code, oops_end(flags, regs, sig); } +static void sanitize_error_code(unsigned long address, + unsigned long *error_code) +{ + /* + * To avoid leaking information about the kernel page + * table layout, pretend that user-mode accesses to + * kernel addresses are always protection faults. + */ + if (address >= TASK_SIZE_MAX) + *error_code |= X86_PF_PROT; +} + static void set_signal_archinfo(unsigned long address, unsigned long error_code) { @@ -611,6 +623,8 @@ no_context(struct pt_regs *regs, unsigned long error_code, * faulting through the emulate_vsyscall() logic. */ 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. */ @@ -759,13 +773,7 @@ __bad_area_nosemaphore(struct pt_regs *regs, unsigned long error_code, if (is_errata100(regs, address)) return; - /* - * To avoid leaking information about the kernel page table - * layout, pretend that user-mode accesses to kernel addresses - * are always protection faults. - */ - if (address >= TASK_SIZE_MAX) - error_code |= X86_PF_PROT; + sanitize_error_code(address, &error_code); if (likely(show_unhandled_signals)) show_signal_msg(regs, error_code, address, tsk); @@ -884,6 +892,8 @@ do_sigbus(struct pt_regs *regs, unsigned long error_code, unsigned long address, if (is_prefetch(regs, error_code, address)) return; + sanitize_error_code(address, &error_code); + set_signal_archinfo(address, error_code); #ifdef CONFIG_MEMORY_FAILURE -- 2.25.1