From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-11.7 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,INCLUDES_PATCH,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 087DBC4338F for ; Fri, 30 Jul 2021 00:34:01 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D998760F46 for ; Fri, 30 Jul 2021 00:34:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231888AbhG3AeD (ORCPT ); Thu, 29 Jul 2021 20:34:03 -0400 Received: from mail.kernel.org ([198.145.29.99]:58554 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229523AbhG3AeC (ORCPT ); Thu, 29 Jul 2021 20:34:02 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 99AD260F21; Fri, 30 Jul 2021 00:33:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1627605238; bh=d9GQl5EJTvuOzzjdzsLOUFVFQ1w35Dm5T2hYbZADpB8=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=DZHP12hXIfTDhQb+DNrCpfqjU558IuAuyX6JapTF21RYrhHEpxCNnkinkT275hYlv BZpLy9/OUkT5vwaB5jvvXhxtk990WKj6ANNtDPaOeVtCqbDvmRLYpg1AmknMjcMsZV GfPzhvlyPfb0rrynPV5Z4MNDaEBtMlLT+AVPtf3r/CZgNtSXOZVNNCc8NuyJkZnkQ6 b03LsyYPADtLbc4WDG9oyxsLpe3d6ZQ75As3NbiXR0NWjzuLtyW1B8UQs4Ol0H21gy MFFLutgqIiKmvCQ4cvJ9hde4B3+9ygfNahAG1WR47Ut1LTunDs2YmijbbWo9nsQkb1 PeA4ClBUpHjvA== Date: Fri, 30 Jul 2021 03:33:54 +0300 From: Jarkko Sakkinen To: Dave Hansen Cc: Tony Luck , Sean Christopherson , x86@kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v3 1/7] x86/sgx: Provide indication of life-cycle of EPC pages Message-ID: <20210730003354.xahfbqnjnkexvxh6@kernel.org> References: <20210719182009.1409895-1-tony.luck@intel.com> <20210728204653.1509010-1-tony.luck@intel.com> <20210728204653.1509010-2-tony.luck@intel.com> <17054ca5-0ef7-4b28-ab26-b1b96aa7403f@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <17054ca5-0ef7-4b28-ab26-b1b96aa7403f@intel.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Jul 28, 2021 at 03:12:03PM -0700, Dave Hansen wrote: > On 7/28/21 1:46 PM, Tony Luck wrote: > > +++ b/arch/x86/kernel/cpu/sgx/main.c > > @@ -581,7 +581,7 @@ struct sgx_epc_page *sgx_alloc_epc_page(void *owner, bool reclaim) > > for ( ; ; ) { > > page = __sgx_alloc_epc_page(); > > if (!IS_ERR(page)) { > > - page->owner = owner; > > + page->owner = owner ? owner : page; > > break; > > } > > I'm a little worried about this. > > Let's say we get confused about the type of the page and dereference > page->owner. If it's NULL, we get a nice oops. If it's a real, valid > pointer, we get real valid memory back that we can scribble on. > > Wouldn't it be safer to do something like: > > page->owner = owner ? owner : (void *)-1; > > -1 is non-NULL, but also invalid, which makes it harder for us to poke > ourselves in the eye. Works for me. /Jarkko