Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp61626pxk; Tue, 15 Sep 2020 17:52:03 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzMdLJBZtaYksaNWvnST74E7C/gMwJjIYdPOR+Oe/2nic2JL6zXaEtHOojMUz0hdh+r+yNG X-Received: by 2002:a17:906:e0c7:: with SMTP id gl7mr22464793ejb.109.1600217522970; Tue, 15 Sep 2020 17:52:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600217522; cv=none; d=google.com; s=arc-20160816; b=hqxy0sVqcQ38onaZ3Q+4iIS7u7ZoXApzxo9tvDFwGGJF5Gw5EbZL4kynhGjGZVE0pX hyCZ3evCz2TLYxN4iOaVYCPwk4EhdYWmTaZ5/s+PqhkZsr3sDpDHcEJsB7+S9heJomtF zMcVqvrOaGL3hpYdyFRDvOCPpVH9u2/DIHk9a0F4Npi2Aqz8BPQjg2M35Lx/7qF3Os74 kyP8OMzpMygr8RZAtJJeMZM4JcyqIaTbRnxmoPwkxhgLAXLZxOUHPF/NImUUNPeTMzv1 cVzzdt68rvJ9UUYqxMhPV7s17mWVaGZ3LEgqjgx9eJK0SOdSsXzOziRmm4Mh+1KMi43g 4fow== 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 :dkim-signature; bh=KNaeZ0++0+eI/t4oPbp7MTW/KkSMPaG3lcfgaHbPxbw=; b=V7spwkFcZ7kvBE81I+c7Fudt9+bEJ/tFLxxF95dWU+GpQJmWSlaFDo7cxYc2JzmhuW uKH9abOLW8jhNg1A8f294aflATvAhjZxG2w3KxOb6oWyefYD6kp/rifG14/HGnmY8UFY Pt6o+QJkv20F2WKxIBc6OOe6xgu5lKvujk/GkxcWmxFTGbpLGMpK380ONs34dVd1hx2O h4NNnjoeE7BZTNt2IPxuvNHZPp2KDucSIi3QYD9wSNZf0uSddLIy2vDP3C+GVx20G/XU nBegMKpgJfTERzJb7lW4vGgndNWyMXZyENaIqKWC2O4p8+y2VUacBPXluVTRzmRCzrqP zYOQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@kapsi.fi header.s=20161220 header.b=mIzUZG1g; 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 y2si10512378edu.414.2020.09.15.17.51.40; Tue, 15 Sep 2020 17:52:02 -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; dkim=fail header.i=@kapsi.fi header.s=20161220 header.b=mIzUZG1g; 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 S1726380AbgIOLk1 (ORCPT + 99 others); Tue, 15 Sep 2020 07:40:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34730 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726326AbgIOLbo (ORCPT ); Tue, 15 Sep 2020 07:31:44 -0400 Received: from mail.kapsi.fi (mail.kapsi.fi [IPv6:2001:67c:1be8::25]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9FD91C06121D; Tue, 15 Sep 2020 04:28:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=kapsi.fi; s=20161220; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=KNaeZ0++0+eI/t4oPbp7MTW/KkSMPaG3lcfgaHbPxbw=; b=mIzUZG1gxYS1miqbihi+XtS38A TeuYIlaUSqUzeJbd0QIXJ2tBNehqOsSkBHUi2xPOdD5w9GplPPeIHP618HqF4vW2kV/MEOKuVrzT8 RCnmpOT7pd6hPn0X7iy4cgbJWXKKcLfK4HKwbPrPfdWb15rEnmhoG4fHhk/Szfpy+kQ7ekG/q9yyK thzswhNZlORex4fkbe0k3Y8BsTlHfRpnyBrhf8A9hDD8mkArtDSRueUNLmIUyc/F/ep26LTfSHBtq L/u3AD8U/bstjIU/RCsYbVr7CG3GoMKoI4Qb7MzObB5fFIgNcxk2dPDPIPZecgIK3SdvVQWVL7d5c Lyy97oew==; Received: from 83-245-197-237.elisa-laajakaista.fi ([83.245.197.237] helo=localhost) by mail.kapsi.fi with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1kI98o-0000mX-Ch; Tue, 15 Sep 2020 14:28:54 +0300 From: Jarkko Sakkinen To: x86@kernel.org, linux-sgx@vger.kernel.org Cc: linux-kernel@vger.kernel.org, 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 v38 19/24] x86/fault: Add helper function to sanitize error code Date: Tue, 15 Sep 2020 14:28:37 +0300 Message-Id: <20200915112842.897265-20-jarkko.sakkinen@linux.intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200915112842.897265-1-jarkko.sakkinen@linux.intel.com> References: <20200915112842.897265-1-jarkko.sakkinen@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SA-Exim-Connect-IP: 83.245.197.237 X-SA-Exim-Mail-From: jjs@kapsi.fi X-SA-Exim-Scanned: No (on mail.kapsi.fi); SAEximRunCond expanded to false 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 1a7cc6d3281a..9e5ec861aba0 100644 --- a/arch/x86/mm/fault.c +++ b/arch/x86/mm/fault.c @@ -555,6 +555,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) { @@ -611,6 +623,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. */ @@ -759,13 +773,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); @@ -884,6 +892,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