From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.128.41 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796384470; b=tv7/4cBFlkq1fMcb6fzT3DDpy6IQNpD8K83yRWnPFdxl+qMfwCDfXrbXXoNgt0GHCnqj Y8E912U5T126l7FuBd5RUfqGKhuH4sOtgdmxI39VdqgEshVkG/Q3UXxewosicD4riv/TP maG15ueXyo5++U/NwjCj3XJGRCFryhWxsnOa3ZkOoLj/l/hCI0KgKnjH94py+C5hNWeTm Ex93mAjfbt8BQA4VH7SHbHwioZpDwBTLVL4OZAuHLobIgmJyzQSNL6qL8RygkOr+GoySD lplyIxwgRc/zAkFIq79GoRFPdF91qkIAom2UAEy/ynalvmOqc4H46cwNAvY1iwVltUA== 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=P08DyDGdn7nYtVqxU5e+u8OAPJ40X2Rl6TgfL3/ysZYcldp1CLR5IoK0B8fqVFH4UWQd U8acsOt9eYflPr3ny4bSBIwPEWZGeSd3n+Q398XjBee9QWP7VN4pPv5DOLJNIbBAQ4rMt UGLiPirIjRrFQJ2oIdOSrzJ1caCBvYmfWbSmlAgIuqcI59vgk88wrDztPVWv+6nElKtq2 3/mZFfDbsshI9GAN0C9Jjbzw5uw+oYEJ9Awfu0+U6rwNV6H4Njwun3g7F2beQ15kSwhop SJrvxoWGneTb1EvVcpDVYtYPoGVTbqqpSvkTgw0Fe3zZ+YcRZjgSEG6fRWRLIJVaqrw== 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.41 Received: from mail-wm1-f41.google.com (mail-wm1-f41.google.com [209.85.128.41]) (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 93AA4606A32F for ; Fri, 4 Dec 2026 11:41:10 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 93AA4606A32F 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-f41.google.com with SMTP id 5b1f17b1804b1-4bb64ef5a00so5517495e9.3 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=r/mmvloXf3FmpUIQEH8OJTU+sGia5k97keyt1ZYf9Dy80HpQ83WuRSUgI5Sp3GdstT ss+6EzTFvT1Bslu9UeRygDAIjR85Pm0ghqMYY/C05f6g7eFY9o70retfJ8OJzQ6+F8dS sx5qLrV1wBLqr7ywEP18v85AV+BlYgGnOiZxvgI6Zn42pOcFeexFoRL/Fa09ADTQtWNS D6JyNH/pLg9w2C2DVTcnd6tuo66fng+AWsElFlLh+C7vZNIGIEvka+zri/apQoh7bVs2 Noc0Kg8/uan61nZy9HnCGgja3TtH2YJErpoGCI9gX6B6pMFV1eRQ5dch6vDWLcf2cWTM XqAQ== X-Forwarded-Encrypted: i=1; AL+hErGgxeby/Ii4OUnxeg+0HCYZ8rgvR6Z/cD7e+QqRCbnaGj49IOnsikDncvBeYKCmIVX6ilHBMsI=@vger.kernel.org X-Gm-Message-State: APuU4Z93dsfZSmCs+nTenWzxQ+S4WTO2nzqDMtieU2le7UtoFuCdv6ls GGWseknl7lWHVkhoPqjCAq0NU6dj/Ei6VZ0wxH9qG697SzWTTk0tLW3+ X-Gm-Gg: AZFdTZfP8J7VUvZ9VsZy09gvwJ6lQPyHnWzHBCquKFxYt9GuRrg/A7iqB45pDNmlyMM RylW8C4lLvFOo+Ua+xSxBxzY5kuLKK7Vz+VMAXMiBoqPAPVAmQIO2rUndovvXSuUffetMkWS+YS Hmjv12tQxjzoiVmQUoBgZorZfVgPruMS8OgA3KMPrrhtAM88MPk/b6kU89tuDlKe/Rr2yykuhYc ATrxK9dc9ciGnuXn+y33FBkkj4wN7/qvkHnbkrV2cOQ4evDW8CuCN+Pek+TZOc9ZakM4lXJTWkO +gX0abvCUWbl0UL1R9T4judJsHrtVhcpIjeQqkcOcE7/Zb10fTmccfCC9UbJbB2uvCfpwf8w0pr Izp8QaMo9ONeMU+p1akEhsyiAg4iMej1EtSz9aG4m/JDoFTIXf/DZhrZkfnO2hEf6cpf3jG8Nlp LXg0TsUzR5ZGXh7eOse+2PH/znVmZK5VDEE3WdI8MJFbR6p9UoGuk5rRGWbxcdKJDhmQDPxBgC1 IG2dOtaqdWOn+u1WHOIrzDQSW/0UnHk5s0UGQvSaSfRibGRe26qbyErosqQ61pbSBnZ312w0RQn Itb8rgPMXHPWUB4CKG4jq4oJFZAzYlsNkrPoZLcf3xEmfR98/p8t7rJwO/pU7Za5kMFLWDknUqF 1 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: stable@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