Received: by 2002:ab2:7a09:0:b0:1f8:46dc:890e with SMTP id k9csp32282lqo; Wed, 15 May 2024 07:02:22 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWh3lmm3NiP3yLNXUkwbrC3+n+wfKsc1Syoqw6nn+3bCERNdOBRTzeysDJhzSQMpVzv+jafXK/qbF/mWWMnQay5B7n4z7KA6NLVW2wwwQ== X-Google-Smtp-Source: AGHT+IGakD+Mc4l19Z0vOTBvKYx/aYEDroMHEczysoxqqFwQyUSQGpMvyWAYM+yL/OqwZGeRuC5G X-Received: by 2002:a17:902:f681:b0:1e3:e093:b5f0 with SMTP id d9443c01a7336-1ef43d0adadmr215363095ad.8.1715781742296; Wed, 15 May 2024 07:02:22 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715781742; cv=pass; d=google.com; s=arc-20160816; b=O1XpFg+Eo/YEvXcctyRW8IyWcT4GghPfMVUl/s3jtcuxeiTDvw0r6f1H0lgYg2u4Ze HTZWfd+gzp+3jeHNiAGJnCBUvZpgZ6fNYbScrafQ386elnP6tYAFlKLA3Cz7V7opqoyn yIMAGXqe3qW0P5cMAj7LAe2/dl8SekuNw0D3EDowpY18bYjm19qEPT0lubxkP833i/t5 vtY6Oh8Tu5+Nd3Qf4+hAfJh39XTfTn4vI4eBsmp9bnHdy7FPXmAJHPkvb5e3VDEmToWD rUOh3coi1yxCKWU2RJa6TbjI1Ekkf3f4D0POikl4i5xXcrqJ08PalQ+7wY5LO3mEBus7 4enA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:references:from:subject:cc:to:message-id:date :content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:dkim-signature; bh=84MhrfLAfPZ4rzDAENlLpFr/kzDWhj6ZrRe88WKC8s8=; fh=vK/LsacQu4awtGTknndUOKCWK0ktsy/FiEliIVGZcD0=; b=oOHxZT91B1oHIBBg4vfULHhvuTo0eAES8SyYBWxTQWQhkPNwMIoMEZQ97CkrgvwLQT la5FaM4PzeB/YXpUsv6tvc8Z+kD/QRdaIq5frpDeOy6v27uI31DbQJG57VPDXdjwjmqv befOI+eAnUBZZyw9MCnMXs1N08R++TPg/wyHTTMFSyHTlLFKDfuyaB841iaS3jd+Vk81 JAZ98HZMyRZyml+meQeGKfBQcQhmipZ9eZniyGRX93XO2Hfq3nmYSN7RqYj9+T8hmM6j KSJn1fwnmnUWpwHecuFpEHLit0nf6vT3tXgdMMM8izSNE28iINLuG1DtAWsEK149wth0 012w==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=HUjyS7Qa; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-179951-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-179951-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id d9443c01a7336-1ef0bf3163esi136268185ad.286.2024.05.15.07.02.21 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 May 2024 07:02:22 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-179951-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=HUjyS7Qa; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-179951-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-179951-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 06B14B23430 for ; Wed, 15 May 2024 13:56:55 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id AF9F713F421; Wed, 15 May 2024 13:56:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="HUjyS7Qa" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D3DBD57CA1; Wed, 15 May 2024 13:56:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715781394; cv=none; b=hdFAjlMSgo6xdpwd7/A1mig2mwhSHojM3CS3Z3fSjcU+MQdJt0O3Fg5C7LFtpHxcd96nlzfMWtIQTpvq+XdzWYr0ifo4ATvyQGjQROjPjqTTBi4WFEV4eoOL+uoBdZbqUrhHWD9BkzamqrevTvwCDiR/Aj1Ih+fEpcMkXDqVpYs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715781394; c=relaxed/simple; bh=x5d5maiHYQceAd2mdSo7gyBviByo2OZ+3BbIm3Oj2T4=; h=Mime-Version:Content-Type:Date:Message-Id:To:Cc:Subject:From: References:In-Reply-To; b=di6tnSoqOvJaNnH3liGvNncoP47xxkhWcdFqgSQXD1Gy2NjWJ6l2x7FoAdm8A6sSoEXWfzcp1mKBOLdViAyGu8yMR+HR9+uq5yA6rFLlem4MBLLsgNRScPZ7wrA6UlUAkVqfdKHKfvZnPrpo4em9O9QmVJ4KFUO4d4eJYMdCATk= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=HUjyS7Qa; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id F172DC116B1; Wed, 15 May 2024 13:56:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1715781394; bh=x5d5maiHYQceAd2mdSo7gyBviByo2OZ+3BbIm3Oj2T4=; h=Date:To:Cc:Subject:From:References:In-Reply-To:From; b=HUjyS7Qa8zShSh+L6xvl2u3ru30ewgN07Pi7AJnUIjJqSnbGdNs1eIIhbCzwSCBQb 0pt/nEhcuTg+kfv/pVRd/BSZXseGv58KzHN9Elp+JSnnouVfX2P3zvE3qqG/SXPwz2 nWfjryzIQKbMJGeFNFyx3TFk3s7hLXc5VKIoM257DF0CJxFdZqKoLGrlX0fqQTJBeh 8YiuOkQEGbqQD9fZt9YjFwgm+h2IMRWublOlacp0pnpEUIMA6Xtv4/b5Xxu9HF148l jNVIwLutbCy2CD1n3/cdKywlBWfBR/+61rDRtfsyYasnrDpz+5aZlScY0gj52UxZ6m Clm1gN04v+PMw== Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8 Date: Wed, 15 May 2024 16:56:30 +0300 Message-Id: To: "Jarkko Sakkinen" , "Dmitrii Kuvaiskii" , , , , , , Cc: , , , =?utf-8?q?Marcelina_Ko=C5=9Bcielnicka?= Subject: Re: [PATCH v2 1/2] x86/sgx: Resolve EAUG race where losing thread returns SIGBUS From: "Jarkko Sakkinen" X-Mailer: aerc 0.17.0 References: <20240515131240.1304824-1-dmitrii.kuvaiskii@intel.com> <20240515131240.1304824-2-dmitrii.kuvaiskii@intel.com> In-Reply-To: On Wed May 15, 2024 at 4:54 PM EEST, Jarkko Sakkinen wrote: > On Wed May 15, 2024 at 4:12 PM EEST, Dmitrii Kuvaiskii wrote: > > diff --git a/arch/x86/kernel/cpu/sgx/encl.c b/arch/x86/kernel/cpu/sgx/e= ncl.c > > index 279148e72459..41f14b1a3025 100644 > > --- a/arch/x86/kernel/cpu/sgx/encl.c > > +++ b/arch/x86/kernel/cpu/sgx/encl.c > > @@ -382,8 +382,11 @@ static vm_fault_t sgx_encl_eaug_page(struct vm_are= a_struct *vma, > > * If ret =3D=3D -EBUSY then page was created in another flow while > > * running without encl->lock > > */ > > - if (ret) > > + if (ret) { > > + if (ret =3D=3D -EBUSY) > > + vmret =3D VM_FAULT_NOPAGE; > > goto err_out_shrink; > > + } > > I agree that there is a bug but it does not categorize as race > condition. > > The bug is simply that for a valid page SIGBUS might be returned. > The fix is correct but the claim is not. > > > =20 > > pginfo.secs =3D (unsigned long)sgx_get_epc_virt_addr(encl->secs.epc_p= age); > > pginfo.addr =3D encl_page->desc & PAGE_MASK; > > @@ -419,7 +422,7 @@ static vm_fault_t sgx_encl_eaug_page(struct vm_area= _struct *vma, > > err_out_shrink: > > sgx_encl_shrink(encl, va_page); > > err_out_epc: > > - sgx_encl_free_epc_page(epc_page); > > + sgx_free_epc_page(epc_page); > > err_out_unlock: > > mutex_unlock(&encl->lock); > > kfree(encl_page); > > Agree with code change 100% but not with the description. > > I'd cut out 90% of the description out and just make the argument of > the wrong error code, and done. The sequence is great for showing > how this could happen. The prose makes my head hurt tbh. Also please remember that stable maintainers need to read all of that if this is a bug fix (it is a bug fix!) :-) So shorted possible legit argument, no prose and the sequence was awesome :-) BR, Jarkko