Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp1419211pxb; Thu, 4 Feb 2021 12:27:05 -0800 (PST) X-Google-Smtp-Source: ABdhPJzCFcUi3dRBycHvujtgLR9IkEzKWi1LDFb8zeu2w6aqzw5FBIbiwO6w1qDK4mqiYMx5vYNl X-Received: by 2002:aa7:dd57:: with SMTP id o23mr360076edw.252.1612470424967; Thu, 04 Feb 2021 12:27:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1612470424; cv=none; d=google.com; s=arc-20160816; b=XVkz77cKsPeFXchUeVYkQNyEGiIcYmaJSpZeV43VC4rhYmgRDNkjATqJKRbFDRJvb5 G5MnxBlUSJcp2/yefZMFwZgnG4X7Imr/HIT7qGRBTTbifa2oJf8TojKMQvdSuItfVOGV YFTu9bjr+aaZYMCyyDUOp9auU/VVgGfUCDOd97a6zMgd1KrD7lelJeWJlGxhxoe5AcT7 2EmZL1v4+okE8yM42ebnvI0ECVsA5ifXZpk41dR55tgLCcnThgLsmhfWKniZDg00nH2p GvDoVMJAjO4YY/NimuoQi4H/tPZyuQRsVkKNAwtheAeM76MM9GeI83jXdAMi5N+AYMtg 4frA== 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=388dygswvemg3Mj3TiR7mQNJ/V6JIsMVBitRKVSrLsY=; b=YW7yfD4oTsQNttEsdOPk+swV0xgSW0aAUthV7fCr6ssklw14R0WRJ38QwPEWTXBIZf /DZ5esXFop0n5SC14g3XiqiV6AO6DJqpvvG/7C6eAJKIdQQO0U+b1c50CjXHtlRF0h6b KlOlFtEWbZh281KCYMIUpcEolf7+moMV9VED6X1XuxZNzbD4J+7jZkCe6JjQ4A/8hJVB pDT7Uu8rmDA33r7ujp3Vge2JLlZQ9Xvt7hM7XKxggzY3Q56Jg3HjU26RclfzqVV4CkhN 2TnaYdTFVHa8EIRahKetbulL06R/5HRuREvxDIz21XxmySP6QSQ4f7RhwYPD6y0f3PHk 5riA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=YBxlqh3o; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id q26si3767745edt.415.2021.02.04.12.26.40; Thu, 04 Feb 2021 12:27:04 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=YBxlqh3o; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S240112AbhBDUYJ (ORCPT + 99 others); Thu, 4 Feb 2021 15:24:09 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45936 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240096AbhBDUXg (ORCPT ); Thu, 4 Feb 2021 15:23:36 -0500 Received: from mail-pg1-x52a.google.com (mail-pg1-x52a.google.com [IPv6:2607:f8b0:4864:20::52a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 78421C0613D6 for ; Thu, 4 Feb 2021 12:22:56 -0800 (PST) Received: by mail-pg1-x52a.google.com with SMTP id t25so2933977pga.2 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=bC/qH+222uX3uYex2eD0mOaXpEwJda1RWs3RaR6I8EYSQx1J9mScYoSOmrg7eXskxU sx7pkrpV7gRy11d+NshvjplKFOd2eiqFZWDC8qlWX9GZHeYQSdQUzEU6CKFYe/mCDC29 Dhlld+ZbiXWM4HXMtTBzllhjufWT7ePDMavTWJtsuPEuhHXvKh1Cm4t3iodxWt84Sx3x W0TDizlR8XElEzF9ZZRqks/INH/MHqgqmDnlVIBukmD6sDCYjJ+kWob1vs3kzWkcjckb 408PeVlYKRBNlT22VxiD2pd6kh45UwGNzf5xcWkyQ/y9Nj93WH6VK9q07rb8CcbF413f 80hQ== X-Gm-Message-State: AOAM530Xkphn1jtv7hzu+WfrlHoA/O4Jdt6Uyj2Gs8HdisLmEgCZ1dus Xj/0SnsLvCu72YLKGxfBeFbyVg== 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> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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