From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.128.53 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796384471; b=qh3bD8i4gZCcXz/VD2rzvFEe5KGLKrDOqW8wP37hH3q8BPAIb/Ob/qiD23mpBBjZenF6 pLlNwpc4etIFstUF5wn39PxNzZANIs2ZaApBKThyM/51IHxDu5FBH4MefkcLqkWNvou8g hbwuGFiE0PXQKcK14cCH+EBDInFaxx+j0OpVobn6EvIHlIWkghN4wcpYY9Gpz5I7io4c/ 6zNBuINOWK4gs74VD1spNsNp4Stz8G9SqUlQtm3GSq+QYjeq2iTdnmMhSZ8qQlBXLkumh AiHnY3YFkNXIypTVGR6jI//o6F2etZZzwOLrGN7DbJIqPc0lTyOneQ82SUbdohh4B+A== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796384471; 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=iaXY2WLdNySuOBrhrJtuT/0Eug9nx1ONS4zpCqqlVKT9uUOno7x0eU2SXmXxtBeNHMxE B5idnYvMww7nFlFTs+5HPCsHR6gdSzKPUiPA8JzO9N8irj0dqXP9qhNamvP/WaYtW/R/N 54j2p4QyqsQsdSo0cN72yLIaFsfHXS6e9XnrVudM/ILtA5cr2B1wmhJ+BKFw2lkZmWaAQ 4Lpf3TBmpDqxXpZO5EuNkx6C1LklN/3EELGcPYrYa8H5iaCSe+0YUavNWPxLnHSLYfNoa IcsBmjF4CRkLIAiyx7EU0RXfXnwOEx9IfZr1Hchp0T0v9uSixgGludbfU0pYeQFR/QA== 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.53 Received: from mail-wm1-f53.google.com (mail-wm1-f53.google.com [209.85.128.53]) (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 D8EE0606A335 for ; Fri, 4 Dec 2026 11:41:10 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org D8EE0606A335 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-f53.google.com with SMTP id 5b1f17b1804b1-4bba5e17728so5564845e9.2 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=ULM7HObrh2lnrd9fWx0pDwjbj+eBEzmlISbuBYYAdWSTl3wSN2KROICckUgkxvMAis W/g21oQlKweggneB6gNgi7veSci6kA1zgzhAWAhT5j5P7FyiAd7MVjbwa0wE+78wBQss HhQwqWo3xdbb+5kG+GfJF6IHlpm/2GIeVLCy+xDwvTDGLl2n76wPvexc9zl8b27yvER+ 9fGFXaDyElhR4zNaQWadncVifvfab1eYrqPG9SztgrJrrqmMqvcEoCFHgO+VZCkiVehi kmgZ0qgOxkRolBe5pA4eNB9l5w5AwTXm8SLQTGXzc38tPxSV0bX9X+ZLLUK9esJJriAF io5w== X-Forwarded-Encrypted: i=1; AL+hErEv/KiwslsQwHrgFKGkgO261IIbMklvQIWFwU2BG0LhMl7c9pLEV5L1b0P4WoKDa0jRB3moMkkdNYcUvcA=@vger.kernel.org X-Gm-Message-State: APuU4Z9xnsmIf+hyCLJLKQV4w3S3vepOhoKhSznthvmd16rrAvQOaBsV VvLiKKzNwUYyoeF5MUxY/U26TZCgvmfmNkt4CBUVLrgy4TOs6FrwMijF X-Gm-Gg: AZFdTZeZ+xdZWgZM3xjxyHg/y6XthD/54WToEcOEzx0WXfDCeE5XUa3hR1x/NYoEMLD ZCDT9nYFNdozbxmAYmIrAMH2G/01YrwxMlScyLxolBdV6l25yyfuDAHmeylDoMw6bPCrR+VLM1I UXoQpavFiphedPL/RgV7n9JYLJr7C13K4/0lJHZpWCoZCX57rjESH/WzJ/19UtHG7JBbtkvfcr9 v9pk3LRfX6HO7LBFCMulGcaoWMIwCdX77XHMX10/C6VEXUVgzypfu7qMM+r03axx6Dff/AaG81e m8NaYgVV3KrHKnZTYjLgrPvF1g5v4M/tYQlR8iSQTCocaG3pFVmGNuW3wk8Xk8hkA4v5Db8qddP k/FYllJwHa/rk79In8nfPMWJKU1FRA3/mdM5v9k68QWLo90edVPJccJiRRTtoqDZ8baQjghwQKw AwwOGxHMr2Z0r5PII9wKJkJAL9OvMyW0TsJkNyNux8i3P8YM7ZMPBbyAQiq9fa+Pkm/hdt7JKtY hduh0PU774XbCU/kkQqKxsrssz9n1oTDWGIqufmSa2JZJJdPkThjOI/PjyokdqAcpH4RF0wLPHh HQmQ0RnVMwVBxJz+KNxNsFrj3LgAkkWFWRJJe4VJZmyR5ytGDpd3EwrSS6t+nSfbkgPsAZEzBF6 X 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-kernel@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