Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp4191145rwb; Fri, 30 Sep 2022 14:27:41 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4MrM2aIEtu3L+jjj4u0FXktFQy0D0XZR+a8AoI2mw4HVK9AZWecqW6m8TnDmiLPlcPVBHt X-Received: by 2002:a17:906:fd8d:b0:780:997:8b7b with SMTP id xa13-20020a170906fd8d00b0078009978b7bmr7871867ejb.635.1664573261293; Fri, 30 Sep 2022 14:27:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664573261; cv=none; d=google.com; s=arc-20160816; b=ockOIUq538vK9glRMLMUGMIRO0MIuZ/3VO3ej3n0xTdgaPdLCcy6wODQX1j5IQc5Kg lxwXvSyCrf3wxSOewpeoZ/FkIbmt6JpBDTV6cTVApsCu4l1AximRkclDSkxfrqMLxZZu lOYbWT33XLaV2xLe2+hLwIeXXZmbPnv3ooV3MwroJ+3dsRdqWKYVGQRlPu8NXtXuGtB4 JeBR/jZy9uhL9MCzP8qJkCTwdIDNVfuo4d6TiPY+OCkS2ehtGfzYDpgltfA6OHix+4mz /REL3FzfBSBZ9FoRFbeFKcIJW/nTy4LmWKDTfmA4zcVcpF0Zoyq6S4aErj0Z0g92mZUl zhDA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:to:content-language:subject:user-agent:mime-version:date :message-id:dkim-signature; bh=mLpYiECGaTgfWI7723UoTzwSHUEWX4x3iZ011nnFV5I=; b=Qies7Ou3O5XuiZbHF+RRIN4sx4oWRWbLiAp3rv4e097krq44D/JVf9gMC+K9TAK5Qj OcphmAsVVR7qlJ54edhsg3c4w79YyebHw6EbRTpAJjcHFq9j/xVmoxptD8SLDiXqUHEt +eGl3dtn0S9VXAfD8i6Rcd0zu8o/7ZmaxZGZ8whnR05D6jyFHuZRaQiMeNrTpf4uGVhM BVxpZCB8R1wGPDvHsQ9zAcIz2cF0n1RQaOSjSS4fdgredT/T7oFyrDalChNb9oZMoNts cbAAYYCiVo+27bigI5sznpBuxYPSf8iqXi2fhOZnBC4QAZuPeid9HMJ+6wdmg3PoRtUF zdlg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=B6murggl; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id hc30-20020a170907169e00b007800311e216si2725979ejc.12.2022.09.30.14.27.15; Fri, 30 Sep 2022 14:27:41 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=B6murggl; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231852AbiI3UiB (ORCPT + 99 others); Fri, 30 Sep 2022 16:38:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41216 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231590AbiI3Uh7 (ORCPT ); Fri, 30 Sep 2022 16:37:59 -0400 Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5A3BF1CE635; Fri, 30 Sep 2022 13:37:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1664570277; x=1696106277; h=message-id:date:mime-version:subject:to:references:from: in-reply-to:content-transfer-encoding; bh=dQJ+pcysW2VFlAp5bziLeT5jCGvnyB3q28WBZP0NsgM=; b=B6murgglVUVTaIXn/Tui6i32801TVWpMup79vZJ+9dQP/vRpjZIVa+Lf DnF++bYEBBbRSfBdQIJb8UWqmwsLfUPolTrXipp12kq9IthAOG83SqfTv hgRY5YQGaW2j5utupqsjv1M+HX05kgfgpQqcA05pW12Qf9DjSJebY/XxQ 7rLBxyNynaFdo/9I5LR+kQ2qoCdSDwgt1OWT0p4fyKrVcV+Q8+uMs33PQ 3AaT5Y74wQZGY+KOd8RQ8X19D1SKtkz577splgDwtfc1o7T2qAKp6giBh Taxi87MaHo0OGdOd/bt//HVlQ24DgTCf5fX8Ue0MXnY3h0Yzb5l4dlMFq A==; X-IronPort-AV: E=McAfee;i="6500,9779,10486"; a="299883896" X-IronPort-AV: E=Sophos;i="5.93,358,1654585200"; d="scan'208";a="299883896" Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Sep 2022 13:37:57 -0700 X-IronPort-AV: E=McAfee;i="6500,9779,10486"; a="951683520" X-IronPort-AV: E=Sophos;i="5.93,358,1654585200"; d="scan'208";a="951683520" Received: from lzearing-mobl.amr.corp.intel.com (HELO [10.209.49.67]) ([10.209.49.67]) by fmsmga005-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Sep 2022 13:37:55 -0700 Message-ID: <5994adb0-12b7-b8f1-ecdc-ebf56af48947@intel.com> Date: Fri, 30 Sep 2022 13:37:54 -0700 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.11.0 Subject: Re: [PATCH v2 22/39] mm: Don't allow write GUPs to shadow stack memory Content-Language: en-US To: "Edgecombe, Rick P" , "Shankar, Ravi V" , "bsingharora@gmail.com" , "hpa@zytor.com" , "Syromiatnikov, Eugene" , "peterz@infradead.org" , "rdunlap@infradead.org" , "keescook@chromium.org" , "dave.hansen@linux.intel.com" , "kirill.shutemov@linux.intel.com" , "Eranian, Stephane" , "linux-mm@kvack.org" , "fweimer@redhat.com" , "nadav.amit@gmail.com" , "jannh@google.com" , "dethoma@microsoft.com" , "linux-arch@vger.kernel.org" , "kcc@google.com" , "bp@alien8.de" , "oleg@redhat.com" , "hjl.tools@gmail.com" , "Yang, Weijiang" , "Lutomirski, Andy" , "pavel@ucw.cz" , "arnd@arndb.de" , "Moreira, Joao" , "tglx@linutronix.de" , "mike.kravetz@oracle.com" , "x86@kernel.org" , "linux-doc@vger.kernel.org" , "jamorris@linux.microsoft.com" , "john.allen@amd.com" , "rppt@kernel.org" , "mingo@redhat.com" , "corbet@lwn.net" , "linux-kernel@vger.kernel.org" , "linux-api@vger.kernel.org" , "gorcunov@gmail.com" References: <20220929222936.14584-1-rick.p.edgecombe@intel.com> <20220929222936.14584-23-rick.p.edgecombe@intel.com> <9fed0342-2d02-aaf2-ed66-20ff08bdfd0b@intel.com> <44314145f644ab822ac36cc8c78520d5f34d5bd8.camel@intel.com> From: Dave Hansen In-Reply-To: <44314145f644ab822ac36cc8c78520d5f34d5bd8.camel@intel.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-7.8 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A, RCVD_IN_DNSWL_HI,SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 9/30/22 13:30, Edgecombe, Rick P wrote: > On Fri, 2022-09-30 at 12:16 -0700, Dave Hansen wrote: >> On 9/29/22 15:29, Rick Edgecombe wrote: >>> @@ -1633,6 +1633,9 @@ static inline bool >>> __pte_access_permitted(unsigned long pteval, bool write) >>> { >>> unsigned long need_pte_bits = _PAGE_PRESENT|_PAGE_USER; >>> >>> + if (write && (pteval & (_PAGE_RW | _PAGE_DIRTY)) == >>> _PAGE_DIRTY) >>> + return 0; >> Do we not have a helper for this? Seems a bit messy to open-code >> these >> shadow-stack permissions. Definitely at least needs a comment. > It's because pteval is an unsigned long. We could create a pte_t, and > use the helpers, but then we would be using pte_foo() on pmd's, etc. So > probably comment is the better option? Yeah, a comment is probably best. This is one of those "generic" page table functions that doesn't work well with the p{te,md,ud}_* types. It's either this or cast over to a pteval_t for pmd/pud and pretend this is a pte-only function.