Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp325837imm; Fri, 5 Oct 2018 04:34:50 -0700 (PDT) X-Google-Smtp-Source: ACcGV63LrOIanMJjdgT1kSQa/TEznrUAkh8DOsK7V+QE8cfMoW7YvvKha9JqucwiyQLyvt1BaMGM X-Received: by 2002:a62:302:: with SMTP id 2-v6mr11202340pfd.145.1538739290269; Fri, 05 Oct 2018 04:34:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1538739290; cv=none; d=google.com; s=arc-20160816; b=t2NFtCke4yPN0rClGBw++mCdeD46oDFh5woRhrQ2Ts4ylOB6QW2jthw4OUdihhgWZ5 qCGBmYi7ZqooHLUzaCVK/gXL9Ed2je7RZ6+Av054P1R9ie1d0PCVTmfXR3kwiZRRjb+b 18Tv4emE7eg7sWnmXPitrLOlY7IEwKx4VZl6nzVooQTKPa2rpj7v4prwoiyuOx/5iFT8 XD7fPyVa40fySWzeKuc0sotPOCsBjod0ZCSyFkleE517/LgIoZVAc1i1GEQ79ypomtjf 08bZ65DdOhcW0TNCQTgoyS37/CY1V1yaTSzMzQ7o+IR5rCp7nVrmGcUMRQNQJpDZIUKK n5wA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:organization:in-reply-to :content-transfer-encoding:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=3i8AbLt2JeCvJ08svlxYVqn/601u4JIlxlntpOeeDVo=; b=npdNM8kDlZ+KQbOmFQbjvVAuSpBKACJiI3tXJJxyWJXjtaAFni/x+ZEhMIguq7TdZd p/RPhGt/uW7qkRkux5Q8pO2NOu3s2O6rZEl0XMlamqlZ2uZHN4lYpXGhfsDugakYI1tj r/NoZyKA57IAiituWtNXD05ttB662KiuCrRSD50pdNQ6m4EUS6hP5VxUACtJJfi9bYZQ wpwHqqO22fqJoNRYsoMJkcugtFDXGIFbm9YpmeuIl2MgAXctz8QTKbvdAG2WohMOjy3l dY4E3x8RBOWJvxbEUe95mD7kUiAW2hMkClqtDOsxCyxmcqnB+DLS0sRQuMkDfXxYkzdV OZ1w== 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 r10-v6si6676164pgg.259.2018.10.05.04.34.33; Fri, 05 Oct 2018 04:34:50 -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 S1728361AbeJESb0 (ORCPT + 99 others); Fri, 5 Oct 2018 14:31:26 -0400 Received: from mga03.intel.com ([134.134.136.65]:21825 "EHLO mga03.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727581AbeJESb0 (ORCPT ); Fri, 5 Oct 2018 14:31:26 -0400 X-Amp-Result: UNSCANNABLE X-Amp-File-Uploaded: False Received: from orsmga007.jf.intel.com ([10.7.209.58]) by orsmga103.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 05 Oct 2018 04:33:03 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.54,344,1534834800"; d="scan'208";a="78718953" Received: from jsakkine-mobl1.tm.intel.com (HELO localhost) ([10.237.50.74]) by orsmga007.jf.intel.com with ESMTP; 05 Oct 2018 04:32:44 -0700 Date: Fri, 5 Oct 2018 14:32:44 +0300 From: Jarkko Sakkinen To: Sean Christopherson Cc: x86@kernel.org, platform-driver-x86@vger.kernel.org, dave.hansen@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, Suresh Siddha , Thomas Gleixner , Ingo Molnar , Borislav Petkov , "H. Peter Anvin" , Darren Hart , Andy Shevchenko , "open list:X86 ARCHITECTURE (32-BIT AND 64-BIT)" Subject: Re: [PATCH v14 15/19] platform/x86: Intel SGX driver Message-ID: <20181005113244.GB25985@linux.intel.com> References: <20180925130845.9962-1-jarkko.sakkinen@linux.intel.com> <20180925130845.9962-16-jarkko.sakkinen@linux.intel.com> <1538676077.2562.6.camel@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <1538676077.2562.6.camel@intel.com> Organization: Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo User-Agent: Mutt/1.9.4 (2018-02-28) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Oct 04, 2018 at 11:01:17AM -0700, Sean Christopherson wrote: > On Tue, 2018-09-25 at 16:06 +0300, Jarkko Sakkinen wrote: > > Intel Software Guard eXtensions (SGX) is a set of CPU instructions that > > can be used by applications to set aside private regions of code and > > data. The code outside the enclave is disallowed to access the memory > > inside the enclave by the CPU access control. > > > > SGX driver provides a ioctl API for loading and initializing enclaves. > > Address range for enclaves is reserved with mmap() and they are > > destroyed with munmap(). Enclave construction, measurement and > > initialization is done with the provided the ioctl API. > > ... > > > +/** > > + * sgx_ioc_enclave_init - handler for %SGX_IOC_ENCLAVE_INIT > > + * > > + * @filep: open file to /dev/sgx > > + * @cmd: the command value > > + * @arg: pointer to an &sgx_enclave_init instance > > + * > > + * Flushes the remaining enqueued EADD operations and performs EINIT. Does not > > + * allow the EINITTOKENKEY attribute for an enclave. > > + * > > + * Return: > > + *???0 on success, > > + *???SGX error code on EINIT failure, > > + *???-errno otherwise > > + */ > > +static long sgx_ioc_enclave_init(struct file *filep, unsigned int cmd, > > + ?unsigned long arg) > > +{ > > + struct sgx_enclave_init *initp = (struct sgx_enclave_init *)arg; > > + struct sgx_sigstruct *sigstruct; > > + struct sgx_einittoken *einittoken; > > + struct sgx_encl *encl; > > + struct page *initp_page; > > + int ret; > > + > > + initp_page = alloc_page(GFP_HIGHUSER); > > + if (!initp_page) > > + return -ENOMEM; > > + > > + sigstruct = kmap(initp_page); > > + einittoken = (struct sgx_einittoken *) > > + ((unsigned long)sigstruct + PAGE_SIZE / 2); > > + memset(einittoken, 0, sizeof(*einittoken)); > > + > > + ret = copy_from_user(sigstruct, (void __user *)initp->sigstruct, > > + ?????sizeof(*sigstruct)); > > + if (ret) > > + goto out; > > + if (sigstruct->attributes & SGX_ATTR_EINITTOKENKEY) { > > + ret = EINVAL; > > This should be "ret = -EINVAL". Ouch :-( Thank you for spotting this out. /Jarkko