Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp73124imu; Mon, 10 Dec 2018 16:24:59 -0800 (PST) X-Google-Smtp-Source: AFSGD/Xr/xIby/i2F8b7Z9qdPnqrkFjPh0nw8hLAKIcKxkM+m5iWVK3xMZmgDfga8Uh+CMAgrDmU X-Received: by 2002:a63:8149:: with SMTP id t70mr13014074pgd.172.1544487899451; Mon, 10 Dec 2018 16:24:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544487899; cv=none; d=google.com; s=arc-20160816; b=KiL/kJcF/RfnAh8HgbSlYIxzH1fJMKkbLvv/uLC1GW5Qt1j5kFYdmVzvp9hktfSB8i pl+bGTCpK6obl5OAoqvihCJksoFBRFp2mlLeOdZ9SDi6pC2aUc6mHJFWHI9vp4d0agGL 8RbhSh0wnxT7+s0p3HiQcaweB3FIxIRVlcErNbBUPA+/bKEH6od3Uz6j8Y+Q4RzgWV0J IHvzBT8OYJrCaYgMZsShy6fpB7MKNd7JLqMsrgflyxfWFLF+9kMafIH5uMKnC2KfFa8C vR1Zl3aAOAd9Qc+gDGQQd5kUdN63Rnc3XkskGTfKTNtMDZ2uq+9krbfL3Cf453/iZTIr MoHA== 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=vbQhZK1n7R6pyHBJLi1vnYWY1NTpKapudl6IjEUi9ro=; b=C3djXbaN4e0UuBol64qHViA95PeCnrKezbLloX1QF5VC6la0LWuI57EyKIB26Tf+A2 2KBI4defH+CFApyfUi+1iF6VB7tlQJ7tNwvkFE1LVygB6P6b7PADUQNytHpAv8W3K21D oPtV77/x/WZ/NLsceKPXyqQv6LUIpLisGl2GOF//37oefy0DBVjgNO0ZJX+7zZGpBFoq 07Kz/tveI7Qjs1BK+jRCfq1dQ7Lo+ppyJW6noKhBvniqMfgsxEgogBqUIu84If/gLYLg qBcExM1uWzX/gVxHkf4mDqHyFYPF459e+kyxgc7rtE+O0vflH4jsraT427+7aVTTZakV lRyQ== 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 x187si11148192pgx.241.2018.12.10.16.24.44; Mon, 10 Dec 2018 16:24:59 -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 S1729986AbeLJXWB (ORCPT + 99 others); Mon, 10 Dec 2018 18:22:01 -0500 Received: from mga04.intel.com ([192.55.52.120]:11277 "EHLO mga04.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727852AbeLJXV7 (ORCPT ); Mon, 10 Dec 2018 18:21:59 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga001.jf.intel.com ([10.7.209.18]) by fmsmga104.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 10 Dec 2018 15:21:57 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.56,340,1539673200"; d="scan'208";a="117684777" Received: from sjchrist-coffee.jf.intel.com ([10.54.74.154]) by orsmga001.jf.intel.com with ESMTP; 10 Dec 2018 15:21:57 -0800 From: Sean Christopherson To: Thomas Gleixner , Ingo Molnar , Borislav Petkov , x86@kernel.org, Jarkko Sakkinen , Sean Christopherson , Dave Hansen , Andy Lutomirski , Peter Zijlstra Cc: "H. Peter Anvin" , linux-kernel@vger.kernel.org, linux-sgx@vger.kernel.org, Andy Lutomirski , Josh Triplett , Haitao Huang , Jethro Beekman , "Dr . Greg Wettstein" Subject: [RFC PATCH v3 2/4] x86/fault: Attempt to fixup unhandled #PF on ENCLU before signaling Date: Mon, 10 Dec 2018 15:21:39 -0800 Message-Id: <20181210232141.5425-3-sean.j.christopherson@intel.com> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20181210232141.5425-1-sean.j.christopherson@intel.com> References: <20181210232141.5425-1-sean.j.christopherson@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 Call fixup_sgx_enclu_exception() in the SIGSEGV and SIGBUS paths of the page fault handler immediately prior to signaling. If the fault is fixed, return cleanly and do not generate a signal. In the SIGSEGV flow, make sure the error code passed to userspace has been sanitized. Cc: Andy Lutomirski Cc: Jarkko Sakkinen Cc: Dave Hansen Cc: Josh Triplett Signed-off-by: Sean Christopherson --- arch/x86/mm/fault.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c index 7e8a7558ca07..d3903965334c 100644 --- a/arch/x86/mm/fault.c +++ b/arch/x86/mm/fault.c @@ -28,6 +28,7 @@ #include /* vma_pkey() */ #include /* efi_recover_from_page_fault()*/ #include /* store_idt(), ... */ +#include /* fixup_sgx_enclu_exception() */ #define CREATE_TRACE_POINTS #include @@ -928,6 +929,9 @@ __bad_area_nosemaphore(struct pt_regs *regs, unsigned long error_code, if (address >= TASK_SIZE_MAX) error_code |= X86_PF_PROT; + if (fixup_sgx_enclu_exception(regs, X86_TRAP_PF, error_code, address)) + return; + if (likely(show_unhandled_signals)) show_signal_msg(regs, error_code, address, tsk); @@ -1045,6 +1049,9 @@ do_sigbus(struct pt_regs *regs, unsigned long error_code, unsigned long address, if (is_prefetch(regs, error_code, address)) return; + if (fixup_sgx_enclu_exception(regs, X86_TRAP_PF, error_code, address)) + return; + set_signal_archinfo(address, error_code); #ifdef CONFIG_MEMORY_FAILURE -- 2.19.2