Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp254198imu; Mon, 26 Nov 2018 10:25:59 -0800 (PST) X-Google-Smtp-Source: AJdET5edrmQ1FkxeIQbhr8IVA+GoZc24X0hAzib1CwdvlRK5KCAaeQCHacbuL6XR9ruJp6UfWKLK X-Received: by 2002:a62:f247:: with SMTP id y7mr29330028pfl.25.1543256759056; Mon, 26 Nov 2018 10:25:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543256759; cv=none; d=google.com; s=arc-20160816; b=idnSZWcwy4CkMz5tZGKXEO9XvigGAiFKbIEnxF4Wz+7LEO1HJ80rPsNrAGAlpVF1w+ w2oD1tX3cxKMqTX0SAXSdjR96qRgrE9Nw9coyg/3fk+P65kBQUYRAvsv23eIxlfdbbyI 8nt4oxU2oCQB7BkodNDaKA3wS+g/ueuKg4l58prp1h+GQpdATqC+bZA2MKfmpNgDVOqS dGGG5t3Rz9QEAs8q5KdXOOg1a6wJVh9Y9tuw/jYWPLWngRpM1hcCtZEH5RBEKfVTORHW UIdaSqg47epbPnOuOhhUgbQt0Ev+fLTJQr6IiCrUtADeFKsPCKTsBpL8bk2d5FNBgIZ2 FVrQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=EqeV4TeryiUcwG3CPOaniPYaDk7e7Pn8+39T9u3vcfE=; b=asqc1mfuQZ/mRo63XJWFAOgoTeXK3SjenI4uQEL6zYDEcGGXH5/Nn/PjBgUmriU64e HvSlV6dUwNzbIzypXHG5oO8KlqSuNsoBjtjBqbygK77lNK/wpB37i91tFz61wAmmjhIT Qp/rBU9NvqT0ZdNnHepaX3RZoAN2fz2PDuohE+fNfiWLyPhra43pFWKEdcbClwNr0+8b DXwI35XBbSPUPTb7Z2RyydjwKNJhWPwyr2xHko5IPsKumhm33W+Bb3Yg8DazPCB4qgM9 WOOtB++xWg35U+j1LGToIvOcUfaTZm3Gx/nfbG+o9rUOP7lMzCHE9/8wNqB+A/xSnl2Z rEHw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="yoG/GYOq"; 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i64si918335pge.361.2018.11.26.10.25.27; Mon, 26 Nov 2018 10:25: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; dkim=pass header.i=@kernel.org header.s=default header.b="yoG/GYOq"; 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726266AbeK0FRc (ORCPT + 99 others); Tue, 27 Nov 2018 00:17:32 -0500 Received: from mail.kernel.org ([198.145.29.99]:49346 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725723AbeK0FRc (ORCPT ); Tue, 27 Nov 2018 00:17:32 -0500 Received: from mail-wr1-f45.google.com (mail-wr1-f45.google.com [209.85.221.45]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 8074420989 for ; Mon, 26 Nov 2018 18:22:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1543256556; bh=6hPGnLrV+QZcJMVsSvi/1YVZ8fpPO+ovW56LjFsKwBg=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=yoG/GYOqALUkffbFnchUi9AtizbXwUek27ORislopOZY/cNFCt/q0FBupfrFnZ9tl it/UFaiP2uszxK09FAivYTZW9H2IWWRLEMHHMPcTZlDpE2HppEQZiqR1lrNWf9r/RW naGdN1C5gElGNrwuysefVIFrKRdb4KdKLBIFHHQw= Received: by mail-wr1-f45.google.com with SMTP id l9so19979123wrt.13 for ; Mon, 26 Nov 2018 10:22:36 -0800 (PST) X-Gm-Message-State: AA+aEWYd7oH9RkDGMWq71oEZGvPRSVgHm5HkHEHhmVxUm5OCdryaKx57 yW7wBM5ER3nF//UKlO40asmY/nB54d90B9ZBkLk9Ag== X-Received: by 2002:a5d:5541:: with SMTP id g1mr25339264wrw.330.1543256552960; Mon, 26 Nov 2018 10:22:32 -0800 (PST) MIME-Version: 1.0 References: <20181120120442.GA22172@linux.intel.com> <20181122111253.GA31150@wind.enjellic.com> <20181124172114.GB32210@linux.intel.com> <20181125145329.GA5777@linux.intel.com> <0669C300-02CB-4EA6-BF88-5C4B4DDAD4C7@amacapital.net> <20181125185524.GA23224@wind.enjellic.com> <94154ECB-3EF7-4A37-9057-0B84DBCE650E@amacapital.net> <20181126110038.GA27609@wind.enjellic.com> In-Reply-To: <20181126110038.GA27609@wind.enjellic.com> From: Andy Lutomirski Date: Mon, 26 Nov 2018 10:22:20 -0800 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v17 18/23] platform/x86: Intel SGX driver To: "Dr. Greg Wettstein" Cc: Jarkko Sakkinen , Andrew Lutomirski , X86 ML , Platform Driver , linux-sgx@vger.kernel.org, Dave Hansen , "Christopherson, Sean J" , nhorman@redhat.com, npmccallum@redhat.com, "Ayoun, Serge" , shay.katz-zamir@intel.com, haitao.huang@linux.intel.com, Andy Shevchenko , Thomas Gleixner , "Svahn, Kai" , mark.shanahan@intel.com, Suresh Siddha , Ingo Molnar , Borislav Petkov , "H. Peter Anvin" , Darren Hart , Andy Shevchenko , LKML Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Nov 26, 2018 at 3:00 AM Dr. Greg wrote: > > On Sun, Nov 25, 2018 at 04:37:00PM -0800, Andy Lutomirski wrote: > > > Bah, I hit send on a partially written draft. I???ll try again soon. > > > > --Andy > > Your first issue seems to be complete so I will respond to that in > order to make sure we are not talking past one another. It wasn't, but your answer is enlightening! I've read the SGX *manual*, but I hadn't dug through the actual Intel-supplied enclaves. So, when I said that the LE isn't an important part of the overall trust model, I meant that it isn't *in hardware*. It's certainly possible to write SGX software that weakens the security of the overall system, and Intel seems to have done so: > > The Intel supplied launch enclave (LE) specifically denies > initialization of enclaves which have the PROVISION attribute set, > with the exception of enclaves whose MRSIGNER values match those of > the keys that Intel uses to sign the PCE and PVE enclaves. See line > 219 of psw/ae/le/launch_enclave.cpp in the Intel SDK. This seems entirely reasonable. (But see below...) > This report, along with the PEK, is submitted to the PCE enclave in > order to generate the Platform Provisioning IDentity (PPID), which is > the privacy critical identifier. The PCE verifies the report > generated by the PVE and rejects the request to generate the PPID if > the report was generated by an enclave that was not initialized with > the PROVISION bit set, see line 109 of psw/ae/pce/pce.cpp. ...and this seems entirely unreasonable. Your description does indeed appear consistent with the code: the PCE will hand out the PPID to any requesting enclave that has the PROVISION bit set, so you are correct that: > Once again, the important design factor in all of this is the premise > that the launch enclave will not allow enclaves other then the PCE and > PVE to access the PROVISION bit. But here's where the whole thing goes off the rails. I would argue that the Intel-supplied (and Intel-signed, apparently!) PCE is just straight-up buggy. What Intel is *trying* to do is to hand out the PPID to an appropriately signed enclave. What they actually did is to hand out the PPID to any enclave that has the PROVISION bit set. This is poor design because it overload the PROVISION bit. That bit is supposed to mean "may use EGETKEY to obtain provisioning and provisioning seal keys", which is not actually what Intel wants here. It's also poor design without FLC because it pointlessly relies on the LE to enforce a restriction on the use of provisioning enclaves, when the code could instead have checked MRSIGNER.. And it's just straight up wrong with FLC because there is no guarantee whatsoever that the LE being used is Intel's. And, for that matter, there is no guarantee that the requesting enclave doesn't have the DEBUG bit set. (It's also poor design because the PCE doesn't appear to verify that the report passed in is actually intended to be associated with a call to get_ppid(). There appear to be reports associated with provision "msg1" and "msg3". If it's possible to get a valid report for msg3 to be accepted as a msg1 report of vice versa, then it might be game over.) Sorry, but this is not Linux's problem. The right fix is, in my opinion, entirely clear: the PCE should check MRSIGNER and possibly even MRENCLAVE in the report it receives. Intel needs to fix their PCE, sign a fixed version, and find some way to revoke, to the extent possible, the old one. And the SGX enclave authors need to understand something that is apparently subtle: THE LAUNCH POLICY IS NOT PART OF THE TCB AND SHOULD NOT BE RELIED UPON. Enclaves can and should be written to remain secure even in the complete absence of any form of launch control. I went and filed a bug on github. Let's see what happens: https://github.com/intel/linux-sgx/issues/345 Also, the whole SGX report mechanism seems to be misused in the SDK. An SGX report is a cryptographic primitive that essentially acts like a signed blob. Building a secure protocol on top of signed messages or on top of reports takes more than just making up ad hoc blob formats and signing them. There needs to be domain separation between different messages, and this seems to be entirely missing. Do you know if Intel has had a serious audit of their platform enclave code done? > > > No, I have no clue why Intel did it this way. I consider it to be a > > mistake. > > Are you referring to there being a mistake in the trust relationships > that the provisioning protocol implements or the overall concept of a > provisioning key? I'm referring to the hardware's policy as to when keys that don't depend on OWNEREPOCH can be obtained. As far as I know, the only real need for such keys is to verify that the running platform is a real Intel platform, which means that access to the provisioning key is only useful to Intel-approved services. Why didn't Intel enforce this in hardware or microcode? I see no reason that EGETKEY should hand out those key types of the enclave is not signed by Intel. For that matter, I also don't see why the provisioning seal key needs to exist -- the regular seal key could be used instead and, if OWNEREPOCH changes, the platform could just re-certify itself. > > >> The driver should establish the equivalent of three linked lists, > > >> maintainable via /sysfs pseudo-files or equivalent plumbing. The > > >> lists are referenced by the kernel to enforce the following policies. > > >> > > >> 1.) The right to initialize an enclave without special attributes. > > >> > > >> 2.) The right to initialize an enclave with the PROVISION_KEY attribute set. > > >> > > >> 3.) The right to initialize an enclave with the LICENSE_KEY attribute set. > > >> > > >> The lists are populated with MRSIGNER values of enclaves that are > > >> allowed to initialize under the specified conditions. > > > NAK because this is insufficient. You're thinking of a model in > > which SGX-like protection is all that's needed. This is an > > inadequate model of the real world. The attack I'm most concerned > > about wrt provisioning is an attack in which an unauthorized user is > > permitted. > > We will be interested in your comments as to why the proposal is > insufficient in the real world of FLC. That's what you get for reading my unfinished email :) Your proposal fails to protect against SGX malware. Here's an SGX malware use case: the attacker writes a malicious enclave and gets a victim machine to run it as a non-root user. They bundle it with a valid Intel-signed copy of the relevant platform enclaves and use them to bootstrap the attestation process. The malicious enclave attests its identity to a command-and-control server and obtains malicious code to run. The good guys can't reverse engineer the malware enclave, because they can't pass the attestation check and therefore can't obtain the encrypted code. This isn't prevented by your proposed solution: the provisioning enclaves are all signed by Intel. What's needed is a check that prevents unauthorized *users* from running them. --Andy