Received: by 2002:a25:c205:0:0:0:0:0 with SMTP id s5csp3913713ybf; Tue, 3 Mar 2020 15:41:30 -0800 (PST) X-Google-Smtp-Source: ADFU+vt4ZNWA3/M0qgCEkFtlqZswG/2ccpKhMan63HT10c6I8QlTX+e08czUYokEIjYHtVctNKsE X-Received: by 2002:a9d:7088:: with SMTP id l8mr285780otj.208.1583278890582; Tue, 03 Mar 2020 15:41:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1583278890; cv=none; d=google.com; s=arc-20160816; b=KzY3gZdgGI3Yc71SfBqyd92ho46GYiJCzjJb0pkgbQM6x5XcE0RZKCrBX8k3LSIXCI 7SMgXsXDa2tXpFxp6Ea80YvfHHF0FCCHWp893q2LsGQKjwv80yhWaQVad6SyZ888oCEr VGtTdVBlql9iOAWi8+pF6CQgvAOZSSFCmomqVbeQ07UL1FuNSJY7hXezOav76PFzhFjS ie1ZnlVt6oY+FscgmiUiuiUBqZ3BBzwKAJnJhW5jQ2YZN3AIYcYVhbkj5M8UVTIeaI9v 2374rnXJjzm7gsK0Dqvw1jf/Lae1HInpIKdv7dNBiw89eJneeJE6ADIwlQUWCHJbX3We AUcQ== 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=zvsaXDMnNzpukwS09vhYK0Tda7k5jgkwbqgnwZf0grU=; b=0elSewy77yKV/WlF1T2Ok8hx3Jwxf0XfaxRq6OXVt2zPe7IW/nXTlFy3YCBoMNgO/o FRvR274eeTfq3SLzSswlJvhQcBG247auq50Y5CaGprbAzK27f2TwjsCJYGXVu61lnxlX NMXxOQ0B+nrOmiE1q68Bf4Zue4QCK45H5jn8UQUeUHtLjlwU/MN2RFLL9JC6pMVAjXmP 74uNJ6ubsXnzpzbLRLtF8h9cwktM5vJQLh+Vq+gN+1IDr5FegwkWEYQLG/2rEahOB49v XKgjNoklw0whhIM2QAZUJQ3I7W0vaFvegLjPC86VDHQ8U8Nd7Tv7fMyz8ugVIuYsX6wB CkUg== 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 y8si80228otq.122.2020.03.03.15.41.19; Tue, 03 Mar 2020 15:41:30 -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 S1728946AbgCCXj5 (ORCPT + 99 others); Tue, 3 Mar 2020 18:39:57 -0500 Received: from mga02.intel.com ([134.134.136.20]:53544 "EHLO mga02.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728366AbgCCXj4 (ORCPT ); Tue, 3 Mar 2020 18:39:56 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by orsmga101.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 03 Mar 2020 15:39:56 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.70,511,1574150400"; d="scan'208";a="440790374" Received: from kwasilew-mobl.ger.corp.intel.com (HELO localhost) ([10.251.88.57]) by fmsmga006.fm.intel.com with ESMTP; 03 Mar 2020 15:39:49 -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 v28 19/22] x86/fault: Add helper function to sanitize error code Date: Wed, 4 Mar 2020 01:36:06 +0200 Message-Id: <20200303233609.713348-20-jarkko.sakkinen@linux.intel.com> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200303233609.713348-1-jarkko.sakkinen@linux.intel.com> References: <20200303233609.713348-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.25.0