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 900FBC47089 for ; Sat, 3 Dec 2022 02:40:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235173AbiLCCkH (ORCPT ); Fri, 2 Dec 2022 21:40:07 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58310 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235238AbiLCCkE (ORCPT ); Fri, 2 Dec 2022 21:40:04 -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 CEC7AF9E39 for ; Fri, 2 Dec 2022 18:40:03 -0800 (PST) Received: by mail-pj1-x1036.google.com with SMTP id b13-20020a17090a5a0d00b0021906102d05so6674375pjd.5 for ; Fri, 02 Dec 2022 18:40:03 -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:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=XLViDR2zcWqltZaMqOGe9UxH/Um8wO533PT9cRofQvA=; b=T4HzE5jaCq8vZkmDtWPOboOLn6craU7f/b/P8EJ6uRQd8L1E2whKgn4WGwiBS1b7U6 c8zE9oXrXi/eg25YVdEdHOwAzyoEsHNE9+Rf7MSyNkzA0myb+7xNNtjPfTkKgGY2pyyN cXtIAN+AegJpgeHjkS/87VgCfN9Su2eIhsrLw= 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:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=XLViDR2zcWqltZaMqOGe9UxH/Um8wO533PT9cRofQvA=; b=Yf0HIUdMpYOd6vtCgl82jS4Nf5zCfAjxlZafbNO5JBfjYoHPKSiKbjpWpXlURtVmMg itbHjwv21J8+AIFqSj1ysSeFfMyaIMhLeqUhrkC8HrJnSobOrynSXm6skVJucPQnu+1S CcSq7sHdKeDd0LBegrFYONh6XOt6/EW7YTXSgfVFqcfdXzpXuBluXY6Go8yts5aBmi4u wm1aljEYYkm4iqbI8ck7UBRQLetP3uNKve/SOrKRoaPSl509wzBPCDqwNUvE3IqGPo+4 gREQqIuHapK54JEJwxVPy9YSaXZK9MVj5ngyQXw8grg/JqlKLZeJVbZwI5EL8XCYDnu/ jY1g== X-Gm-Message-State: ANoB5pmuDBJ1URB5VHJbfbr/OsGXU7vty3rV3GWR1Jq2mTTesLi4NT/1 EY7tohlA1b/ArdkUhdGrb09Ujw== X-Google-Smtp-Source: AA0mqf5A/xJVhK8c81WSI6tm1qf38hEAd20DFdNPVcIcrs0OziQiD4xi28050EAgthHM5YFZZ45KCA== X-Received: by 2002:a17:903:555:b0:189:959a:84d8 with SMTP id jo21-20020a170903055500b00189959a84d8mr23315184plb.38.1670035203342; Fri, 02 Dec 2022 18:40:03 -0800 (PST) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id cx5-20020a17090afd8500b002135de3013fsm5351942pjb.32.2022.12.02.18.40.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Dec 2022 18:40:02 -0800 (PST) Date: Fri, 2 Dec 2022 18:40:02 -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 Subject: Re: [PATCH v4 24/39] mm: Warn on shadow stack memory in wrong vma Message-ID: <202212021840.D890531@keescook> References: <20221203003606.6838-1-rick.p.edgecombe@intel.com> <20221203003606.6838-25-rick.p.edgecombe@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20221203003606.6838-25-rick.p.edgecombe@intel.com> Precedence: bulk List-ID: X-Mailing-List: linux-api@vger.kernel.org On Fri, Dec 02, 2022 at 04:35:51PM -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 requires some core mm changes to function > properly. > > One sharp edge is that PTEs that are both Write=0 and Dirty=1 are > treated as shadow by the CPU, but this combination used to be created by > the kernel on x86. Previous patches have changed the kernel to now avoid > creating these PTEs unless they are for shadow stack memory. In case any > missed corners of the kernel are still creating PTEs like this for > non-shadow stack memory, and to catch any re-introductions of the logic, > warn if any shadow stack PTEs (Write=0, Dirty=1) are found in non-shadow > stack VMAs when they are being zapped. This won't catch transient cases > but should have decent coverage. It will be compiled out when shadow > stack is not configured. > > In order to check if a pte is shadow stack in core mm code, add default > implmentations for pte_shstk() and pmd_shstk(). > > Tested-by: Pengfei Xu > Tested-by: John Allen > Signed-off-by: Rick Edgecombe Reviewed-by: Kees Cook -- Kees Cook