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 X-Spam-Level: X-Spam-Status: No, score=-11.1 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C75BCC433E0 for ; Thu, 4 Feb 2021 20:22:58 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 44D6A64F59 for ; Thu, 4 Feb 2021 20:22:58 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 44D6A64F59 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=chromium.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id BC6996B006E; Thu, 4 Feb 2021 15:22:57 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id B9CBE6B0070; Thu, 4 Feb 2021 15:22:57 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id AB43F6B0071; Thu, 4 Feb 2021 15:22:57 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0074.hostedemail.com [216.40.44.74]) by kanga.kvack.org (Postfix) with ESMTP id 9608F6B006E for ; Thu, 4 Feb 2021 15:22:57 -0500 (EST) Received: from smtpin29.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 6347A1EF1 for ; Thu, 4 Feb 2021 20:22:57 +0000 (UTC) X-FDA: 77781709194.29.F810938 Received: from mail-pf1-f179.google.com (mail-pf1-f179.google.com [209.85.210.179]) by imf08.hostedemail.com (Postfix) with ESMTP id 3AF3E80191F4 for ; Thu, 4 Feb 2021 20:22:56 +0000 (UTC) Received: by mail-pf1-f179.google.com with SMTP id f63so2800723pfa.13 for ; Thu, 04 Feb 2021 12:22:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=388dygswvemg3Mj3TiR7mQNJ/V6JIsMVBitRKVSrLsY=; b=YBxlqh3o4VbdvCSD8fiFV07eUilq+0xn80cMGEG4eVl46Gc/k3lWSMs/5g7fP5iXe1 MHCEVDlZsBWs6S/5TBVbdo/n3Twj70ulawIUmo04ahBphIU6j6i7QJqqkR6EQp9e/h2D vytPtTBr/gks7MTZzAPC5ap2f0bLl9MipDB0A= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=388dygswvemg3Mj3TiR7mQNJ/V6JIsMVBitRKVSrLsY=; b=dKSxCB0DN0Y6eIxcpJLlW8ngQw4CZNeHBc0i3yI0jNRklhSq5vvqr3mDcYMKE8xffD GRhmFvj6bEyq7/wndDCO4urpBiryzpE6H2jqLM84WYoXhRZmwhq3ptqvQYgwH4xtSeLs bbMY8EP7Sk18MYrz76HgBGqEmVaHL9/HukzBDp7lm/1JSzDp6Nyl6Hf163E6MRjK+Mtu 6idlyBTyJjuzv4sfCghInvJ59KGo981XqJrR3M72ogQH4Vy6ut4Wd1TsI4NYt0tAZYep Fw99NnyNDyw2/cCa0/3EMfoYDXJSfN5M4oN82W0xX6uMDVGPU2UEMtdiTeBGdx3t+Gee v9qg== X-Gm-Message-State: AOAM530y5he69WGPI8JlblCVU/8zuAgc2A67CZv4BSUmxxH7asHgWPNj /Zd5pbKJ4pDj/Cg5qdfCqFXODw== X-Google-Smtp-Source: ABdhPJwWgksGDBlRqYjE9XMhgf8NQ8Q9/HDu4uVh6JKJ+AthAtLYo5N1j7SLRKfmihKDYNlkwLJYqQ== X-Received: by 2002:a63:1865:: with SMTP id 37mr738085pgy.206.1612470176112; Thu, 04 Feb 2021 12:22:56 -0800 (PST) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id r194sm6560531pfr.168.2021.02.04.12.22.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Feb 2021 12:22:54 -0800 (PST) Date: Thu, 4 Feb 2021 12:22:54 -0800 From: Kees Cook To: Yu-cheng Yu 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" , Vedvyas Shanbhogue , Dave Martin , Weijiang Yang , Pengfei Xu Subject: Re: [PATCH v19 15/25] mm: Fixup places that call pte_mkwrite() directly Message-ID: <202102041222.C53C9A462@keescook> References: <20210203225547.32221-1-yu-cheng.yu@intel.com> <20210203225547.32221-16-yu-cheng.yu@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210203225547.32221-16-yu-cheng.yu@intel.com> X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 3AF3E80191F4 X-Stat-Signature: mq6j1nfwpyhwqb1n471jxbk3k8cj6ce7 Received-SPF: none (chromium.org>: No applicable sender policy available) receiver=imf08; identity=mailfrom; envelope-from=""; helo=mail-pf1-f179.google.com; client-ip=209.85.210.179 X-HE-DKIM-Result: pass/pass X-HE-Tag: 1612470176-960896 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Wed, Feb 03, 2021 at 02:55:37PM -0800, Yu-cheng Yu wrote: > When serving a page fault, maybe_mkwrite() makes a PTE writable if it is in > a writable vma. A shadow stack vma is writable, but its PTEs need > _PAGE_DIRTY to be set to become writable. For this reason, maybe_mkwrite() > has been updated. > > There are a few places that call pte_mkwrite() directly, but effect the > same result as from maybe_mkwrite(). These sites need to be updated for > shadow stack as well. Thus, change them to maybe_mkwrite(): > > - do_anonymous_page() and migrate_vma_insert_page() check VM_WRITE directly > and call pte_mkwrite(), which is the same as maybe_mkwrite(). Change > them to maybe_mkwrite(). > > - In do_numa_page(), if the numa entry 'was-writable', then pte_mkwrite() > is called directly. Fix it by doing maybe_mkwrite(). > > - In change_pte_range(), pte_mkwrite() is called directly. Replace it with > maybe_mkwrite(). > > A shadow stack vma is writable but has different vma > flags, and handled accordingly in maybe_mkwrite(). > > Signed-off-by: Yu-cheng Yu Reviewed-by: Kees Cook -- Kees Cook