Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp4740205ybi; Mon, 3 Jun 2019 16:47:13 -0700 (PDT) X-Google-Smtp-Source: APXvYqwpVBo3B8LBDxEaHaTipGxph2FIl2F7hlPzdpqIQQwdSUSmzoy0Xd1DGWdB14TaRLNPYnoe X-Received: by 2002:a63:474a:: with SMTP id w10mr14313768pgk.352.1559605632957; Mon, 03 Jun 2019 16:47:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1559605632; cv=none; d=google.com; s=arc-20160816; b=ahUn0LyK5uhzuwOel2ZILGpD/6GOZC95Ylm2Nv6/S2xRQ/OH4aBPhrlsX3qucCd8qm H3MnsyDJWgKymZpIipOlPvHctJT4izHvz2gBjnZf9pLYj9jtYlLUSRnMgTWbRAt+c7lC 7Pu57yASA76LSos3M5XCj65vxpq5J2+v3N7l9EDrJRSfV2CNIXWWY9WqcarGDkDnopPV fdWKst4dFITXmOIRZpbo6P66Y84eZ1Wn/EQob3nxANgRoWjmkon6/E/CY5SMGvNM4uN/ uNhGokjX7hMgqic2lTust6/buT5uG+QzsIU+JZYQyLmuIlH7d7/8NJshNcbsGI/XWXYP 10ZQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:content-transfer-encoding :dlp-reaction:dlp-version:dlp-product:content-language :accept-language:in-reply-to:references:message-id:date:thread-index :thread-topic:subject:cc:to:from; bh=U+cPeew0NObNHR0f0BEPLeEV/v69rAxIEDr+u73gnO8=; b=1B847wMNC8WKVpz2fy/QrVQLclTx9WxUlPRNuyFH7jdENNiLVxoNrmF3rF64rsKWFl eKvryyfYcCi1ZhPnMmi7RcEGHSvWBlJ9QV3gR96PpT2pLAAn8sRlbNVjmyL/D6t4b6kv Vuhjce8ElbIVZHy/xKsiXS9lamxa2Na1KHBsOE31zkWZmoBg5QhNK9oAyYfeibZZmM53 ZnVik6+8M6XVS5PuIzHE0Qh1+RA4x4tkh/JjE0rkxUuEeoCvAEBwR2joPEgkANUD2fQK RlCJGWlHgiByKUDsUM9vcfANJve6mQVF1HsIIFK8wu+bNhC6jCeakUfLW8lwTPijGZho lW8w== 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 g11si19039163pgs.201.2019.06.03.16.46.56; Mon, 03 Jun 2019 16:47:12 -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 S1726464AbfFCXpy convert rfc822-to-8bit (ORCPT + 99 others); Mon, 3 Jun 2019 19:45:54 -0400 Received: from mga17.intel.com ([192.55.52.151]:3668 "EHLO mga17.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726101AbfFCXpx (ORCPT ); Mon, 3 Jun 2019 19:45:53 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga107.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 03 Jun 2019 16:45:52 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.60,548,1549958400"; d="scan'208";a="181334111" Received: from orsmsx102.amr.corp.intel.com ([10.22.225.129]) by fmsmga002.fm.intel.com with ESMTP; 03 Jun 2019 16:45:51 -0700 Received: from orsmsx123.amr.corp.intel.com (10.22.240.116) by ORSMSX102.amr.corp.intel.com (10.22.225.129) with Microsoft SMTP Server (TLS) id 14.3.408.0; Mon, 3 Jun 2019 16:45:46 -0700 Received: from orsmsx116.amr.corp.intel.com ([169.254.7.165]) by ORSMSX123.amr.corp.intel.com ([169.254.1.141]) with mapi id 14.03.0415.000; Mon, 3 Jun 2019 16:45:46 -0700 From: "Xing, Cedric" To: "Christopherson, Sean J" CC: Jarkko Sakkinen , Andy Lutomirski , Stephen Smalley , James Morris , "Serge E . Hallyn" , LSM List , Paul Moore , Eric Paris , "selinux@vger.kernel.org" , Jethro Beekman , "Hansen, Dave" , Thomas Gleixner , "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 , "Roberts, William C" , "Tricca, Philip B" Subject: RE: [RFC PATCH 3/9] x86/sgx: Allow userspace to add multiple pages in single ioctl() Thread-Topic: [RFC PATCH 3/9] x86/sgx: Allow userspace to add multiple pages in single ioctl() Thread-Index: AQHVGAki7TYpY4ZsUk+m4jTej+khLaaJYAJQgAF1XwCAAAjgAP//veIw Date: Mon, 3 Jun 2019 23:45:45 +0000 Message-ID: <960B34DE67B9E140824F1DCDEC400C0F654ED478@ORSMSX116.amr.corp.intel.com> References: <20190531233159.30992-1-sean.j.christopherson@intel.com> <20190531233159.30992-4-sean.j.christopherson@intel.com> <960B34DE67B9E140824F1DCDEC400C0F654ECBBD@ORSMSX116.amr.corp.intel.com> <20190603200804.GG13384@linux.intel.com> <20190603203950.GJ13384@linux.intel.com> In-Reply-To: <20190603203950.GJ13384@linux.intel.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-titus-metadata-40: eyJDYXRlZ29yeUxhYmVscyI6IiIsIk1ldGFkYXRhIjp7Im5zIjoiaHR0cDpcL1wvd3d3LnRpdHVzLmNvbVwvbnNcL0ludGVsMyIsImlkIjoiZTEzYzAxMTAtYzhkNC00MDZhLWFmMjEtMzY1OTQ4YzBhMWRiIiwicHJvcHMiOlt7Im4iOiJDVFBDbGFzc2lmaWNhdGlvbiIsInZhbHMiOlt7InZhbHVlIjoiQ1RQX05UIn1dfV19LCJTdWJqZWN0TGFiZWxzIjpbXSwiVE1DVmVyc2lvbiI6IjE3LjEwLjE4MDQuNDkiLCJUcnVzdGVkTGFiZWxIYXNoIjoibkE2Rm5qdWZyak14eVpBbHk3QUlrYlQreE4wWFVSNE9GclBmWU5zcjhiYlQ5dEVxelJyam9VdDZYalVMMjlpRSJ9 x-ctpclassification: CTP_NT dlp-product: dlpe-windows dlp-version: 11.2.0.6 dlp-reaction: no-action x-originating-ip: [10.22.254.140] Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 8BIT MIME-Version: 1.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org > From: Christopherson, Sean J > Sent: Monday, June 03, 2019 1:40 PM > > On Mon, Jun 03, 2019 at 01:08:04PM -0700, Sean Christopherson wrote: > > On Sun, Jun 02, 2019 at 11:26:09PM -0700, Xing, Cedric wrote: > > > > From: Christopherson, Sean J > > > > Sent: Friday, May 31, 2019 4:32 PM > > > > > > > > +/** > > > > + * sgx_ioc_enclave_add_pages - handler for > > > > +%SGX_IOC_ENCLAVE_ADD_PAGES > > > > + * > > > > + * @filep: open file to /dev/sgx > > > > + * @cmd: the command value > > > > + * @arg: pointer to an &sgx_enclave_add_page instance > > > > + * > > > > + * Add a range of pages to an uninitialized enclave (EADD), and > > > > +optionally > > > > + * extend the enclave's measurement with the contents of the page > (EEXTEND). > > > > + * The range of pages must be virtually contiguous. The SECINFO > > > > +and > > > > + * measurement maskare applied to all pages, i.e. pages with > > > > +different > > > > + * properties must be added in separate calls. > > > > + * > > > > + * EADD and EEXTEND are done asynchronously via worker threads. > > > > +A successful > > > > + * sgx_ioc_enclave_add_page() only indicates the pages have been > > > > +added to the > > > > + * work queue, it does not guarantee adding the pages to the > > > > +enclave will > > > > + * succeed. > > > > + * > > > > + * Return: > > > > + * 0 on success, > > > > + * -errno otherwise > > > > + */ > > > > +static long sgx_ioc_enclave_add_pages(struct file *filep, > unsigned int cmd, > > > > + unsigned long arg) > > > > +{ > > > > + struct sgx_enclave_add_pages *addp = (void *)arg; > > > > + struct sgx_encl *encl = filep->private_data; > > > > + struct sgx_secinfo secinfo; > > > > + unsigned int i; > > > > + int ret; > > > > + > > > > + if (copy_from_user(&secinfo, (void __user *)addp->secinfo, > > > > + sizeof(secinfo))) > > > > + return -EFAULT; > > > > + > > > > + for (i = 0, ret = 0; i < addp->nr_pages && !ret; i++) { > > > > + if (signal_pending(current)) > > > > + return -ERESTARTSYS; > > > > > > If interrupted, how would user mode code know how many pages have > been EADD'ed? > > > > Hmm, updating nr_pages would be fairly simple and shouldn't confuse > > userspace, e.g. as opposed to overloading the return value. > > Or maybe update @addr and @src as well? That would allow userspace to > re-invoke the ioctl() without having to modify the struct. How about returning the number of pages (or bytes) EADD'ed, similar to write() syscall?