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 C4567C433FE for ; Mon, 3 Oct 2022 18:24:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229811AbiJCSYR (ORCPT ); Mon, 3 Oct 2022 14:24:17 -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-Google-Smtp-Source: AMsMyM48Fs8gaQUQGBbjWpok2lFT9yYn1cXchH8flHZ8xyiWHgOGJ7sBj0XqkcvhSLNZbKtef4o3rg== 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> 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