Received: by 2002:a25:683:0:0:0:0:0 with SMTP id 125csp105525ybg; Sun, 31 May 2020 18:24:37 -0700 (PDT) X-Google-Smtp-Source: ABdhPJziQmc8I3W1MnoTU1u9d9izDsxUu4PISaBwCr/u+42uLR9x9g9JL9ZPZWYQ6+aErb9PzjFy X-Received: by 2002:a17:906:d8d7:: with SMTP id re23mr16678499ejb.22.1590974676895; Sun, 31 May 2020 18:24:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1590974676; cv=none; d=google.com; s=arc-20160816; b=vqAN+ddeGXuGuZyjU5r3CC45yzF9Jk3W8RpK4hIa00uBNXVBBUPhcD0Zqxe5lK6K6S iNQEWo67HtjIsAjb5bj+v34XbxmuQBNZoK1k6Gn6ZyAhMJ2eB0Ktgs+c0+ODe9n5Cc7Y 1SQJD1BOu6NeJiporQElO7KiIPNB4qI+/+IICmXt7rbZRMX0/38e74NDAR2TgVqFmANN d+TS2cHnMDdQlsviye7D8bzeWpId7gM9mnhUTpEfIvOxoRKglkwaZDC1/Qmj7W1Iu/vX qmjpb/WqDaLOqA7Y32RyxvMeEBNoi3ev9+w+PvOp0s1TZGUQO8LDVmLBTXyj2s95u0ma wzhg== 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=kap7yPZWorQCDhPQWC+ffLn7FVhnl9OqL6PEJUhua+g=; b=eQR9Azu9qakzBNMZBvIvw6GqFNNKsEDQeDkn2+euO9gm6itO/BKRzzs4JmRRiGuiba JpI4ntOoECzugoeV6WJoSWXQ4G38S4DxepU447ZjroEuwydLpAy7dvKyhP2+v/qS/RCk dwR1hkYdx/ypIKfkzRqtZBGwq6gfCodzRzEdgj+PRFEE6rR4pOzmRthrEFQ8ruZcHF20 yTfTX2kDS3mdkmmO+Y2y9enWCTmojs3NsCIPoFfOeR26e7yUOXyN9kE1MUVQH9GB4WPU TeR3KvLFMbnYNMkVZkJGUNWXO/yN5txRnYFYE4KyVhojmV7riP+k+bmQJDULaeKr27J+ U6Lw== 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 a99si10731309edf.381.2020.05.31.18.24.14; Sun, 31 May 2020 18:24:36 -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 S1727847AbgFABUS (ORCPT + 99 others); Sun, 31 May 2020 21:20:18 -0400 Received: from mga02.intel.com ([134.134.136.20]:51175 "EHLO mga02.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726555AbgFABUS (ORCPT ); Sun, 31 May 2020 21:20:18 -0400 IronPort-SDR: NmP+cG2b85XJRwUcPrn5oqKhXAWa003W4ycUC0fbkaGu8Fod5upja6WIv21kNuZQAH7lTh1c5F eKkq3duWODkA== 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/ECDHE-RSA-AES256-GCM-SHA384; 31 May 2020 18:20:18 -0700 IronPort-SDR: Bk/Ny9oOxI+cBFgFw20IkJTjpBIq6UbUJbE32EgUBOx+zOouurxE5hoOpPMprcRAbC6bJCxRP7 fS4jFImHfVBQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.73,459,1583222400"; d="scan'208";a="268157319" Received: from hbetts-mobl.ger.corp.intel.com (HELO localhost) ([10.252.59.178]) by orsmga003.jf.intel.com with ESMTP; 31 May 2020 18:20:10 -0700 From: Jarkko Sakkinen To: linux-kernel@vger.kernel.org, x86@kernel.org, linux-sgx@vger.kernel.org Cc: 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 v31 16/21] x86/fault: Add helper function to sanitize error code Date: Mon, 1 Jun 2020 04:16:40 +0300 Message-Id: <20200601011645.794040-17-jarkko.sakkinen@linux.intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200601011645.794040-1-jarkko.sakkinen@linux.intel.com> References: <20200601011645.794040-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 16c53c874bb9..23666e34abbc 100644 --- a/arch/x86/mm/fault.c +++ b/arch/x86/mm/fault.c @@ -704,6 +704,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) { @@ -760,6 +772,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. */ @@ -908,13 +922,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); @@ -1031,6 +1039,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