Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp36640imu; Fri, 14 Dec 2018 13:58:48 -0800 (PST) X-Google-Smtp-Source: AFSGD/VeYvZpgbhh61phZobSNYbHHo34QCbPomI/xtq5vk+n2L6W0NFDFzQgu+ukV+CmMX+GywkS X-Received: by 2002:a63:6782:: with SMTP id b124mr4224761pgc.151.1544824728369; Fri, 14 Dec 2018 13:58:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544824728; cv=none; d=google.com; s=arc-20160816; b=kXIuGicM/GmF8uoZ6K4Rj4g7m/fWxNWcplmX6JaSWRU7OIdjExQ8lJm4P+OxEhRdSk KBJ4yCUuRJsgjcHgA1QulrTP/nh5CoB4ggt3JaYWkGM9MDyrK1zR7j7ZlyfouW0DZ9h2 5prxSCYS5AwLJWcSx1mFVBPswAV9pDy8VgZ5A+ciHslf3Dm3yPcwX5EH6i+BB8eGR9nm kSwVTNdts08WtNajeW4hpLo2GrHNv9KAfFJQTIisEdbyQuZjDkz0U42LXcGZHiwcwZBS NGSLYDa1DsBXkTKKGh+UQo+zYY91JobGO5Try9+uDHgM4WShEHI6Z8a46eWwAnZfKJ9i 1Y2A== 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=UCTP3B3LPjq1jYPwIVHmF7QYRiKlEDM30BShpirfXAs=; b=araAAKonGWyTHN5QKtOZFWsOsFsxDjNnwpYIBAoKvDNieTnanznlMwHd90MwjQnHyn zrLHUYRibl4jtcOCztdtlQ+62UtRC8HMneDOmn32oBkTRFmpW8mN20EehcEzo+32IlB0 IooEbdSTDg/3SADtyQ+G7rFn+2bTHE9cRHAolzbUYIHLQlHjS+qU6e+mW8UVDwG1hAK0 j6qa7x57OMOy7XiYlRBLUSOqBu/oIUIVFSWVs2QcVP/iLkvlxZCq/cQ56fNEM8QEPx1A qaG8cIkFXBj0XC+HOw2vzjvTn8q9hiwcqjK2KzAJDautpfZ6kT00ruVpypHjnhTSgvgj 3CPQ== 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 5si5057473plx.391.2018.12.14.13.58.33; Fri, 14 Dec 2018 13:58:48 -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 S1731289AbeLNV5h (ORCPT + 99 others); Fri, 14 Dec 2018 16:57:37 -0500 Received: from mga01.intel.com ([192.55.52.88]:13311 "EHLO mga01.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731020AbeLNV5d (ORCPT ); Fri, 14 Dec 2018 16:57:33 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 14 Dec 2018 13:57:33 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.56,354,1539673200"; d="scan'208";a="118650669" Received: from sjchrist-coffee.jf.intel.com ([10.54.74.154]) by FMSMGA003.fm.intel.com with ESMTP; 14 Dec 2018 13:57:33 -0800 From: Sean Christopherson To: Andy Lutomirski , Thomas Gleixner , Ingo Molnar , Borislav Petkov , x86@kernel.org, Dave Hansen , Peter Zijlstra , Jarkko Sakkinen Cc: "H. Peter Anvin" , linux-kernel@vger.kernel.org, linux-sgx@vger.kernel.org, Andy Lutomirski , Josh Triplett , Haitao Huang , Jethro Beekman , "Dr . Greg Wettstein" Subject: [RFC PATCH v5 2/5] x86/fault: Add helper function to sanitize error code Date: Fri, 14 Dec 2018 13:57:26 -0800 Message-Id: <20181214215729.4221-3-sean.j.christopherson@intel.com> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20181214215729.4221-1-sean.j.christopherson@intel.com> References: <20181214215729.4221-1-sean.j.christopherson@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 ...to prepare for vDSO exception fixup, which will expose the error code to userspace and runs before set_signal_archinfo(), i.e. squashes the signal when fixup is successful. Signed-off-by: Sean Christopherson --- arch/x86/mm/fault.c | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c index 7e8a7558ca07..fefeb745d21d 100644 --- a/arch/x86/mm/fault.c +++ b/arch/x86/mm/fault.c @@ -719,18 +719,22 @@ pgtable_bad(struct pt_regs *regs, unsigned long error_code, oops_end(flags, regs, sig); } -static void set_signal_archinfo(unsigned long address, - unsigned long error_code) +static void sanitize_error_code(unsigned long address, + unsigned long *error_code) { - struct task_struct *tsk = current; - /* * 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; + *error_code |= X86_PF_PROT; +} + +static void set_signal_archinfo(unsigned long address, + unsigned long error_code) +{ + struct task_struct *tsk = current; tsk->thread.trap_nr = X86_TRAP_PF; tsk->thread.error_code = error_code | X86_PF_USER; @@ -771,6 +775,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. */ @@ -920,13 +926,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); @@ -1045,6 +1045,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.19.2