Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp1325901yba; Thu, 16 May 2019 19:23:30 -0700 (PDT) X-Google-Smtp-Source: APXvYqyk7pumQ79V0U40V7MY8Emoyuhy4C5+2QYW2h+Je7BlBYywt67RifkGlda2Y5bystxMQRFH X-Received: by 2002:a63:6a42:: with SMTP id f63mr54578516pgc.377.1558059810068; Thu, 16 May 2019 19:23:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558059810; cv=none; d=google.com; s=arc-20160816; b=UgVuPzqsTDEfr5ydkamxifmC8+acA59XUE6ICxyWEiLO+CLVSQPJ4UWnRAbjH6rEJl zl9+xTv3kEKMBLrJYiB/XGrk/B/08XuhNDY9+CmRzW3zoa5uuLXURNnsFKDusUm9sCkp C51SJgrhIlWdn5XRpO0KrVGYdVgfC7V780fqVziTIjKtC24IapOJJzi95he9OftFaJvc gZcoqtb5MSOUcKSrCwC98zJChB7knm4GSmREWaN75rmYSEfvBf1NND67tn2j+HPNxLRg g0bPeZWBqvUoBhWKnYyT4Ao0ZNlnLdTRbZMdwWiOiWU8HRQ+BR7QBRew29Xyu87Vec04 2Kdw== 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:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=xfjYs+As5N+vk0UjvAWJC8SUJp2n7jnU3vJkeaJ22BQ=; b=ja0KnIttmMNrgkOil4C7NxcBFIIfQX0NHLkoXej5kRjfEvQqqjG6ISwJgvrXrJ1Hlt /HXYvVND1/dUy+vRTGWDrYxGgOGmvFPZXN/BbRJIrFRlOLS3XGVlTnN2+0iHzE+dAcgb JTBi1KdrTWoIRjYnUq1/la05kcGA20SOFBG5rygoYal2S7/E26auinnD1j4cyPkoBzRh 6sSNu+2e+7rgHiuCcHowg5eeF5t+iBSlxDvx0nSD2sBMdB0n1NRnUFPOlAbpru3bl8Fw XFQgFPMf/ohi6axOYZrm47ClFm9i1f/J+GWTL97+fwaN5aJN5GYkJrAHqGhjYXKEGoMP WXBQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=OPNb+7w9; 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 m1si6823768pld.236.2019.05.16.19.23.14; Thu, 16 May 2019 19:23:30 -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; dkim=pass header.i=@kernel.org header.s=default header.b=OPNb+7w9; 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 S1727255AbfEQAfd (ORCPT + 99 others); Thu, 16 May 2019 20:35:33 -0400 Received: from mail.kernel.org ([198.145.29.99]:47852 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727213AbfEQAfa (ORCPT ); Thu, 16 May 2019 20:35:30 -0400 Received: from mail-wm1-f47.google.com (mail-wm1-f47.google.com [209.85.128.47]) (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 7492D2177B for ; Fri, 17 May 2019 00:35:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1558053329; bh=niIKH4botxbpWeWqvmcPwLDMSSafV2ChSNsYdIe+iGo=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=OPNb+7w9EXpQrLSrg2I5dPykVkZZJHXC3F41CUHkpgBwZ50z9slGV2cYrRzxgMQ7h FzYo91c6FoeuFlTvFDJicBqjNF5m/d1nSgEQ/l3vrWwt1WdWQPVLlSN+SMCMJESf9g TDJOMq4p357K3UE7XLF9nNWw9YI3KlNL7Q6JZuXE= Received: by mail-wm1-f47.google.com with SMTP id 198so5249543wme.3 for ; Thu, 16 May 2019 17:35:29 -0700 (PDT) X-Gm-Message-State: APjAAAUjGmeeEbN+NwdnKZiIZnLPN1QuXI/rwMUTjYeh7XcAKVZClT6L OoJ7xEfruKF6SUXxQp2e09P5YVSBJycBy5mD/wcGdQ== X-Received: by 2002:a7b:c084:: with SMTP id r4mr93634wmh.14.1558053327909; Thu, 16 May 2019 17:35:27 -0700 (PDT) MIME-Version: 1.0 References: <8fe520bb-30bd-f246-a3d8-c5443e47a014@intel.com> <358e9b36-230f-eb18-efdb-b472be8438b4@fortanix.com> <960B34DE67B9E140824F1DCDEC400C0F4E886094@ORSMSX116.amr.corp.intel.com> <6da269d8-7ebb-4177-b6a7-50cc5b435cf4@fortanix.com> <20190513102926.GD8743@linux.intel.com> <20190514104323.GA7591@linux.intel.com> <20190514204527.GC1977@linux.intel.com> <20190515013031.GF1977@linux.intel.com> <960B34DE67B9E140824F1DCDEC400C0F654E38CD@ORSMSX116.amr.corp.intel.com> <960B34DE67B9E140824F1DCDEC400C0F654E3FB9@ORSMSX116.amr.corp.intel.com> In-Reply-To: <960B34DE67B9E140824F1DCDEC400C0F654E3FB9@ORSMSX116.amr.corp.intel.com> From: Andy Lutomirski Date: Thu, 16 May 2019 17:35:16 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: SGX vs LSM (Re: [PATCH v20 00/28] Intel SGX1 support) To: "Xing, Cedric" Cc: Andy Lutomirski , James Morris , "Christopherson, Sean J" , "Serge E. Hallyn" , LSM List , Paul Moore , Stephen Smalley , Eric Paris , "selinux@vger.kernel.org" , Jarkko Sakkinen , Jethro Beekman , "Hansen, Dave" , Thomas Gleixner , "Dr. Greg" , Linus Torvalds , LKML , X86 ML , "linux-sgx@vger.kernel.org" , Andrew Morton , "nhorman@redhat.com" , "npmccallum@redhat.com" , "Ayoun, Serge" , "Katz-zamir, Shay" , "Huang, Haitao" , Andy Shevchenko , "Svahn, Kai" , Borislav Petkov , Josh Triplett , "Huang, Kai" , David Rientjes Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, May 16, 2019 at 3:23 PM Xing, Cedric wrote: > > Hi Andy, > > > > SIGSTRUCT isn't necessarily stored on disk so may not always have a f= d. > > How about the following? > > > void *ss_pointer =3D mmap(sigstruct_fd, PROT_READ,...); > > > ioctl(enclave_fd, SGX_INIT_THE_ENCLAVE, ss_pointer); > > > > > > The idea here is SIGSTRUCT will still be passed in memory so it works > > the same way when no LSM modules are loaded or basing its decision on > > the .sigstruct file. Otherwise, an LSM module can figure out the backin= g > > file (and offset within that file) by looking into the VMA covering > > ss_pointer. > > > > I don=E2=80=99t love this approach. Application authors seem likely to= use > > read() instead of mmap(), and it=E2=80=99ll still work in many cares. I= t would > > also complicate the kernel implementation, and looking at the inode > > backing the vma that backs a pointer is at least rather unusual. > > Instead, if the sigstruct isn=E2=80=99t on disk because it=E2=80=99s dy= namic or came > > from a network, the application can put it in a memfd. > > I understand your concern here. But I guess we are making too much assump= tion on how enclaves are structured/packaged. My concern is, what if a SIGS= TRUCT really has to be from memory? For example, an enclave (along with its= SIGSTRUCT) could be embedded inside a shared object (or even the "main" ex= ecutable) so it shows up in memory to begin with. Hmm. That's a fair point, although opening /proc/self/exe could be somewhat of a workaround. It does suffer from a bit of an in-band signaling problem, though, in that it's possible that some other random bytes in the library resemble a SIGSTRUCT. > I was not saying enclaves were exempt to good security practices. What I = was trying to say was, EPC pages are *not* subject to the same attacks as r= egular pages so I suspect there will be a desire to enforce different polic= ies on them, especially after new SGX2 features/applications become availab= le. So I think it beneficial to distinguish between regular vs. enclave vir= tual ranges. And to do that, a new VM_SGX flag in VMA is probably a very si= mple/easy way. And with that VM_SGX flag, we could add a new security_sgx_m= prot() hook so that LSM modules/policies could act differently. I'm not opposed to this, but I also don't think this needs to be in the initial upstream driver. VM_SGX also isn't strictly necessary -- an LSM could inspect the VMA to decide whether it's an SGX VMA if it really wanted to. That being said, do you have any specific behavior differences in mind aside from the oddities involved in loading the enclave. > > And if you are with me on that bigger picture, the next question is: what= should be the default behavior of security_sgx_mprot() for existing/non-SG= X-aware LSM modules/policies? I'd say a reasonable default is to allow R, R= W and RX, but not anything else. It'd suffice to get rid of EXECMEM/EXECMOD= requirements on enclave applications. For SGX1, EPCM permissions are immut= able so it really doesn't matter what security_sgx_mprot() does. For SGX2 a= nd beyond, there's still time and new SGX-aware LSM modules/policies will p= robably have emerged by then. I hadn't thought about the SGX1 vs SGX2 difference. If the driver initially only wants to support SGX1, then I guess we really could get away with constraining the EPC flags based on the source page permission and not restricting mprotect() and mmap() permissions on /dev/sgx/enclave at all.