Received: by 2002:a25:7ec1:0:0:0:0:0 with SMTP id z184csp8707388ybc; Fri, 29 Nov 2019 15:21:29 -0800 (PST) X-Google-Smtp-Source: APXvYqwstCRF8Fh6LfJ21S2N3dnWQjxFscx/ORHVAhr8X6AZQuENDWsarHAnGOlaZo/jaomG0MYP X-Received: by 2002:a05:6402:1296:: with SMTP id w22mr43788747edv.65.1575069689842; Fri, 29 Nov 2019 15:21:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1575069689; cv=none; d=google.com; s=arc-20160816; b=jooh5YXJa8pO88MMAgJn63lU5CzqD5ohmmQscTyWrmypIyhsQnPI9cXN6LVI6849wS MRC6P0uflyw+llDG2WQQM1tgxs46HjLjPTPwvyJ/EOZrfbsqxua3BmkAYXkUes0HdQrz HCaPP/9EyKIA87f4V0kXK2hlGALLHIa2tKeEv+YF79CeU5Xqqvdg3EP/Z7sfRq2Y96jS ZcvdbN5cMzSJkBAUMZOWbbAS2yZGkkNuBze5lQI1yK9ScUS9eV8GjxP1ea6yUgRtdalj vVXby49hJwF4O3ALHCL/B+Fa+5HUnZiVLQN2XXEw66xLdiGeMRUoxh4/H3N2hFFBQH8c 3jGg== 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=9W/ZgwSjPGMLbZElEDSVyM8Bpp/4yEgLKi0WtruzOzU=; b=Kdf9KpP9yRWg57J+5I9IRMRExXSaCL9wjZ8J5R5AIBN364gRzWuXupDxwAOginoOa1 DOY/pad4aJ2JUHVTi0b9mdnfjLc5lqq+VtzeOV9kdcTgqMGEf4FwMKtOAuDqI8H1msO6 c3n8CSyy6iiT9jiHBfmX70cr3FASqlmBbqxHdp9gpZRK02IE6icrmsjMw59O1Zaffb2p +wMyt1HM7kHiO7VDsjvQkvniYbFW5XOBCCGsFuHswl3YG7xFXft+NtB/8bp3oDZtRH6o ES4QqV2pXBJx8skJWMj9anPlygrUwCiPouLWjVfbCrvl+t3ygtP2lfJs7oFMce62XxKl KvXg== 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 k2si6978528ejq.151.2019.11.29.15.21.06; Fri, 29 Nov 2019 15:21:29 -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 S1727403AbfK2XRo (ORCPT + 99 others); Fri, 29 Nov 2019 18:17:44 -0500 Received: from mga06.intel.com ([134.134.136.31]:21192 "EHLO mga06.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727073AbfK2XRn (ORCPT ); Fri, 29 Nov 2019 18:17:43 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga005.jf.intel.com ([10.7.209.41]) by orsmga104.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 29 Nov 2019 15:17:43 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.69,259,1571727600"; d="scan'208";a="384194487" Received: from gamanzi-mobl4.ger.corp.intel.com (HELO localhost) ([10.252.3.126]) by orsmga005.jf.intel.com with ESMTP; 29 Nov 2019 15:17:24 -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, 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, cedric.xing@intel.com, puiterwijk@redhat.com, Jarkko Sakkinen Subject: [PATCH v24 19/24] x86/fault: Add helper function to sanitize error code Date: Sat, 30 Nov 2019 01:13:21 +0200 Message-Id: <20191129231326.18076-20-jarkko.sakkinen@linux.intel.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191129231326.18076-1-jarkko.sakkinen@linux.intel.com> References: <20191129231326.18076-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 b1f0060b263f..0e0842e941eb 100644 --- a/arch/x86/mm/fault.c +++ b/arch/x86/mm/fault.c @@ -681,6 +681,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) { @@ -737,6 +749,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. */ @@ -885,13 +899,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); @@ -1008,6 +1016,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.20.1