Received: by 2002:a25:d7c1:0:0:0:0:0 with SMTP id o184csp3626685ybg; Mon, 28 Oct 2019 16:10:55 -0700 (PDT) X-Google-Smtp-Source: APXvYqxBx/TzGwpK34WwQq9lkqnvdO+aMaVzeVGfRYYRO16a9WzLXwkaYfHKxYbh5UVoA82xZz8m X-Received: by 2002:a50:b6e1:: with SMTP id f30mr22354669ede.212.1572304255450; Mon, 28 Oct 2019 16:10:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1572304255; cv=none; d=google.com; s=arc-20160816; b=NOuki5vjCbmZjK+PM9kGqmzMQBrB60sxHVpTEnwWqTyfJK5PIV6qPJfEzBqpMkJwt1 sF3BCMOGnU/pjCd7P7jrh6GGpE6ksMeall/JFdOZQJKWmwJB21YGP+DdTf87CAQ9lemB Pp4XYcNZhqGYA/YdxTBMPESNDMIN4LEtgwAW29Y6TIwRr+yI9SI4LGJLOUGjfyPV977Z mLUr8RiAeXTTmPte0U0c5wGCK7jC88/mf9XVczG2/HeiC3VyxjOgFYyOkfS8uLWfJ4nk pQJScH9ygTwrSXEhIg0CA6A56sSJehQLBvd5fW3Svin7+3rl3YwlAk9BTpHNoPLjqFq8 ONmg== 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=EKhCbYSp4BapVCQJ9hkiEcSQOgg/67Zxch61BhWJWG/ox3k5aLcxkKwkczl/IvSlHJ E0XbVSDEKqNjUV5+jk+49WyZ22L/Z7vnSet/4j7gCmIalNb8e5MueGN2Vv89lCQ45hmz rAc4IbHMKZtbzdY1HykQYesIacyKw7fwZ9aLQ0jOKeKzMo0B0jKsGC62FifXy51eZj4G x8wyH05h4P5UTJiyLYOqpVwpx1CGnVL+kL1yM4D5VzXDO33CNrnylBP7bdufZrY2i/7J gWDMCPZc83WTtobuLxWrlBdLsw/QnNQX4Rrr+ZGrCB633OIsWcsfiL3iCwcmO8QmbDnV WyYg== 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 63si9478466edp.302.2019.10.28.16.10.32; Mon, 28 Oct 2019 16:10:55 -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 S2390104AbfJ1VGu (ORCPT + 99 others); Mon, 28 Oct 2019 17:06:50 -0400 Received: from mga18.intel.com ([134.134.136.126]:9567 "EHLO mga18.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730204AbfJ1VGt (ORCPT ); Mon, 28 Oct 2019 17:06:49 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by orsmga106.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 28 Oct 2019 14:06:48 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.68,241,1569308400"; d="scan'208";a="224760095" Received: from shrehore-mobl1.ti.intel.com (HELO localhost) ([10.251.82.5]) by fmsmga004.fm.intel.com with ESMTP; 28 Oct 2019 14:06:41 -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, cedric.xing@intel.com, puiterwijk@redhat.com, Jarkko Sakkinen Subject: [PATCH v23 19/24] x86/fault: Add helper function to sanitize error code Date: Mon, 28 Oct 2019 23:03:19 +0200 Message-Id: <20191028210324.12475-20-jarkko.sakkinen@linux.intel.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191028210324.12475-1-jarkko.sakkinen@linux.intel.com> References: <20191028210324.12475-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