Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp3275095rwb; Mon, 3 Oct 2022 12:17:20 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7Kl2co9A6VMwsiavZZtlyCxpkNQT+fXw/t42erQU67JvE/mow63O6DX3eQ1juOLWz9iWby X-Received: by 2002:a17:90b:3b47:b0:202:a81f:4059 with SMTP id ot7-20020a17090b3b4700b00202a81f4059mr13817891pjb.150.1664824640388; Mon, 03 Oct 2022 12:17:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664824640; cv=none; d=google.com; s=arc-20160816; b=Cp9huRn7VhscehzWwQhjav7HFzMz48gmQBgWP87aHMXBqsNMtVWUZgyhKQrvw1E4gb Q0gz4p9940baDawj2JrUNNsb9Mkbf5N9uARPuo6+Bze2QRJH1NwBqWNPCkYTD8/N3Tig jPa+Ls3DLYOoUCCSjyW5QUhTk9dAcE5Nsd9ybr8Y1+xwtUlpJvs61s2NzXMwtFNu0a7i Zbw9hRa+uE79Ad0+uE1a0/etocA0HsVcUNfFokhtO/MnPiGlvLubdJFSjnRWfWSO7Ivd iuSdDC1dNYYjqYVSz+Lk1k9jjMrEHv1+tuM0LhKfR2AB4j0XwKBunsznZ0Xh3MhVAcyW 5cFw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=wwu9lS4IvfCeN8Phj9REKX62enam27neFFF0OO9ppKE=; b=YuR98Z0OafPJRo+N5ptAWngMXbSk08PWjogcjHTRKefn3ztswM/ujEyg5Ej+y9tELm xuanFITRxQ+IJLJdhuhVjI+UC/Xxbgz6a4DqpMMJKetuThOEX586Ib5I9ElsdT/QQvc2 uyNP5iiqSOYcG5/UFe9kioul9Lpykr57EhrF5N4PZ5+Ef25HakcDvRXIbMbnXIegQsHM LEmV0NOdsxRvX3G4+69yT8FuDps9BA5DxDiW/++ogYja5d5WaJ/3zdcfo48EFudG8iwY jyxr/oojin+1osj4zSl8HFCnplB0Xb03SmzwT3gMNjdIbhGfINc0OTQ2PlX5loZ01g6p phHA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=lKYqWl6A; 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=chromium.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id x70-20020a638649000000b0044eb52cc6cesi3864430pgd.574.2022.10.03.12.17.08; Mon, 03 Oct 2022 12:17:20 -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=@chromium.org header.s=google header.b=lKYqWl6A; 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=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229717AbiJCSYQ (ORCPT + 99 others); Mon, 3 Oct 2022 14:24:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49460 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229905AbiJCSYO (ORCPT ); Mon, 3 Oct 2022 14:24:14 -0400 Received: from mail-pl1-x632.google.com (mail-pl1-x632.google.com [IPv6:2607:f8b0:4864:20::632]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9B98F422F2 for ; Mon, 3 Oct 2022 11:24:10 -0700 (PDT) Received: by mail-pl1-x632.google.com with SMTP id c24so10415764plo.3 for ; Mon, 03 Oct 2022 11:24:10 -0700 (PDT) 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; bh=wwu9lS4IvfCeN8Phj9REKX62enam27neFFF0OO9ppKE=; b=lKYqWl6A7r7Sr3/E8BW6VSg1cqafipTQuK3eeQGyiGtbferERJ1wgzXHmp//KGEi2u 8h9uWTewlGL3XnZ5UgKRaznBiAGYZQBq50XP0umLoU6PolD2t32jNaRYebTAta7cD5AD ZPlpGlvp8IeKDGNn/JAOTfP3n9rQeemlrq1uE= 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; bh=wwu9lS4IvfCeN8Phj9REKX62enam27neFFF0OO9ppKE=; b=jeyjw9qdgSmW8q2NRUIG6OzMJ/XhVPp2vNdjRmPgcDHH5+QP0Y2ydpg7n1xLoMOz3N QaZrXMYMV0zkREeeUKfjX4N0d7Yh/nzBNkwpOFe9Lyvh1yC5p+IgQ5xZ3Dw6VtYLpckC KdJfMA2j1+lJmm21e5xAtoFHp9qX5D5Mg7huVIzq5OYh4puE3zZe4Q/lzNUvG8Tp+hqm DJBp7ARDWkQZy896DaU/WTpKVuRbR3mGBpLdzWibRAaTPYRC7sFQtcMXKKvz66+Snizc grGznCW3S7s8b/KZeKYS2IqdtsN9YfNBkAv1oW35+7Gap+LMynjUdLV7aJ/2w/xrqwNf lLEw== X-Gm-Message-State: ACrzQf1OrdGNX0KmJ7rmnywjA4MyhpQKtQndZ1gQkLgSjZx+xI9eKG14 VYQ2oJkv+kedulIZchvfhZ41iw== X-Received: by 2002:a17:902:b589:b0:179:f8c5:7212 with SMTP id a9-20020a170902b58900b00179f8c57212mr23373642pls.174.1664821449445; Mon, 03 Oct 2022 11:24:09 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id y1-20020a626401000000b0053e8f4a10c1sm7717403pfb.217.2022.10.03.11.24.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Oct 2022 11:24:08 -0700 (PDT) Date: Mon, 3 Oct 2022 11:24:07 -0700 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 , "Ravi V . Shankar" , Weijiang Yang , "Kirill A . Shutemov" , joao.moreira@intel.com, John Allen , kcc@google.com, eranian@google.com, rppt@kernel.org, jamorris@linux.microsoft.com, dethoma@microsoft.com, Yu-cheng Yu Subject: Re: [PATCH v2 17/39] mm: Fixup places that call pte_mkwrite() directly Message-ID: <202210031124.81D807B6B@keescook> References: <20220929222936.14584-1-rick.p.edgecombe@intel.com> <20220929222936.14584-18-rick.p.edgecombe@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220929222936.14584-18-rick.p.edgecombe@intel.com> X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS 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 Thu, Sep 29, 2022 at 03:29:14PM -0700, Rick Edgecombe wrote: > From: Yu-cheng Yu > > With the introduction of shadow stack memory there are two ways a pte can > be writable: regular writable memory and shadow stack memory. > > In past patches, maybe_mkwrite() has been updated to apply pte_mkwrite() > or pte_mkwrite_shstk() depending on the VMA flag. This covers most cases > where a PTE is made writable. However, there are places where pte_mkwrite() > is called directly and the logic should now also create a shadow stack PTE > in the case of a shadow stack VMA. > > - do_anonymous_page() and migrate_vma_insert_page() check VM_WRITE > directly and call pte_mkwrite(), which is the same as maybe_mkwrite() > in logic and intention. Just change them to maybe_mkwrite(). > > - When userfaultfd is creating a PTE after userspace handles the fault > it calls pte_mkwrite() directly. Teach it about pte_mkwrite_shstk() > > In other cases where pte_mkwrite() is called directly, the VMA will not > be VM_SHADOW_STACK, and so shadow stack memory should not be created. > - In the case of pte_savedwrite(), shadow stack VMA's are excluded. > - In the case of the "dirty_accountable" optimization in mprotect(), > shadow stack VMA's won't be VM_SHARED, so it is not nessary. > > Signed-off-by: Yu-cheng Yu Reviewed-by: Kees Cook -- Kees Cook