Received: by 2002:a25:b794:0:0:0:0:0 with SMTP id n20csp2941112ybh; Mon, 5 Aug 2019 09:17:58 -0700 (PDT) X-Google-Smtp-Source: APXvYqywyv7mdLaP160IkjJ9NNKjRErpsixmEgGgX5z8zcoZlC3BdrKG9RSlko/8w417XbgOcKzJ X-Received: by 2002:a63:1918:: with SMTP id z24mr131334087pgl.94.1565021878586; Mon, 05 Aug 2019 09:17:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565021878; cv=none; d=google.com; s=arc-20160816; b=WqkKas+fmx+HIaNNAOLe0V9Tg+6NmVOcarLuXm7N14DJoXoGYjl9SB9ZKESQvB/i6m 5f4nan0x+uV5y0KiNZSx6GMfznZpYTZQ17ts+43kr3ud+7w5vuWimN+gKwb0wyyamV3o 0CQuHYned5rNCuJhc7f9EqnJFeGpzPLGv440gftiEfqoisoQmFN0ATBErOMJK1RjNJcQ zlQelLLuFyJ3XGLHZ32vXKKq0lujXGLL+mADe11dOab4PtDlQsZMn/LU6YOB2GWdlcn3 BhCMWAoZZZWYC0hz66r9W1p2+mz9DRzpiwwhdEl1/cnBfinXuMVaYOgkfs0IYDztQR36 Ptrw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=8JSwEv4a8R7+mCE1lA9x4aC9f4B7aHrznpqSQL85xoU=; b=APFZuYSJMZhuL8AWUMwfu6OLvOTV7XXWFC0sXROrEHMZn5u1FOUUMDu/1ufLrc9pUQ IZpRaZeOf8Mq0q5ipd+q0aowRek7zf1DY5XRtgtYQmJPA1a9UXsX+97HF2/8Sep6D2r1 iT0Gs48jPQlTxsZeblimlWR70TbKYJTdJv24FAcz1ckaVLFPgc0TzbwOy6dUc0rSZ9L4 L13cTYWjQeBF7dH8CTa4NzwL5rZeEXEQq6dMySFcHWVKi5eODAGZsYMTzgMU28jhK2uc +aN/v0KcjBiSMZQN+s7Nw5gpIZe7dxSnf7rfhoLLGEzmE7NVKe4Rlu6K7afkwmQqdt0H zffA== 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 e25si51318321pff.30.2019.08.05.09.17.42; Mon, 05 Aug 2019 09:17:58 -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 S1728918AbfHEQQq (ORCPT + 99 others); Mon, 5 Aug 2019 12:16:46 -0400 Received: from mga09.intel.com ([134.134.136.24]:32039 "EHLO mga09.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726691AbfHEQQq (ORCPT ); Mon, 5 Aug 2019 12:16:46 -0400 X-Amp-Result: UNSCANNABLE X-Amp-File-Uploaded: False Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by orsmga102.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 05 Aug 2019 09:16:45 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.64,350,1559545200"; d="scan'208";a="373754202" Received: from sjchrist-coffee.jf.intel.com (HELO linux.intel.com) ([10.54.74.41]) by fmsmga006.fm.intel.com with ESMTP; 05 Aug 2019 09:16:45 -0700 Date: Mon, 5 Aug 2019 09:16:44 -0700 From: Sean Christopherson To: Jarkko Sakkinen Cc: linux-kernel@vger.kernel.org, x86@kernel.org, linux-sgx@vger.kernel.org, akpm@linux-foundation.org, dave.hansen@intel.com, nhorman@redhat.com, npmccallum@redhat.com, serge.ayoun@intel.com, shay.katz-zamir@intel.com, haitao.huang@intel.com, andriy.shevchenko@linux.intel.com, tglx@linutronix.de, kai.svahn@intel.com, bp@alien8.de, josh@joshtriplett.org, luto@kernel.org, kai.huang@intel.com, rientjes@google.com, cedric.xing@intel.com, Suresh Siddha Subject: Re: [PATCH v21 16/28] x86/sgx: Add the Linux SGX Enclave Driver Message-ID: <20190805161644.GD29275@linux.intel.com> References: <20190713170804.2340-1-jarkko.sakkinen@linux.intel.com> <20190713170804.2340-17-jarkko.sakkinen@linux.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190713170804.2340-17-jarkko.sakkinen@linux.intel.com> User-Agent: Mutt/1.5.24 (2015-08-30) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, Jul 13, 2019 at 08:07:52PM +0300, Jarkko Sakkinen wrote: > +static unsigned long sgx_get_unmapped_area(struct file *file, > + unsigned long addr, > + unsigned long len, > + unsigned long pgoff, > + unsigned long flags) > +{ > + if (flags & MAP_PRIVATE) > + return -EINVAL; > + > + if (flags & MAP_FIXED) > + return addr; > + > + if (len < 2 * PAGE_SIZE || len & (len - 1)) > + return -EINVAL; > + > + addr = current->mm->get_unmapped_area(file, addr, 2 * len, pgoff, > + flags); > + if (IS_ERR_VALUE(addr)) > + return addr; > + > + addr = (addr + (len - 1)) & ~(len - 1); > + > + return addr; > +} Thinking about this more, I don't think the driver should verify or adjust @addr and @len during non-fixed mmap(). There is no requirement that userspace must map the full ELRANGE, or that an enclave's ELRANGE can *never* be mapped to non-EPC. The architectural requirement is that an access that hits ELRANGE must map to the EPC *if* the CPU is executing the associated enclave. This means that a process can have random mappings that overlap an enclave's ELRANGE while the enclave is active, it just can't access that memory from within the enclave. A good example is a large enclave, e.g. 3gb of actual code/data, that userspace wants to locate below 4gb for some reason, e.g. running an unmodified non-enclave binary under graphene. Requiring @addr+@len to be naturally sized and aligned will force @addr to 0x0, which is often disallowed by the kernel.