Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp2373298imm; Thu, 27 Sep 2018 11:43:11 -0700 (PDT) X-Google-Smtp-Source: ACcGV63Hx+F9vZZ3Q9noKKbpT0PhdgI3AR6q9dP+n+3Qol1QGB1AW9usopQdjLWx9n9dpXDUTXM7 X-Received: by 2002:a63:31c8:: with SMTP id x191-v6mr11213783pgx.229.1538073791197; Thu, 27 Sep 2018 11:43:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1538073791; cv=none; d=google.com; s=arc-20160816; b=no2hTLqpufNgSz+Go53YqHho/JrA+nurlwJz3x0q3ebwXidPa//oUJkDXkEele1coe Basn/5wtRieafbcRfSOOX3lP65914wEWKw4p8CGyuUII7oZaBJpBThZCbJmudwV0JZ26 7hO0eDXnq7XWQSRUOnPPKX2iSlp1d2VV2XtK3fwQgiTDQus8lwIRZ8/1RbEr13ZE8o4b C8iA7Ew6LjbenafrwK6npTYZEZRJC98H9LMyxS7kD/z7h3wan12H/O6OXinJ+wpNSF39 5WRvrvs7s1p0En3+GFqhRQGNZbDkNfkrn1SfXfceqKc6wcNSoDVqimZk/0RreMbYLDDI 9MkA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:subject:mime-version:user-agent :message-id:in-reply-to:date:references:cc:to:from; bh=8pk/w5/7nbrRU0DJRZItW8PS8ErO5gH66N8Y6ZOpH4I=; b=X7vnEIZUOi/CNKNdGW62waXMElK6TcxktJuqh2vLIDnjgQNwcpVZRHPxDrCKe0xz7G psc1N9cChxmYdsoCjNQacWdFr/svs5/XCg9O/+LfFx6F8YiBg9YgV8sPBXSJp1syhJ6k MXXPHekHD6upmM57LKxHY9BzPQCKs9IpH4DUUJrUjxPcaBqIGW1LhZT6YuCxAGzjXCnw +j/PktxBkAdi6ihi44hRXhdAk8HMZ5J2Ec47k080yuLxQg5sGu8WHYClfgbsfSx3gLFa eHu9TbFfZ6TxD14xEnTR87j3S/3+45NXffEgN/klkvbeZbDfo3+zW3rdG4v1bTM4l7jh 9UNQ== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id x10-v6si2670905pgk.423.2018.09.27.11.42.54; Thu, 27 Sep 2018 11:43:11 -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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728589AbeI1BBr (ORCPT + 99 others); Thu, 27 Sep 2018 21:01:47 -0400 Received: from out01.mta.xmission.com ([166.70.13.231]:59943 "EHLO out01.mta.xmission.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727320AbeI1BBq (ORCPT ); Thu, 27 Sep 2018 21:01:46 -0400 Received: from in02.mta.xmission.com ([166.70.13.52]) by out01.mta.xmission.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.87) (envelope-from ) id 1g5bEm-00005T-Sw; Thu, 27 Sep 2018 12:42:08 -0600 Received: from [105.184.227.67] (helo=x220.xmission.com) by in02.mta.xmission.com with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.87) (envelope-from ) id 1g5bEl-0003a3-ER; Thu, 27 Sep 2018 12:42:08 -0600 From: ebiederm@xmission.com (Eric W. Biederman) To: Jarkko Sakkinen Cc: x86@kernel.org, platform-driver-x86@vger.kernel.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, linux-sgx@vger.kernel.org, andriy.shevchenko@linux.intel.com, Dave Hansen , Arnd Bergmann , linux-arch@vger.kernel.org (open list:GENERIC INCLUDE/ASM HEADER FILES), linux-kernel@vger.kernel.org (open list) References: <20180925130845.9962-1-jarkko.sakkinen@linux.intel.com> <20180925130845.9962-9-jarkko.sakkinen@linux.intel.com> Date: Thu, 27 Sep 2018 20:41:48 +0200 In-Reply-To: <20180925130845.9962-9-jarkko.sakkinen@linux.intel.com> (Jarkko Sakkinen's message of "Tue, 25 Sep 2018 16:06:45 +0300") Message-ID: <87in2qpytv.fsf@xmission.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.1 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-XM-SPF: eid=1g5bEl-0003a3-ER;;;mid=<87in2qpytv.fsf@xmission.com>;;;hst=in02.mta.xmission.com;;;ip=105.184.227.67;;;frm=ebiederm@xmission.com;;;spf=neutral X-XM-AID: U2FsdGVkX19kV+2kuKa9xKfhj4/4O5sif/vv7FEdn3c= X-SA-Exim-Connect-IP: 105.184.227.67 X-SA-Exim-Mail-From: ebiederm@xmission.com X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on sa06.xmission.com X-Spam-Level: X-Spam-Status: No, score=0.9 required=8.0 tests=ALL_TRUSTED,BAYES_50, DCC_CHECK_NEGATIVE,FVGT_m_MULTI_ODD,T_TM2_M_HEADER_IN_MSG,XMSubLong autolearn=disabled version=3.4.1 X-Spam-Report: * -1.0 ALL_TRUSTED Passed through trusted hosts only via SMTP * 0.8 BAYES_50 BODY: Bayes spam probability is 40 to 60% * [score: 0.4255] * 0.7 XMSubLong Long Subject * 0.0 T_TM2_M_HEADER_IN_MSG BODY: No description available. * -0.0 DCC_CHECK_NEGATIVE Not listed in DCC * [sa06 1397; Body=1 Fuz1=1 Fuz2=1] * 0.4 FVGT_m_MULTI_ODD Contains multiple odd letter combinations X-Spam-DCC: XMission; sa06 1397; Body=1 Fuz1=1 Fuz2=1 X-Spam-Combo: ;Jarkko Sakkinen X-Spam-Relay-Country: X-Spam-Timing: total 376 ms - load_scoreonly_sql: 0.03 (0.0%), signal_user_changed: 2.4 (0.6%), b_tie_ro: 1.70 (0.5%), parse: 1.13 (0.3%), extract_message_metadata: 15 (4.0%), get_uri_detail_list: 2.9 (0.8%), tests_pri_-1000: 5 (1.4%), tests_pri_-950: 1.34 (0.4%), tests_pri_-900: 1.08 (0.3%), tests_pri_-400: 30 (8.1%), check_bayes: 29 (7.7%), b_tokenize: 10 (2.6%), b_tok_get_all: 10 (2.5%), b_comp_prob: 3.1 (0.8%), b_tok_touch_all: 4.4 (1.2%), b_finish: 0.61 (0.2%), tests_pri_-100: 4.6 (1.2%), check_dkim_signature: 0.50 (0.1%), check_dkim_adsp: 2.4 (0.6%), tests_pri_0: 295 (78.4%), tests_pri_10: 2.8 (0.8%), tests_pri_500: 14 (3.7%), rewrite_mail: 0.00 (0.0%) Subject: Re: [PATCH v14 08/19] signal: x86/sgx: Add SIGSEGV siginfo code for SGX EPCM fault X-Spam-Flag: No X-SA-Exim-Version: 4.2.1 (built Thu, 05 May 2016 13:38:54 -0600) X-SA-Exim-Scanned: Yes (on in02.mta.xmission.com) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Jarkko Sakkinen writes: > 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 Don't do this crazy ifdef thing. si_codes are not supposed to be per architecture. There are a few historical bugs but with a 32bit space it is just stupid to add #ifdefs. Just set. #define SEGV_SGXERR 8 and increase NSIGSEGV Anything else is just asking for trouble. Especially when you want to get SGX working on itaninum. > #define SEGV_ADIDERR 6 /* Disrupting MCD error */ > #define SEGV_ADIPERR 7 /* Precise MCD exception */ > #define NSIGSEGV 7 Eric