Received: by 2002:a25:868d:0:0:0:0:0 with SMTP id z13csp1666847ybk; Thu, 21 May 2020 12:14:35 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxKNsWQ3Dg4b6y3O/a/lC80bqceQBDgLH1baLraErZxHIyIxV59VEH3Xc6P+6ln10XKvhs6 X-Received: by 2002:a05:6402:1558:: with SMTP id p24mr228720edx.32.1590088475746; Thu, 21 May 2020 12:14:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1590088475; cv=none; d=google.com; s=arc-20160816; b=PFPLMZrFNMbcrpcLw7VhFNqqfKNFJsqa1Tf5vkw9liL8tYUJsY4IUetg3sYjWHaj6z ILswu2sFtYqM1QmPj9vREc0qAdZjZyM77wyduSeNrt5UbtjL/8U7mB02m5WN/LMeXIId 3pNZ1m8c+AhyQItzXzvGv8XSYprQ9pH6cV7TGUTV30aRSNgR0E7kF9fwo7pMEuv65FRt 9Usi5GWkxrMhGjc0+t2ZwWe6WjuEBWDeA3RpkSBiPivuiK/gZ0hxowyBm7SjE2OIFVx5 wlru61/i7uu/wlWJGZT/Fn5FsLaAhWMJXFGdJNPghkyNs+hj5ueiWeIzcnqlz1UIqhva 4SJw== 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:ironport-sdr:ironport-sdr; bh=LSU3x4IGZHAuh2woUzOepd0uPaNP6qmSTJMJDuzMs5Q=; b=j0zKc/0768atvFzCo1dnmldADwPh2QKSk0NnVrx5KicVeJQs9JZjwN49UCJAVM4BD3 u1uC4KKCmHoP3Fu64meMnPOZy3cS1X4rb9PscZ+tt3zjs8d5ZYPM28oNPsRvvtDquI1m WnNuaz84wziF7IFMITvlXhSTxLAT/xCiYyM67/HDWA122uW+QPicmTnuP+AdrEinNZaz xZdqyxtt+BKWdf8jsfRibwzvDf/mzpiF5g2aGrFPyP25EKZ4LCIH/cki+dqqKkjjC/zU rliu0tKq2l7qtuQQeAESdpXTYspuWooraKlY6KD6uZGnRfCSDOEinu09su3gdxo2qdhU +SxA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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. [23.128.96.18]) by mx.google.com with ESMTP id p15si4068589ejl.201.2020.05.21.12.14.13; Thu, 21 May 2020 12:14:35 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S1730310AbgEUTMn (ORCPT + 99 others); Thu, 21 May 2020 15:12:43 -0400 Received: from mga09.intel.com ([134.134.136.24]:54393 "EHLO mga09.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729548AbgEUTMn (ORCPT ); Thu, 21 May 2020 15:12:43 -0400 IronPort-SDR: WUGujn535E645ts12xvcEdV4hSqc+xtcb7TzyVFlLlsMCJwuC2K/Mj5UQLuw7GvC06tDj8g6RZ PvAMdp6BJi2g== X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 May 2020 12:12:37 -0700 IronPort-SDR: k/gY0kMbbAgEsAcR2SVVvwo0+gbzdvmVDEPkiFO+SzsNMG8QVCti7p6M4jGEEQfa4CY2hW8/rD I5GaEw5gzZ0w== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.73,418,1583222400"; d="scan'208";a="466911464" Received: from sjchrist-coffee.jf.intel.com (HELO linux.intel.com) ([10.54.74.152]) by fmsmga005.fm.intel.com with ESMTP; 21 May 2020 12:12:36 -0700 Date: Thu, 21 May 2020 12:12:36 -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, 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, puiterwijk@redhat.com, linux-security-module@vger.kernel.org, Suresh Siddha , Jethro Beekman , Haitao Huang , Chunyang Hui , Jordan Hand , Seth Moore Subject: Re: [PATCH v30 10/20] x86/sgx: Linux Enclave Driver Message-ID: <20200521191236.GA23043@linux.intel.com> References: <20200515004410.723949-1-jarkko.sakkinen@linux.intel.com> <20200515004410.723949-11-jarkko.sakkinen@linux.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200515004410.723949-11-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 Fri, May 15, 2020 at 03:44:00AM +0300, Jarkko Sakkinen wrote: > +long sgx_ioctl(struct file *filep, unsigned int cmd, unsigned long arg) > +{ > + struct sgx_encl *encl = filep->private_data; > + int ret, encl_flags; > + > + encl_flags = atomic_fetch_or(SGX_ENCL_IOCTL, &encl->flags); > + if (encl_flags & SGX_ENCL_IOCTL) > + return -EBUSY; > + > + if (encl_flags & SGX_ENCL_DEAD) > + return -EFAULT; Returning immediately is wrong as it leaves SGX_ENCL_IOCTL set. This results in the application seeing -EBUSY on future ioctls() instead of -EFAULT. Can be fixed as below. Do you want me to send a formal patch on linux-sgx? diff --git a/arch/x86/kernel/cpu/sgx/ioctl.c b/arch/x86/kernel/cpu/sgx/ioctl.c index 77757a74644d..df35a79e915c 100644 --- a/arch/x86/kernel/cpu/sgx/ioctl.c +++ b/arch/x86/kernel/cpu/sgx/ioctl.c @@ -751,8 +751,10 @@ long sgx_ioctl(struct file *filep, unsigned int cmd, unsigned long arg) if (encl_flags & SGX_ENCL_IOCTL) return -EBUSY; - if (encl_flags & SGX_ENCL_DEAD) - return -EFAULT; + if (encl_flags & SGX_ENCL_DEAD) { + ret = -EFAULT; + goto out; + } switch (cmd) { case SGX_IOC_ENCLAVE_CREATE: @@ -772,6 +774,7 @@ long sgx_ioctl(struct file *filep, unsigned int cmd, unsigned long arg) break; } +out: atomic_andnot(SGX_ENCL_IOCTL, &encl->flags); return ret; > + > + switch (cmd) { > + case SGX_IOC_ENCLAVE_CREATE: > + ret = sgx_ioc_enclave_create(encl, (void __user *)arg); > + break; > + case SGX_IOC_ENCLAVE_ADD_PAGES: > + ret = sgx_ioc_enclave_add_pages(encl, (void __user *)arg); > + break; > + case SGX_IOC_ENCLAVE_INIT: > + ret = sgx_ioc_enclave_init(encl, (void __user *)arg); > + break; > + default: > + ret = -ENOIOCTLCMD; > + break; > + } > + > + atomic_andnot(SGX_ENCL_IOCTL, &encl->flags); > + > + return ret; > +}