Received: by 2002:a05:6358:f14:b0:e5:3b68:ec04 with SMTP id b20csp3661499rwj; Mon, 19 Dec 2022 23:30:38 -0800 (PST) X-Google-Smtp-Source: AA0mqf6rP4sOErAQxLFtG5A8hf3ZSvuyf3zWJVc+1cMCLyQgOCfg2XTUOAgdSL4Eacy9K/81kKbd X-Received: by 2002:a17:906:2a50:b0:7a6:276f:7eed with SMTP id k16-20020a1709062a5000b007a6276f7eedmr38309739eje.9.1671521437792; Mon, 19 Dec 2022 23:30:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1671521437; cv=none; d=google.com; s=arc-20160816; b=wnNy+1WUFUMWMjdt9EalafgEKMGivh6wRx46hja1Uo5wbKMGJYSrETC3kUwaeFtkN6 WqWO0QDgRIS281/25QbCKiP9k1kdotIMDWWS2YzL8ubYBSU63ZGTTWovQRznE6xtmtQe u7ElRtbXrpiM6Jt109H9cH/k0r3Tgy1xmU5khcMqjkX9F1xhJ930vrn2to8l8JxAa4/+ o57nhyhyEAdxY+XARHN0Arufxe1+3mn9WbxV30UIo3iqS5VZk3DFL/+NYXdBVLP11gmC B5BsRtg5JyihRd7qiGlUmjdhPkkIa9dD0S34ju0u1jNhGvLnHp7tL2dilm1qmHRt2jbe GgEg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=wuRQqb4yRAJ4FEZaEUwyqkhOJuLTRzxeOhNcE74yoH4=; b=BopVwxGSA+7z5DFX7ui6hlRm4ic9ghKKWVWqMLEhYljyHPRqQ/SXtnf1oxJLq/7KSr waXHeu2SKgOFlLxcbRXF9cXLAb9KfDodhNf+lO+8xYgXiAKoQehhcrvkc4g/mSaEYWCx wDwwQlFh4iwyoY8p96u+/V0rxKRUAN275d59GGtN0xzhsraPHXYc9ynyDya4RvnyWB/k 8v5nfgbs8vfmvPbjMkf9iG7e2gNKUx8A8gReoCylLMK7HFj02TubNbVzsoN9rzzZLnep eKnC/9186FI4DBtQ95nAheZDwNQ4hFqrHkNnDOquPU+7bKTJIaIAls77vYCD2+YhYO6g jnuA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=JZbpM26w; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id v12-20020aa7cd4c000000b0046b807c19b9si9863894edw.190.2022.12.19.23.30.20; Mon, 19 Dec 2022 23:30:37 -0800 (PST) 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=@gmail.com header.s=20210112 header.b=JZbpM26w; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233231AbiLTH1V (ORCPT + 71 others); Tue, 20 Dec 2022 02:27:21 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46950 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233701AbiLTH0Y (ORCPT ); Tue, 20 Dec 2022 02:26:24 -0500 Received: from mail-pj1-x1033.google.com (mail-pj1-x1033.google.com [IPv6:2607:f8b0:4864:20::1033]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B779C1705B for ; Mon, 19 Dec 2022 23:26:21 -0800 (PST) Received: by mail-pj1-x1033.google.com with SMTP id o12so11539778pjo.4 for ; Mon, 19 Dec 2022 23:26:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=wuRQqb4yRAJ4FEZaEUwyqkhOJuLTRzxeOhNcE74yoH4=; b=JZbpM26wcX2ho4irepvHJdt5UeqQwiPyu7R+jVVSgN5Gcct1FWav/0nKIlEGG7Wr/t qOCuZ4KF6aR1ag3SCCwiU8Vx74XEDaTYbFrHlL+VmTd9OSwgmj3qg0WHtHlkcvJVyGVY jcyc8LwsTH+EyYQYCEN7cGXRKdGr8E9C2eodr+Tz89EQJprNi2IGMJmxjRy9UrNDymKa /3vyx/6zVl+r9inx3sFkNw4NvkktYhsqVCdfZIPrVzwFpF0IxxP+1hlsaTujxBYl7qa0 YM2TgNkL0USPA/hjL9mRvBEL2I8mlnA1r6IwEUnQVcz1Bdj7gjAMPYEqQMc3o44RT+Lh xCxQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=wuRQqb4yRAJ4FEZaEUwyqkhOJuLTRzxeOhNcE74yoH4=; b=cbJDtP4uSmmh1KWtgWYRQ7GQxbeyfcStl7e61xPrGynxppVwEqYwk6z+s81hP+EXkt K52yHrkgeeAgP86KtT5KAFcZ0CdsxLXHqKwHHprNR54synVjuphzGKTgpMgDyo96cDQB fk7Ncs70N0umkB8lonLXiZIB6sbvGdtjngVIXHVeQrTeKvueeVCDm9rJAMVEzVREJwae 047XVq+G+yIXFEb+L6MhjLgaCXRMmlxn75fFAY2DL4gVFYj+KXkyMEM3aQhBF5n/C4ez K+eW39eE1xvfKqDJkTHVvC3zYClM6m6HUBzaDztE/kKNI8yqFYoSWh2kSSEACwHmAZvK AvzQ== X-Gm-Message-State: ANoB5plaoMZvZRHynsM0ynaV0qvv6fIU7Ylsr0Rvx5pOcWZlir2HyxcK UX94KvMrIzWy9EfDYS0Xduo= X-Received: by 2002:a05:6a20:7b1b:b0:ae:e972:72a4 with SMTP id s27-20020a056a207b1b00b000aee97272a4mr26568218pzh.36.1671521181236; Mon, 19 Dec 2022 23:26:21 -0800 (PST) Received: from archlinux.localdomain ([140.121.198.213]) by smtp.googlemail.com with ESMTPSA id q15-20020aa7982f000000b00576f9773c80sm7865544pfl.206.2022.12.19.23.26.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Dec 2022 23:26:20 -0800 (PST) From: Chih-En Lin To: Andrew Morton , Qi Zheng , David Hildenbrand , Matthew Wilcox , Christophe Leroy , John Hubbard , Nadav Amit Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, Steven Rostedt , Masami Hiramatsu , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Yang Shi , Peter Xu , Zach O'Keefe , "Liam R . Howlett" , Alex Sierra , Xianting Tian , Colin Cross , Suren Baghdasaryan , Barry Song , Pasha Tatashin , Suleiman Souhlal , Brian Geffon , Yu Zhao , Tong Tiangen , Liu Shixin , Li kunyu , Anshuman Khandual , Vlastimil Babka , Hugh Dickins , Minchan Kim , Miaohe Lin , Gautam Menghani , Catalin Marinas , Mark Brown , Will Deacon , "Eric W . Biederman" , Thomas Gleixner , Sebastian Andrzej Siewior , Andy Lutomirski , Fenghua Yu , Barret Rhoden , Davidlohr Bueso , "Jason A . Donenfeld" , Dinglan Peng , Pedro Fonseca , Jim Huang , Huichun Feng , Chih-En Lin Subject: [PATCH v3 09/14] mm/mprotect: Break COW PTE before changing protection Date: Tue, 20 Dec 2022 15:27:38 +0800 Message-Id: <20221220072743.3039060-10-shiyn.lin@gmail.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20221220072743.3039060-1-shiyn.lin@gmail.com> References: <20221220072743.3039060-1-shiyn.lin@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, 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 If the PTE table is COW-ed, break it before changing the protection. Signed-off-by: Chih-En Lin --- mm/mprotect.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/mm/mprotect.c b/mm/mprotect.c index 668bfaa6ed2ae..119116ec8f5e5 100644 --- a/mm/mprotect.c +++ b/mm/mprotect.c @@ -95,6 +95,9 @@ static unsigned long change_pte_range(struct mmu_gather *tlb, if (pmd_trans_unstable(pmd)) return 0; + if (break_cow_pte(vma, pmd, addr) < 0) + return 0; + /* * The pmd points to a regular pte so the pmd can't change * from under us even if the mmap_lock is only hold for @@ -305,6 +308,12 @@ static inline int pmd_none_or_clear_bad_unless_trans_huge(pmd_t *pmd) return 1; if (pmd_trans_huge(pmdval)) return 0; + /* + * If the entry point to COW-ed PTE, it's write protection bit + * will cause pmd_bad(). + */ + if (!pmd_write(pmdval)) + return 0; if (unlikely(pmd_bad(pmdval))) { pmd_clear_bad(pmd); return 1; -- 2.37.3