Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp3029453ybv; Sun, 9 Feb 2020 13:28:54 -0800 (PST) X-Google-Smtp-Source: APXvYqwsiKPBXJlAD/teQ0+ex5CdNEcjAgrn5l4MmwsoOK+QMfCC988n7fMi0LAqmadBUsDXX24R X-Received: by 2002:aca:cf07:: with SMTP id f7mr8981110oig.5.1581283734319; Sun, 09 Feb 2020 13:28:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1581283734; cv=none; d=google.com; s=arc-20160816; b=bdy8ZB46kJKxKWZooShTPBqMtGRsv+9w5XgI+tfchR9/Y1deYAQhQolm3g0iqYkeBq LRTTwXylKORS2pzUUd8lOACvwGDvI09VvdCX/elKbXPogiP34QHKuL9NNg3OEAU6f9sC LQ9pJ+A2NXFKS8EK/RVEzv730WOpkIwLvh/Q8ON/lGWgEcsZF5Bn0+zni1YL9uCky/O4 f7suyhhgRNGrcgOxXsTSpqHtn3X81DBMZK+oB9VvY1RJoWgX1HVOp53F5RwxD+Tpk032 41DmALDnIp/CA5ADIqQD61Aha/6kWMdqovHc2GkQtw7PC8hpK0BdW8aUshGX3Wj+VR5F vrYQ== 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; bh=EdchFwgr3LI0vLdhQTVBbUSC6AOBu6s7SKOc3vuWU0I=; b=U02szKx5ordxstARvKh2JH+huGGAmVDtFwjEqK23YGjdDeWjXJh6evEMYQ2AxZLmga wDVlfblXo6sUaT9Tp8mAGohGAaC1pskrfOVPfhaIxst+fczNI0upIeuMV+M8cma2INFl OH2ZQxsegHl56Mc2qiOnT8ts9U4Bo1bPOg0O2xJlKPVD5f4oD3VRooj1STWCEf7YDm7q BHLaz7p6z2Yj7cT6FLqgCt05aBD0UUSq186wqabKtGa3EzAIhBfBv8O9NRRdMc/mxRRr TuoDaCSbabE1ENA6q4L9SFBIRuaD6HMjDjm1mJuhwI1XXgd0Fg0VyjTxnJ2uWJHNNN9D ArWA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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. [209.132.180.67]) by mx.google.com with ESMTP id 38si3925775otu.166.2020.02.09.13.28.43; Sun, 09 Feb 2020 13:28:54 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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 S1726915AbgBIV2C (ORCPT + 99 others); Sun, 9 Feb 2020 16:28:02 -0500 Received: from mga04.intel.com ([192.55.52.120]:7318 "EHLO mga04.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726575AbgBIV2C (ORCPT ); Sun, 9 Feb 2020 16:28:02 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga104.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 09 Feb 2020 13:28:01 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.70,422,1574150400"; d="scan'208";a="405398919" Received: from jradtke-mobl1.ger.corp.intel.com (HELO localhost) ([10.252.22.75]) by orsmga005.jf.intel.com with ESMTP; 09 Feb 2020 13:27:56 -0800 From: Jarkko Sakkinen To: linux-kernel@vger.kernel.org, x86@kernel.org, linux-sgx@vger.kernel.org Cc: akpm@linux-foundation.org, dave.hansen@intel.com, sean.j.christopherson@intel.com, nhorman@redhat.com, npmccallum@redhat.com, haitao.huang@intel.com, andriy.shevchenko@linux.intel.com, tglx@linutronix.de, kai.svahn@intel.com, bp@alien8.de, josh@joshtriplett.org, luto@kernel.org, kai.huang@intel.com, rientjes@google.com, cedric.xing@intel.com, puiterwijk@redhat.com, Jarkko Sakkinen Subject: [PATCH v26 17/22] x86/fault: Add helper function to sanitize error code Date: Sun, 9 Feb 2020 23:26:04 +0200 Message-Id: <20200209212609.7928-18-jarkko.sakkinen@linux.intel.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200209212609.7928-1-jarkko.sakkinen@linux.intel.com> References: <20200209212609.7928-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. 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 dee9504cde79..6b662d272af6 100644 --- a/arch/x86/mm/fault.c +++ b/arch/x86/mm/fault.c @@ -682,6 +682,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) { @@ -738,6 +750,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. */ @@ -886,13 +900,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); @@ -1009,6 +1017,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.20.1