From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.221.53 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796382765; b=pOFHKlEJjXE8d7a10LEv4Xo+JY6SA5HPURKKYsrj3gh9IDBVyIWUaYBOXGzCnmipdm3q Ws+2dI8gRC796DRryPYQ6iEVRGu+pIbBrR4iAIiJTJNN5T37YwyneomL+cv6yjb7ZxkxG 0RR9gEl5Wez5gF81RaZP5k0yQpmwnwPezku2Cts1UAe/LJctE7QLMyHRdawjiEms2GKg3 qEm0/dSM04wcAc7Z8yLciqkidh1kH7ml53rg4izO5YrRIB9xUj2t5DugJpGDf0vOyPUTi uVrZFDTSfRPW2378rfkw+fKlzfJW38rSkEPnay/R2Nha70WoAiJ9XNxe9KGjWX0Gh6A== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796382765; 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=GqlC2N9dm1LycpIvzACICLBqGur0RarwP6EZ5tx6mW8=; b=BgQk2hCfXvdw+UiXKXpAZ77eb546M7kToDLBIBRKVbRiYAXTmagCljNj9NStmgOQzwoK NiKrT3xdIj1NTv/Xf8MrvctcwurwEE/Cy8BmkcIPGPZd6/KLbC8iCueJQdwR6CKX9h51b yI9p4CfSa1N96cK87oZ9zC3EEPBkS33x5Bs9EVWJvPuEsq2NEolxfxZhwtr5hYcMjH1CO +3ZT5GteU7IIHVKEfOIdq4bRj1vKeoSoHRsd1wz75BfX5qWf7xQRzXnyM5ATAAvE0XsZd yq3sp6v+HuK3heTmeUH/Brt+Y0B83yF1H4HdwwnuXaEwuQn/dHXy32qjj9BoSzcg4tw== 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=iMqxcEl5; arc=none smtp.remote-ip=209.85.221.53 Received: from mail-wr1-f53.google.com (mail-wr1-f53.google.com [209.85.221.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 BC4A4606A339 for ; Fri, 4 Dec 2026 11:12:44 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org BC4A4606A339 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=iMqxcEl5 Received: by mail-wr1-f53.google.com with SMTP id ffacd0b85a97d-4c4b8e58cfeso656203f8f.3 for ; Fri, 04 Dec 2026 03:12:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796382763; x=1796987563; 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=GqlC2N9dm1LycpIvzACICLBqGur0RarwP6EZ5tx6mW8=; b=iMqxcEl5DKTkv9zpT2ZKu+9vvpUu1iLHTqC+KJXv8zh3khV992EeyMiyMWEoaGXDgy +1Bhwl8UXuHUmajwbDDcbLdoJP/irdMmIb7zqCQRosZsjsg0U8D6RhG5T04KnTZPKjaz tTbC6IRHnZi101EYnNkMteflmV6KetJmLr7QcX9koJpiOVeevFd1kKX4UBdPdKyk8tpa 9wybLIm8Iwc5BqCU+lZ96jupk1XaeRykvwR/K9ZmIWqKLpHE33ij2owLUf71rPyEyRqx DNQjt5utWa2+fqnPtkSJynLEKBqfSfEZkGPNWOIKiksCOoXNsatWWDOAqPvzqvhoe1Ol EDhw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796382763; x=1796987563; 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=GqlC2N9dm1LycpIvzACICLBqGur0RarwP6EZ5tx6mW8=; b=pSPOFmJTCuXaoto9+tJ2lljs14TaCqrvZKs8uGyWIvJ1n31b3IsUADXMKbb5gRVUuM U9xWXlOlQQjM5K/IsDAJuk0nH6VKI/ngnWnIpvGZKAXxTDIJmWZJrLi6cY08nIILMZQQ 2lxJQkPZOfjA1+YQqXCD5wB02baNRYv1J5ZsTPwaBhORHubrF6bwfaAbBREvfNOpXxzC z919K8gjBImfwr1v/akzA+o0U+8sr4cO+fV9QzygfCZQ/Txi5kJIsdmtcM6ORzWE/t4y BH6aKA3HBFEmcLGSCHGtgjA6KJQzx5EBApMBuK7lum1IIwqHUgF6BBcDb8Ke570+DnnK TtEg== X-Forwarded-Encrypted: i=1; AL+hErGzoU0ne7UIvouV3NGx3cNggUs3Lhc7mr/wcoteT2bGwwAtg9O16zotlzJCHFKMbh/YKRx7NDA=@vger.kernel.org X-Gm-Message-State: APuU4Z8s6QmsZ6eATtXwxQWOz70mR0ZJNJUPvMUjsq/Luxemd+L6Saup 6oYqF+wO01fQOSSOf1GdehX4wc/Z5Xmn02cn1ceoEMtxQ9yDDooKcLo8 X-Gm-Gg: AZFdTZfIqwLS3K2I5o5hB3y6PvNVbSODBc1eluMrdU7w/XmhJHI0dExzLq6yUzzpVrC j+2q1z5ThW9qpDVH4FBhcmFBaQFBdLs2SAXC3sr9xeX9vkVdSU0vUAsn3CjmwcZvfV0jMkvWbUl wHt9GWvc32w9O9LuloxK3vEaXJ6bCPbwt3WcoeVg14PDXscHXmlP8BGbIn6WalxtcyuJkyQ/z0z FurnXiwgbLg/oqcWdgiuOxWKU8WUL+h5utJHSSfuUQ8yzvQKfRq7t82vtMsH80GvIJg4hXqCknz Tgm+Mud4QcwiZa6rHixoYOozVcUF1nkIE5cbfFhcFqXYn9VugwOM7vR+m9Q0r6HrIzqAkS2cj+z OZhz22svN1vZXBN70ZjwZUfeO/T/GW221E5ZNlAG4ekczzR7M3zcpnmnzPQh4oA/N2VtcLgehEj 4GnH8NvN6FDJRPLut26haxV50GhVKYXO7CrqmkVBbqTJubcV2p2wwlGnJLv2oXv/qoS6Gjak0Uq BowQarPsGL5JihcE+HLJQFhjC13CG4po02ylv1dsSRg+geEe6IpM/JProiZvp07MuVydAdbkX0N 3ZP50ExelNpL/+iXryJvJbGGNUYv3IxX6ZUAHWQHb9A1WXvzAauMh6E= X-Received: by 2002:a5d:5d10:0:b0:48e:412:3813 with SMTP id ffacd0b85a97d-4d1e8db7b53mr3779180f8f.20.1796382763108; Fri, 04 Dec 2026 03:12:43 -0800 (PST) Received: from [192.168.1.22] ([83.231.69.9]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4d172e41d76sm4669703f8f.23.2026.12.04.03.12.39 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 04 Dec 2026 03:12:42 -0800 (PST) Message-ID: Date: Fri, 4 Dec 2026 12:12:39 +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 19/35] hugetlbfs: recheck the vma range after the lock wait 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-19-9bbeabb555d2@kernel.org> Content-Language: en-US From: "Jose A. Perez de Azpillaga" In-Reply-To: <20261203-hugetlb_fixes_2-v2-19-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: > From: Chris Mason > > A hole punch or a truncation of a hugetlb file that races with a split > of a shared vma can lead to a use-after-free read of a page table, and > to an MMU notifier range with end <= start, which trips a WARN_ON_ONCE() > in KVM. > > hugetlb_unmap_file_folio() computes the address of the folio in a vma > and walks the page tables to unmap the folio. As free_pgtables() unlinks > a vma from the rmap tree before it frees its page tables, i_mmap_rwsem > does not protect page tables outside of the vma, so walking them can > result in a use-after-free read. > > The rmap tree walk guarantees that a found vma spans our folio. However, > when we have to fall back to locking the vma lock first and drop the > i_mmap_rwsem, we don't check whether that is still the case after we > acquired the vma lock and the i_mmap_rwsem. The following is then > possible: > > hugetlb_unmap_file_folio() __split_vma(), new_below == 0 > ========================== ============================= > hugetlb_vma_trylock_write() fails > i_mmap_unlock_write() > down_write(&vma_lock->rw_sema) > vma_prepare() > i_mmap_lock_write() > vma->vm_end = addr > vma_complete() > i_mmap_unlock_write() > i_mmap_lock_write() > vma_lock->vma is not NULL > vma_offset_start() >= vma->vm_end > vma_offset_end() == vma->vm_end > hugetlb_vma_maps_pfn(vma, v_start) > unmap_hugepage_range(vma, v_start, v_end) > > Similarly, a split with new_below == 1, where the vma keeps the upper > part and vm_start and vm_pgoff move up, or shrinking the vma with > mremap() can leave the vma not covering our folio. > > Let's fix it by checking whether the possibly split vma still spans our > folio. Add a VM_WARN_ON_ONCE() to highlight the problem that was > previously missed. > > This has medium urgency, as this is triggerable by unprivileged users. > > Fixes: 40549ba8f8e0 ("hugetlb: use new vma_lock for pmd sharing synchronization") > Cc: > Signed-off-by: Chris Mason > [ david: adjust comment and description ] > Signed-off-by: David Hildenbrand (Arm) LGTM: Reviewed-by: Jose A. Perez de Azpillaga -- cheers, jose a. p-a