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 CF1CBC05027 for ; Sun, 19 Feb 2023 20:44:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231451AbjBSUoC (ORCPT ); Sun, 19 Feb 2023 15:44:02 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43784 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231156AbjBSUoA (ORCPT ); Sun, 19 Feb 2023 15:44:00 -0500 Received: from mail-pl1-x62c.google.com (mail-pl1-x62c.google.com [IPv6:2607:f8b0:4864:20::62c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 57E1014489 for ; Sun, 19 Feb 2023 12:43:58 -0800 (PST) Received: by mail-pl1-x62c.google.com with SMTP id l15so389208pls.1 for ; Sun, 19 Feb 2023 12:43:58 -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=fKpHzd6Tbyr33yS2bO12JJwJSKx89ozdMUK74ZvMWQY=; b=lyB+LBtwPWQHHdKAlNRydMkf2elDFztWlBg6fmvpqXPnZh65qZQww0NMO+8xbYqZB7 U9nfNbftnOH17cvV3hB7fmXC1rwq6ayNMO0P2Oq/eSedQ5vAmiJMfXKM02tjgGZ1jGsy tWqFbd/xVeuocI///kXq5zK9U+wa6hiXFpVGk= 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=fKpHzd6Tbyr33yS2bO12JJwJSKx89ozdMUK74ZvMWQY=; b=yU+qaADdD+cBOKnQmzV3rnbi2SSoXlkvT3yfBs8EIWpUR366cBKjO++0tdtmzRYRYe LNaQhJPSGXJJaA8pw/5asyBhfkpu0fImF2HtLW7rjOxqxpZoPpf93D6TrneVm8YnjP7w szAtk7q/5WCFprYgofGXQek78NiPLcbh8j48DTV9/P/LTBzgqOu2kdK1kt4uMuYGmniL Bj7KkE1UBnJTrwJmQSR/Ca0IzaHDbPay+4JyPuv8Ji5e+7HBemlRJcLqt9PBodJ5b7cB dyCuuozb5xOGezutIKa66OYjPrNnnJWlxliMy0or9DZmmf+RnWn28egK94YRb30dhxpg jwwg== X-Gm-Message-State: AO0yUKWA9aYQ1d3XKRjyTHCEuH35TtUrxopsy4oB5kWOdkLltBNK+FjK PRFfHe8m8zcUgmUHmEKXDuikvA== X-Google-Smtp-Source: AK7set+kcWCM2o49kDDpOvmw8Xuw/R9fB8lqTkZ5n1j58QZPck4H7MjP6asqe7McnmMIWyDzXFGOcw== X-Received: by 2002:a17:903:2305:b0:19a:a4fc:7f80 with SMTP id d5-20020a170903230500b0019aa4fc7f80mr1247862plh.26.1676839437793; Sun, 19 Feb 2023 12:43:57 -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 k3-20020a170902e90300b0019a837be977sm6312881pld.271.2023.02.19.12.43.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 19 Feb 2023 12:43:57 -0800 (PST) Message-ID: <63f28a0d.170a0220.21bf7.b03c@mx.google.com> X-Google-Original-Message-ID: <202302191243.@keescook> Date: Sun, 19 Feb 2023 12:43:56 -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 25/41] x86/mm: Introduce MAP_ABOVE4G References: <20230218211433.26859-1-rick.p.edgecombe@intel.com> <20230218211433.26859-26-rick.p.edgecombe@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230218211433.26859-26-rick.p.edgecombe@intel.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, Feb 18, 2023 at 01:14:17PM -0800, Rick Edgecombe wrote: > The x86 Control-flow Enforcement Technology (CET) feature includes a new > type of memory called shadow stack. This shadow stack memory has some > unusual properties, which require some core mm changes to function > properly. > > One of the properties is that the shadow stack pointer (SSP), which is a > CPU register that points to the shadow stack like the stack pointer points > to the stack, can't be pointing outside of the 32 bit address space when > the CPU is executing in 32 bit mode. It is desirable to prevent executing > in 32 bit mode when shadow stack is enabled because the kernel can't easily > support 32 bit signals. > > On x86 it is possible to transition to 32 bit mode without any special > interaction with the kernel, by doing a "far call" to a 32 bit segment. > So the shadow stack implementation can use this address space behavior > as a feature, by enforcing that shadow stack memory is always crated > outside of the 32 bit address space. This way userspace will trigger a > general protection fault which will in turn trigger a segfault if it > tries to transition to 32 bit mode with shadow stack enabled. > > This provides a clean error generating border for the user if they try > attempt to do 32 bit mode shadow stack, rather than leave the kernel in a > half working state for userspace to be surprised by. > > So to allow future shadow stack enabling patches to map shadow stacks > out of the 32 bit address space, introduce MAP_ABOVE4G. The behavior > is pretty much like MAP_32BIT, except that it has the opposite address > range. The are a few differences though. > > If both MAP_32BIT and MAP_ABOVE4G are provided, the kernel will use the > MAP_ABOVE4G behavior. Like MAP_32BIT, MAP_ABOVE4G is ignored in a 32 bit > syscall. Should the interface refuse to accept both set instead? Reviewed-by: Kees Cook -- Kees Cook