From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.128.52 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796384470; b=4exnf1CJ8yt33de+XYv1gw25N6eVCgY/cQxUq7NBKDQWtuFZMhEUXZwO8Qc3rt/u/DaN 6vAfnQnOx+yKuh6ejVjzUpUgsMSyEZqiMVLmoSQIcNkB/U3bHiWD30QuiTxuAhoP/vBCk vfzSq1Pya5f2WhOJg9q5yJWx8xbcoE3tCMEyUOnazZhMreuah7CBRC9VNbjZUZKwJ4p4I QJ9b6vYgiakN88Li5/yJqrJJOFSUyHsAXrbIE+ZCoG7Byq+6MZ93k/b5MMEDmwSKXfP5A 2X8fXVY2CRYVmuK6VVm6ZvYICbEOdFM8LdNd1hdPPQxvEAmbib25hV1zp44UbIRi5aA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796384470; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: Message-ID:Date:MIME-Version:User-Agent:Subject:To:Cc:References: Content-Language:From:In-Reply-To:Content-Type: Content-Transfer-Encoding; bh=hNLBJhp8o/m3dUKts4p9OvFI19NmtVc78TKZK0mEorA=; b=hfphZ/Sn0+3cvvXc9UaKrFjM42pXaYqtIyXBO+Shj/UCysaqtxx3pFvN3NErrUK3SB7l aS5QS1ZX/FRklv0FFuPPfZqWw6L4NnKxhCwsKpTOVReSv1GDV3VheSLhs9S3LCGUZO71n LLXQ6OGIZPeTxlh2BLfk8XlwNbBjIYu96VzBO80YzK0fJkHi3/VdPFAryug5/9Ej01j7G Hgq57+BSli2SMP6jVLxXzsgQ8e+HH8Vcw3FBsdv16l36ZhNvbSGHM5oPLK3Erc3hkDR1r quQrDnidOXY2NZ6WrfuOeLOCSpN96qNLeDiRcN5QX92N9c9oE7GaqPp8Qn1xnpEYkHw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=CdAQhQ4i; arc=none smtp.remote-ip=209.85.128.52 Received: from mail-wm1-f52.google.com (mail-wm1-f52.google.com [209.85.128.52]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 90CB0606A32C for ; Fri, 4 Dec 2026 11:41:10 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 90CB0606A32C Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=CdAQhQ4i Received: by mail-wm1-f52.google.com with SMTP id 5b1f17b1804b1-4a2000d5fb1so4562825e9.1 for ; Fri, 04 Dec 2026 03:41:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796384469; x=1796989269; darn=vger.kernel.org; h=content-transfer-encoding:content-type:in-reply-to:from :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id:from:to:cc:subject:date:message-id:reply-to :content-type; bh=hNLBJhp8o/m3dUKts4p9OvFI19NmtVc78TKZK0mEorA=; b=CdAQhQ4i3TlxKbQTS6QdqRVMKf68XqSGRzku8Hss7HxtOMRqADsTSuyiOC85Pvaujf b3jEteWXICCDzHJ2TqEhAUD0pPCXKLLsygGOcZjP4MeIdr+0zr0tJ0I9FyDKwBlgFeI3 uTxylclwrBLl5uqBcux33uXcJwvvCCa74lRGFhy4DDXpioQRtO8AWof9Bfv3Fqqmmtk2 NIYpsn2E3NV+3kDQYDbeqVQBEGkSRvNvFJw0XMUNRoyFJ7nGvBlDPTNXr62elSjjFble y02OyMWBGrU2wRYXqOC1Et7QDfRTlxqvY+H+zJ3qD3DXOFNGMxs5tQg4n+XMpqE8IOC9 2gbQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796384469; x=1796989269; h=content-transfer-encoding:content-type:in-reply-to:from :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=hNLBJhp8o/m3dUKts4p9OvFI19NmtVc78TKZK0mEorA=; b=vQpdASQFKB3SloWPZT4IWjefVxxHcUIHzrSoS2Xsz9TED6Tbckxuan5NdKBpWWBepN /EXkAvuEgJxlbBWCsZouBd/waoF3DEYtV0cjXu0waBQ1uHYrw2wh3hUT+J0Dky9uHUVD vfEsCIX7dYlQtui587pQEKtjAnr38wbhS/smjwGg0T1xqm+v6A3Uoei46FDbHEXsPgDu a/YiXIbpuhWcYwipXWrliNKRhxjjmNuX6NNjaksW62xCkDKLP32fK4xn8MaYvYFhCJDi 1FzGdKmpmk49FusFJK9whgHvRAD4lbdIFdZCrfawFiuWtw07nDFQ8djHlbLnkhvtxyof zATQ== X-Forwarded-Encrypted: i=1; AL+hErGM5bRSpA4DbLR6bAGxNIUlXZj1VPnMdvMovOc4mF4QXewbJsbRCTbauTU/GiyQkIBLJQOp3P6b6Pg=@vger.kernel.org X-Gm-Message-State: APuU4Z+tSo+rmxrzLuIlyBImP1iwgqni6IaO2NBddZGYYbXmcENvrfe7 TbQPENPs0avwsNO+Z+zgGyhph9/Q4JEN4gmb4VIKG8xshg3KmrQNnPGL X-Gm-Gg: AZFdTZeaeOJw3t3a5jM2G+px6Y2FLiwgDg+Ip87kt9k81TeXOeH0D+KO/sA94oC3Em8 WBPbfCslIsK8QIM+//1KUBQans7uN8i0UK8w+HycIuCPoD1tW214sbvQnhWTiOP21i6R9/QQ3kJ pouZJiDpAAzSWG0lDa1HQnjN9jDBVGg+bqGRIU1AmhmDxW+Wz/7yWtJQGMkbzIsZ6jJWWIxFzv1 IckuDq0cxgbcPcKzoh71O85Gri2xfAONunuztN+aFQeh2A7TUVVgH3G7WjXq/+6GdVDfajrpkGI 7DUElbGJLn1IKl5ZSkmDQHFoxRCBBE9bQII9QlYWek8wXXwrIVmEUAWKuAA377enZUCkgA+XiwI 1lzoo6fpkKUY2aFVfJlkqD/YRAVQ6NNL2TqtyN7ZpFUTZz6B8tz0NL8SBp6Fipa5IcGWkaI3qqq Xzf3GQGEAP/+4LFJ1fE8CC+TIRtHt1SoRJGe0mIYB4wdPPeWzEyzUQr5UPRpDG8CX5cJJLjWrae Dcc0am9xfnC3M1APdOdDSTJgoFxddkI/xp8GvDCrohL3QR7g9wEntUqZ4IF6HqmCGUD6A1kyYe1 /SsjtmfWGQ9cISDB1+Rti/tvXdE8Mw6OScJjexMbcUjZ0Rw8BxEX1LQ5roSRoiHZHxWOA5FVqSh g X-Received: by 2002:a05:600d:82e4:b0:4a7:76fa:87e9 with SMTP id 5b1f17b1804b1-4bbeb8eb938mr32488795e9.21.1796384468867; Fri, 04 Dec 2026 03:41:08 -0800 (PST) Received: from [192.168.1.22] ([83.231.69.9]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4bbea2acc6esm52439305e9.14.2026.12.04.03.41.05 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 04 Dec 2026 03:41:08 -0800 (PST) Message-ID: <7fee97df-8ea7-4044-a3b8-bda2a59a3b52@gmail.com> Date: Fri, 4 Dec 2026 12:41:05 +0100 X-Mailing-List: linux-doc@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v2 29/35] mm/hugetlb: don't share page tables of a VMA during mprotect() To: "David Hildenbrand (Arm)" , Muchun Song , Oscar Salvador , Andrew Morton , Hongfu Li , Jinmeng Zhou , Mina Almasry , Davidlohr Bueso , Naoya Horiguchi , "Liam R. Howlett" , Vlastimil Babka , Mike Rapoport , Michal Hocko , Jonathan Corbet , Shuah Khan , Randy Dunlap , Vivek Kasireddy , Mel Gorman , Hugh Dickins , Baolin Wang , Dave Airlie , Jason Gunthorpe , Andy Whitcroft , Roman Gushchin , Barry Song , Andrea Arcangeli , Lorenzo Stoakes , Suren Baghdasaryan , Shakeel Butt , Pedro Falcato , Jann Horn , Guillaume Morin , Yang Shi , James Houghton , Rik van Riel , Harry Yoo , Lance Yang , Axel Rasmussen , Peter Xu , Sasha Levin , Kiryl Shutsemau , Christian Brauner , "Steven Rostedt (Google)" , Hongbo Li , Gregory Price , Zi Yan , Joshua Hahn , Rakie Kim , Ying Huang , Matthew Brost , Byungchul Park , Alistair Popple , Andi Kleen , David Rientjes , Joern Engel , "Aneesh Kumar K.V" Cc: linux-mm@kvack.org, linux-doc@vger.kernel.org, Gerd Hoffmann , linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, Johannes Weiner , Chris Mason , Jiaqi Yan , stable@vger.kernel.org References: <20261203-hugetlb_fixes_2-v2-0-9bbeabb555d2@kernel.org> <20261203-hugetlb_fixes_2-v2-29-9bbeabb555d2@kernel.org> Content-Language: en-US From: "Jose A. Perez de Azpillaga" In-Reply-To: <20261203-hugetlb_fixes_2-v2-29-9bbeabb555d2@kernel.org> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit On 12/3/26 12:37 PM, David Hildenbrand (Arm) wrote: > When mprotect() of a shared hugetlb mapping races with a hugetlb fault > in another process that can share the same PMD table, we can end up with > page table entries that don't match the VMA flags, such as writable ones > in a PROT_READ mapping or PROT_NONE ones in accessible VMAs. > > huge_pmd_share() takes i_mmap_rwsem and shares a PMD table if the flags > of the two VMAs match, so while that lock is held the entries in a > table have to match the flags of its VMA. > > However, mprotect_fixup() stores the new flags without i_mmap_rwsem, and > only hugetlb_change_protection() takes it. A fault in between shares a > table that still has the old entries, and the walk then unshares the > table instead of changing them: > > process A process C > VMA is RW, entries are RW VMA is R, PUD is empty > ========================= ====================== > mprotect_fixup() > VMA flags = R > huge_pmd_share() > i_mmap_lock_read() > flags match, take A's table > i_mmap_unlock_read() > hugetlb_change_protection() > i_mmap_lock_write() > huge_pmd_unshare() > clear A's PUD, return 1 > skip the entries > VMA is R, entries are RW > > mprotect() changes both the flags and the entries while holding the > mmap lock in write mode. > > Let's fix it by only sharing the page tables of another VMA if we can > try-read-lock the mmap lock of its mm. If the trylock fails, we simply > try the next VMA, or allocate our own page table. > > A trylock is fine, as we hold i_mmap_rwsem, which is usually taken under > the mmap lock. > > This has medium urgency, as it can result in endless page fault loops if > mprotect() races with PMD table sharing and we end up with PROT_NONE > entries in accessible VMAs. If the kernel accesses such memory, for > example in copy_to_user(), the loop happens in the kernel and the task > cannot be killed. > > Fixes: 39dde65c9940 ("[PATCH] shared page table for hugetlb page") > Cc: > Reported-by: Chris Mason > Signed-off-by: David Hildenbrand (Arm) LGTM: Reviewed-by: Jose A. Perez de Azpillaga -- cheers, jose a. p-a