Received: by 2002:a4a:301c:0:0:0:0:0 with SMTP id q28-v6csp904051oof; Tue, 25 Sep 2018 06:14:09 -0700 (PDT) X-Google-Smtp-Source: ACcGV60MkHAgNEr1KufS4piZaL1r62/dT1xPMP/xEkrs/1NnLmjqtg0N7h/5QYWEw60nyBxaqVuw X-Received: by 2002:a62:8787:: with SMTP id i129-v6mr1181705pfe.62.1537881249054; Tue, 25 Sep 2018 06:14:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537881249; cv=none; d=google.com; s=arc-20160816; b=vSsMRHmVaNwbKctjWZSDB8TbpXtktPFXreO7LKlrQwyAZQBOahkCagBWjHqUepKYYj dhdmlQ2oju6nYEoQdYxbZiwocrMW2A0Aj0o5HNVHocu+hR29md2C/1FU3MCELTgmtUo/ oHNMKTG6F6QUBZMWHSxTcMYLU4sbsUVGMyRFdHLo60tQ8cBIXmEIIhPUEyeIoZEFydrH 9oEzdo36REO129t4TUoD7ZRHIRj+/N9ix/gVTVUTXUkt5JxdZl3lr0wtNKuHC/g3r/hQ to210h+ZLyS23aqs8OYMuzYbzbYB/7LLvkSFlYqRCBaXt9tlYe/23nrFby8MNCHvg8xZ bv6A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from; bh=8G9yv926HNqVDqWNduhFGJtqjd3pCXrGoG1FRgkMGy0=; b=mcs1vWLiNGqxramZurA0cMzsLjwNn8W3v807kGNC9idQ2pq1PymLmX8EJRE8NIu9gs f54iQTfQ9/CzSCiKb6vmulqZNSd86LDXbJUrILzKz1TZUVQ/lrQw1Ju3VJkHZ2GIWzvH zPrc/W7jM1xIhFrLqBP9VMucfYstXdn0BKEXCeSAxxcmxl8/SCHj0jkXl/4wXOfz7+U7 KFwV8AuEjnn8LcTwjb6qAI3BpjV3I6nWgHKuRVNdHLg6TEUIRlnng4RaTW5E/R1cFrKC xGiRSBAjlEj0+fYxOpKTbjXuoLCGmY+4V0tw2N1F4fsHGnYVm6LvynXHagMFOYufBZm8 mOjA== 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 14-v6si2325786pgm.488.2018.09.25.06.13.53; Tue, 25 Sep 2018 06:14:09 -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 S1729316AbeIYTUX (ORCPT + 99 others); Tue, 25 Sep 2018 15:20:23 -0400 Received: from mga02.intel.com ([134.134.136.20]:39126 "EHLO mga02.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727341AbeIYTUW (ORCPT ); Tue, 25 Sep 2018 15:20:22 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orsmga101.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 25 Sep 2018 06:12:50 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.54,302,1534834800"; d="scan'208";a="93546813" Received: from thomasvo-mobl2.ger.corp.intel.com (HELO localhost) ([10.252.53.212]) by orsmga001.jf.intel.com with ESMTP; 25 Sep 2018 06:10:35 -0700 From: Jarkko Sakkinen To: x86@kernel.org, platform-driver-x86@vger.kernel.org Cc: dave.hansen@intel.com, sean.j.christopherson@intel.com, nhorman@redhat.com, npmccallum@redhat.com, serge.ayoun@intel.com, shay.katz-zamir@intel.com, linux-sgx@vger.kernel.org, andriy.shevchenko@linux.intel.com, Dave Hansen , Jarkko Sakkinen , Arnd Bergmann , linux-arch@vger.kernel.org (open list:GENERIC INCLUDE/ASM HEADER FILES), linux-kernel@vger.kernel.org (open list) Subject: [PATCH v14 08/19] signal: x86/sgx: Add SIGSEGV siginfo code for SGX EPCM fault Date: Tue, 25 Sep 2018 16:06:45 +0300 Message-Id: <20180925130845.9962-9-jarkko.sakkinen@linux.intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180925130845.9962-1-jarkko.sakkinen@linux.intel.com> References: <20180925130845.9962-1-jarkko.sakkinen@linux.intel.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Sean Christopherson The SGX Enclave Page Cache Map (EPCM) is a hardware-managed table that enforces accesses to an enclave's EPC page in addition to the software-managed kernel page tables, i.e. the effective permissions for an EPC page are a logical AND of the kernel's page tables and the corresponding EPCM entry. The primary purpose of the EPCM is to prevent a malcious or compromised kernel from attacking an enclave by modifying the enclave's page tables. The EPCM entires for an enclave are populated when the enclave is built and verified, using metadata provided by the enclave that is included in the measurement used to verify the enclave. In normal operation of a properly functioning, non-malicious kernel (and enclave), the EPCM permissions will never trigger a fault, i.e. the kernel may make the permissions for an EPC page more restrictive, e.g. mark it not-present to swap out the EPC page, but the kernel will never make its permissions less restrictive. But, there is a legitimate scenario in which the kernel's page tables can become less restrictive than the EPCM: on current hardware all enclaves are destroyed (by hardware) on a transition to S3 or lower sleep states, i.e. all EPCM entries are invalid (not-present) after the system resumes from its sleep state. Unfortunately, on CPUs that support only SGX1, EPCM violations result in a #GP. The upside of the #GP is that no kernel changes are needed to deal with the EPCM being blasted away by hardware, e.g. userspace gets a SIGSEGV, assumes the EPCM was lost and restarts its enclave and everyone is happy. The downside is that userspace has to assume the SIGSEGV was because the EPC was lost (or possibly do some leg work to rule out other causes). In SGX2, the oddity of delivering a #GP due to what are inherently paging related violations is remedied. CPUs that support SGX2 deliver EPCM violations as #PFs with a new SGX error code bit set. So, now that hardware provides us with a way to unequivocally determine that a fault was due to a EPCM violation, define a signfo code for SIGSEGV so that the information can be passed onto userspace. Cc: Dave Hansen Signed-off-by: Sean Christopherson Signed-off-by: Jarkko Sakkinen --- include/uapi/asm-generic/siginfo.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/include/uapi/asm-generic/siginfo.h b/include/uapi/asm-generic/siginfo.h index 80e2a7227205..fdd898e2325b 100644 --- a/include/uapi/asm-generic/siginfo.h +++ b/include/uapi/asm-generic/siginfo.h @@ -225,7 +225,11 @@ typedef struct siginfo { #else # define SEGV_PKUERR 4 /* failed protection key checks */ #endif +#ifdef __x86_64__ +#define SEGV_SGXERR 5 /* SGX Enclave Page Cache Map fault */ +#else #define SEGV_ACCADI 5 /* ADI not enabled for mapped object */ +#endif #define SEGV_ADIDERR 6 /* Disrupting MCD error */ #define SEGV_ADIPERR 7 /* Precise MCD exception */ #define NSIGSEGV 7 -- 2.17.1