Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp627938ybt; Mon, 6 Jul 2020 18:39:28 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxUFe3ZyAY5iBfPGoUVuTLY+6CUgmCBbRIlm8+kLvnuxcETlYx6yvxZtwzjWjx6hmokX9el X-Received: by 2002:a05:6402:377:: with SMTP id s23mr60134178edw.200.1594085968807; Mon, 06 Jul 2020 18:39:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1594085968; cv=none; d=google.com; s=arc-20160816; b=uNOIftNEBN+GPXXky1okBR9GQTQdaVoIzZ+OsxuNiZRgqfE8K+pC168O0mMUx28Xha XA1pSy6Q8lJXamFfoi2bzxpoRygsY+g0THoShWV53hcs1+ND+VDoVO9ghBPkUZ3N0Zjl 42zfUY+tfR2CJpF3IZqay5l2hLNEpfln/53bnRQHtxai4H3CqjzvuPnvV62APCgtTSxP fVTFWtwcHRj18Yeo1S+3e6HVl/TbKELAceVTeyVOcuR56HLfSLEdjxUvgF2vGaazPfKc N3bcUY1vnBYdBxqJJ7h3sVV5I1eCywWkL8BbJE30gv7mdQKFpdEC0lfNb6cZ0rXMtblT ufAw== 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=eJ9RA3gWjS3Mw4o9YOqQQC3iDeFSbhhkLig1xPk3DLQ=; b=m6LTMcFxLsiZn4H/Mvq5cS17l/ar1Qtva86q75cFjHDbEg7dR+Cf3PCKZhmnX7xnYK Su/IXo3tASz3YKC+0dqAPto1xo3mMrVLR8dYgPNb8LWUC4j0vOjmdqAGYQ5wBWP73mOK dO0tdKDbzegsaI01gd2X6XukMAC1kSIuk7kj4cH4cWDIPhrn+tihp23oaINIJqVcgx9l mojIAYs30SOyPFBheZGro9QoN9qnmmU+jb2Cd9oE5HODF0Or22yIojDMZ2LdJ56HHrrw oKzF0jVmGhs3yuwpHXrRFLs7CVKMekIJZvmALP1mTKwJS1WpmAUI/o91FIvjKxFxt7oG jXxg== 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 dk28si13770237edb.425.2020.07.06.18.39.05; Mon, 06 Jul 2020 18:39:28 -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 S1727800AbgGGBiv (ORCPT + 99 others); Mon, 6 Jul 2020 21:38:51 -0400 Received: from mga02.intel.com ([134.134.136.20]:3039 "EHLO mga02.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726918AbgGGBiv (ORCPT ); Mon, 6 Jul 2020 21:38:51 -0400 IronPort-SDR: Odkbv3dVhoA0LfDOXX4suN/M90b1oBI0SIFoTn3JVx9QUeJfzNYsiVeEZ8d6R/mjwe0kLwij9h OqzbSSeIO9cg== X-IronPort-AV: E=McAfee;i="6000,8403,9674"; a="135771121" X-IronPort-AV: E=Sophos;i="5.75,321,1589266800"; d="scan'208";a="135771121" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Jul 2020 18:38:50 -0700 IronPort-SDR: N6EhlS0iUivgj4zya6xZwoTiqdEPatwNqUtTnrXwjEXBdm2xzppeYyL9TdOyuMD52XFk7nOG/S M2M8A6fMbY3w== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.75,321,1589266800"; d="scan'208";a="388353713" Received: from sjchrist-coffee.jf.intel.com (HELO linux.intel.com) ([10.54.74.152]) by fmsmga001.fm.intel.com with ESMTP; 06 Jul 2020 18:38:47 -0700 Date: Mon, 6 Jul 2020 18:38:47 -0700 From: Sean Christopherson To: Jarkko Sakkinen Cc: Borislav Petkov , x86@kernel.org, linux-sgx@vger.kernel.org, linux-kernel@vger.kernel.org, linux-security-module@vger.kernel.org, Jethro Beekman , Haitao Huang , Chunyang Hui , Jordan Hand , Nathaniel McCallum , Seth Moore , Suresh Siddha , akpm@linux-foundation.org, andriy.shevchenko@linux.intel.com, asapek@google.com, cedric.xing@intel.com, chenalexchen@google.com, conradparker@google.com, cyhanish@google.com, dave.hansen@intel.com, haitao.huang@intel.com, josh@joshtriplett.org, kai.huang@intel.com, kai.svahn@intel.com, kmoy@google.com, ludloff@google.com, luto@kernel.org, nhorman@redhat.com, puiterwijk@redhat.com, rientjes@google.com, tglx@linutronix.de, yaozhangx@google.com Subject: Re: [PATCH v33 11/21] x86/sgx: Linux Enclave Driver Message-ID: <20200707013847.GA5208@linux.intel.com> References: <20200617220844.57423-1-jarkko.sakkinen@linux.intel.com> <20200617220844.57423-12-jarkko.sakkinen@linux.intel.com> <20200627174335.GC15585@zn.tnic> <20200629152718.GA12312@linux.intel.com> <20200704014349.GB129411@linux.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200704014349.GB129411@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 04, 2020 at 04:43:49AM +0300, Jarkko Sakkinen wrote: > On Mon, Jun 29, 2020 at 08:27:19AM -0700, Sean Christopherson wrote: > > On Sat, Jun 27, 2020 at 07:43:35PM +0200, Borislav Petkov wrote: > > > And you could do similar sanity checks in the other ioctl functions. > > > > Ya, as above, SGX_ENCL_INITIALIZED can be checked here. > > > > SGX_ENCL_DEAD is actually already checked in in the top level sgx_ioctl(), > > i.e. the check in sgx_encl_add_page() can technically be flat out dropped. > > > > I say "technically" because I'm a bit torn over SGX_ENCL_DEAD; encl->lock > > must be held to SGX_ENCL_DEAD (the page fault and reclaim flows rely on > > this), but as it stands today only ioctl() paths (guarded by SGX_ENCL_IOCTL) > > and sgx_release() (makes the ioctls() unreachable) set SGX_ENCL_DEAD. > > > > So it's safe to check SGX_ENCL_DEAD from ioctl() context without holding > > encl->lock, at least in the current code base, but it feels weird/sketchy. > > > > In the end I don't think I have a strong opinion. Removing the technically > > unnecessary DEAD check in sgx_encl_add_page() is the simplest change, so it > > may make sense to do that and nothing more for initial upstreaming. Long > > term, I fully expect we'll add paths that set SGX_ENCL_DEAD outside of > > ioctl() context, e.g. to handle EPC OOM, but it wouldn't be a bad thing to > > have a standalone commit in a future series to add DEAD checks (under > > encl->lock) in the ADD and INIT flows. > > AFAIK nonne of th ioctl's should not need SGX_ENCL_DEAD check. I can't tell if the double negative was intended, but I took a peek at your current master and see that you removed the SGX_ENCL_DEAD check in sgx_ioctl(). That check needs to stay, e.g. if EEXTEND fails we absolutely need to prevent any further operations on the enclave. The above was calling out that additional checks on SGX_ENCL_DEAD after acquiring encl->lock are not necessary because SGX_ENCL_DEAD can only be set when the ioctls() are no longer reachable or from within an ioctl(), which provides exclusivity via SGX_ENCL_IOCTL.