Received: by 2002:ac0:bc90:0:0:0:0:0 with SMTP id a16csp721894img; Wed, 20 Mar 2019 09:28:20 -0700 (PDT) X-Google-Smtp-Source: APXvYqy1BcqDHFlqAW7cz0cPVCll2wKiGL0He97FI1MUqV8T/VV1pENHv+Vg2TsaUxGCU7t5quY4 X-Received: by 2002:a17:902:bb86:: with SMTP id m6mr8956546pls.4.1553099300626; Wed, 20 Mar 2019 09:28:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553099300; cv=none; d=google.com; s=arc-20160816; b=w81VVYrVK6xpKvj7jzclocJxrbXdqOuV2EplIHdcJS9ttOZxdbhnGPtzXNUVoazzZ4 u4Mtn7nMUl8eGea7WzcdOS02IKrqVeyYfPBWiNv4+7LrdkDGHURTyzrNFi0ZR+lLl79t x41zvGOj3Bmn2EWg+T/05xJ+gjghQwiuGaJpd8dQGq5JBnb524LgV8MvQxOoB7z4cLWM pFMCz39LOudu/CxIYp7DFucfIKbTvAGJrK6tPClxG8qZPlWtxMtjvdgsRNdr5+LvfXAh ogQmC93zMncRpkTdrEhzA1fWF7VYS6Er65L/ps8x5ibCN8f6JUxEN5MmBCsRm6Kyuv2n dhOw== 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=VMno1XDuJzlKYashZwrx7E2XRm7MXvbKI2qH9Eg6syY=; b=ZTSlO2a9+/k16dFBKul2njkRXG/0cNeGbDvEMyqyVO52KHhncl6n/2TI+Gl5ovj+em VviNn3nkTBFu5zMM6nDmisDh0oywyni5X1rwFML7dsxtCuvqjvEPt86X3qIu9QgBtXQF 8bqWw1+S24jIr6qkTL6kGn5QS3zurx8GmRDALvuKUkUKsJHRXow/1THv+KWv+TYqfaM8 jJlDKfTOo4Aki4/JM145YCBkNORka9CAwbO70YYBC8iOtjQyDIyhaGrh6lrTbQifxFxS ZeQmYfKjAWpUewVrfJyUxaCgIA/WdQFpKOsPBoPFx6ToO5ha/CUzHppuco+EPoJmzyBG kHsg== 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 s8si1848171pgp.140.2019.03.20.09.28.05; Wed, 20 Mar 2019 09:28:20 -0700 (PDT) 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 S1727676AbfCTQZg (ORCPT + 99 others); Wed, 20 Mar 2019 12:25:36 -0400 Received: from mga02.intel.com ([134.134.136.20]:39976 "EHLO mga02.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727089AbfCTQZg (ORCPT ); Wed, 20 Mar 2019 12:25:36 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga003.jf.intel.com ([10.7.209.27]) by orsmga101.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 20 Mar 2019 09:25:35 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.60,249,1549958400"; d="scan'208";a="135715759" Received: from sorenthe-mobl1.ger.corp.intel.com (HELO localhost) ([10.249.254.203]) by orsmga003.jf.intel.com with ESMTP; 20 Mar 2019 09:25:26 -0700 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, serge.ayoun@intel.com, shay.katz-zamir@intel.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 Subject: [PATCH v19,RESEND 21/27] x86/fault: Add helper function to sanitize error code Date: Wed, 20 Mar 2019 18:21:13 +0200 Message-Id: <20190320162119.4469-22-jarkko.sakkinen@linux.intel.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20190320162119.4469-1-jarkko.sakkinen@linux.intel.com> References: <20190320162119.4469-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 ...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 --- 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 78e2807fbede..5babd515f616 100644 --- a/arch/x86/mm/fault.c +++ b/arch/x86/mm/fault.c @@ -719,6 +719,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) { @@ -771,6 +783,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 +934,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 +1053,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.1