Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp829101ybt; Wed, 17 Jun 2020 15:17:51 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxjLc0jQYJgz+E6apBPNH99OwfrK0/0ygrJ7NoFX+qFwwOEeHn+1Sflx0xUTaiCAYYXqJdo X-Received: by 2002:a17:906:6b8e:: with SMTP id l14mr1303872ejr.32.1592432270946; Wed, 17 Jun 2020 15:17:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1592432270; cv=none; d=google.com; s=arc-20160816; b=TIBIh62l38sB/bwTwo9eZjBUC7DKeeuGHFXvx9VV1+zkzJyrd9QhPClRUtnytvSR7A VUc4ZbKuexMzTi/lph+deGeESENeF0hMv2FP6vnc63KsjXbR/OEDhPqf1+XGYBHxZtVE QfQkrXAsD+XIZ75rB66q3ERCfi7k+xPlUYvu2MSQxEv5tgaWxyu+/l7dHNNRKhLLEaPi oOfw0sQUed5lDJx3jSmI8AYQjn5WAB1/CZDm9ecknJ15g6PE8N5QRcDAaWMM2T5TG4H1 Z4OPfPBZZWsliC14KkZz5KNzWRwrriNWn5a4OC1Azn5vbhgHXePocXlfpScrtDZvGDF5 BOUQ== 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=Vxlz9IxoRLEqcnRuOna0kqoGEeU29zZ2eZmVWWxOiSY=; b=IvpK4mZ9KzpZSPwMTNmc8+kaK9fumh2pj2BAuvsMuhcCLEQpq39xUsZSxBeBKEGwAn f0uNj+h0m9K2R+RkZv/lvjmmP8zTfnV+9NLQZrxFEJea5frcNZTMecWSdXZbOwEzdpCu LdEqbbaefkz1SGtcSZ9O6pstNC9CpoVRry2k8UBQTrPVly5IISuh346015uE1jrUF5di Nfhvc4TX9/NcWgIhG2vVCNffJ+Jw/JnhG2TWzg6AZp8OJmTdHhZd83njW/pZfmYoaua7 8nh9ZvfL+HyovRT9igFnTy9qK9U2F2vkuPFIT5ntzhOaz6twzdc81NA7JoXOTPgSVI46 rcvw== 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 w1si678069ejv.375.2020.06.17.15.17.28; Wed, 17 Jun 2020 15:17:50 -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 S1727790AbgFQWM6 (ORCPT + 99 others); Wed, 17 Jun 2020 18:12:58 -0400 Received: from mga11.intel.com ([192.55.52.93]:37642 "EHLO mga11.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726840AbgFQWM5 (ORCPT ); Wed, 17 Jun 2020 18:12:57 -0400 IronPort-SDR: tWPTq/Xzq2AsQDzjyn3Gob9kF1MtvgeiioRaWnMRVhstsJ5mCLb8fVyc8frilcw0RWNo8w796T QDVR4Y189leQ== X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga004.jf.intel.com ([10.7.209.38]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Jun 2020 15:12:57 -0700 IronPort-SDR: 9rvGj4OwJL1vKHo52XOwewQjwZ+jOS5Ulbl/H4SeIq+7oOsNpL//DVTgG4M7+tuGUvZYgmhYFl 9UaP0pE+Ycxg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.73,523,1583222400"; d="scan'208";a="421288646" Received: from ysharon1-mobl1.ger.corp.intel.com (HELO localhost) ([10.252.49.131]) by orsmga004.jf.intel.com with ESMTP; 17 Jun 2020 15:12:45 -0700 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 v33 16/21] x86/fault: Add helper function to sanitize error code Date: Thu, 18 Jun 2020 01:08:38 +0300 Message-Id: <20200617220844.57423-17-jarkko.sakkinen@linux.intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200617220844.57423-1-jarkko.sakkinen@linux.intel.com> References: <20200617220844.57423-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 25d48aae36c1..966af17523fb 100644 --- a/arch/x86/mm/fault.c +++ b/arch/x86/mm/fault.c @@ -556,6 +556,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) { @@ -612,6 +624,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. */ @@ -760,13 +774,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); @@ -885,6 +893,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