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 Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 30D01C636CC for ; Sun, 19 Feb 2023 20:42:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231276AbjBSUl7 (ORCPT ); Sun, 19 Feb 2023 15:41:59 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42094 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230090AbjBSUl6 (ORCPT ); Sun, 19 Feb 2023 15:41:58 -0500 Received: from mail-pj1-x1036.google.com (mail-pj1-x1036.google.com [IPv6:2607:f8b0:4864:20::1036]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 46CF418B01 for ; Sun, 19 Feb 2023 12:41:57 -0800 (PST) Received: by mail-pj1-x1036.google.com with SMTP id x23so1240964pje.2 for ; Sun, 19 Feb 2023 12:41:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=in-reply-to:content-disposition:mime-version:references:subject:cc :to:from:date:message-id:from:to:cc:subject:date:message-id:reply-to; bh=+n51xriYqbsbmvYxxt4ftJ/ywsWPB5yxY3XzOVKdQok=; b=HRzIL01EiKj/B1V4WeH7nE3SXQQTw+bANhZZ8/P4v4m9JiU3rQDUDjq7P6TKtP1rny vCDVBdBy2yNcsh7+DwfKoYd/3bLIxn7mf2cOxU2YAI1Df8480mfwgGzhWANf1AJ1vmBE iifkkTIsXn3XmVPq4cxEpzRJEyv/l4CEuJZOk= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-disposition:mime-version:references:subject:cc :to:from:date:message-id:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=+n51xriYqbsbmvYxxt4ftJ/ywsWPB5yxY3XzOVKdQok=; b=BOcdNWsG1exNtb4QIzMBaY2P7+fatK9ayYKdN9/0ddfu8uuvdVZbfepD44kgopakQs hvj+XDfpOb+UI9lQFOHAlspHYXPv7MAyHQom8xVL/U1Vsdx51z2ZEPYgw6CxeCar3xa9 RdjHEs3iEjNb7AxKtwyxUDPQ3v6dN1D37hLMcAeJzP44VxlDBolYkcZsc9yLeq1xH+ne 93/aa+KYEIzbW0qQQzVU+4LLK72s0SrkiUx7XxCMaDBvBSOZB6guWf4drG3yI6/hTNz0 gCp/LglXIbTO5DD/JhE4j2nU/vS69LtWS8bRoxFaRM1K6A/n2/GPylIzzTwUCmeE/UV/ oRKA== X-Gm-Message-State: AO0yUKWnQJVgEzg8cJDi5V0VFCt1hxDJ304UOobvv3xavACJb/8Xqs4f NFVtl7mXys5kaRjZfdS/qv6LZQ== X-Google-Smtp-Source: AK7set/hmfWCZDm8xxBH1RGSdTrSPtAkyiRqs8cvWgzZE55+0av+de2ucJ0TWqIBTxeOu8W9SRaPTg== X-Received: by 2002:a17:902:d502:b0:196:8292:e879 with SMTP id b2-20020a170902d50200b001968292e879mr3763331plg.1.1676839316745; Sun, 19 Feb 2023 12:41:56 -0800 (PST) Received: from www.outflux.net (198-0-35-241-static.hfc.comcastbusiness.net. [198.0.35.241]) by smtp.gmail.com with ESMTPSA id a8-20020a1709027e4800b0019a8597788csm829072pln.0.2023.02.19.12.41.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 19 Feb 2023 12:41:56 -0800 (PST) Message-ID: <63f28994.170a0220.e86dc.1134@mx.google.com> X-Google-Original-Message-ID: <202302191241.@keescook> Date: Sun, 19 Feb 2023 12:41:55 -0800 From: Kees Cook To: Rick Edgecombe Cc: x86@kernel.org, "H . Peter Anvin" , Thomas Gleixner , Ingo Molnar , linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, linux-mm@kvack.org, linux-arch@vger.kernel.org, linux-api@vger.kernel.org, Arnd Bergmann , Andy Lutomirski , Balbir Singh , Borislav Petkov , Cyrill Gorcunov , Dave Hansen , Eugene Syromiatnikov , Florian Weimer , "H . J . Lu" , Jann Horn , Jonathan Corbet , Mike Kravetz , Nadav Amit , Oleg Nesterov , Pavel Machek , Peter Zijlstra , Randy Dunlap , Weijiang Yang , "Kirill A . Shutemov" , John Allen , kcc@google.com, eranian@google.com, rppt@kernel.org, jamorris@linux.microsoft.com, dethoma@microsoft.com, akpm@linux-foundation.org, Andrew.Cooper3@citrix.com, christina.schimpe@intel.com, david@redhat.com, debug@rivosinc.com Subject: Re: [PATCH v6 20/41] x86/mm: Teach pte_mkwrite() about stack memory References: <20230218211433.26859-1-rick.p.edgecombe@intel.com> <20230218211433.26859-21-rick.p.edgecombe@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230218211433.26859-21-rick.p.edgecombe@intel.com> Precedence: bulk List-ID: X-Mailing-List: linux-api@vger.kernel.org On Sat, Feb 18, 2023 at 01:14:12PM -0800, Rick Edgecombe wrote: > If a VMA has the VM_SHADOW_STACK flag, it is shadow stack memory. So > when it is made writable with pte_mkwrite(), it should create shadow > stack memory, not conventionally writable memory. Now that pte_mkwrite() > takes a VMA, and places where shadow stack memory might be created pass > one, pte_mkwrite() can know when it should do this. > > So make pte_mkwrite() create shadow stack memory when the VMA has the > VM_SHADOW_STACK flag. Do the same thing for pmd_mkwrite(). > > This requires referencing VM_SHADOW_STACK in these functions, which are > currently defined in pgtable.h, however mm.h (where VM_SHADOW_STACK is > located) can't be pulled in without causing problems for files that > reference pgtable.h. So also move pte/pmd_mkwrite() into pgtable.c, where > they can safely reference VM_SHADOW_STACK. > > Tested-by: Pengfei Xu > Signed-off-by: Rick Edgecombe Is there any realistic performance impact from making these not inline now? Reviewed-by: Kees Cook -- Kees Cook