From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.221.41 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796382765; b=ux99Wjat97ztjJFsWW16OkyCb8ObHlw1gIl+QCcPBcLM+N5XLZQjq/tJDC0LxFoTuxAq LFR1se0FuNEJQHZljuCAlis8M3olA/PwmHilWaE6u4kEevBU/sl737HgsWMK8DL7UAgSS Yl7CFxED89GrETQRdpliYt++vsf7/4UQ3S5kyYbv3b4BflJbnoCIvNrC89s/WCu5FQKyZ rQBluk1DirsUGHW1oEKEFgTq5XTMtyPy8f6G6oZdB654uGP5CI4c0e4MJQkFDtM5SFXRR SnvIgOBLGI3qguFdwU6kH3W+clMUgt2laKxQgBQPfTsMcipVIpjH/2mes/ghkuUfrcA== 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=K8BIzsqZxOrzRZLSzE+Zjvy1t5fbD7QS2jmQSOULWoBk1FTFak5L31yTViswzlabfue7 LA2loQeJGX0YslNnviVT+8TsZRwV2YnYuzZOEgwQnhndrUj07dp6JzgPF+w5PWbu/1Ah1 V1qXhVmz04RHRNY/pWOt8CR+nwJGJYcZZf58uAAQwmd/+LBKBmqWPuCVSni4ztISD3yCo ghKmjAiL4fl7l+wxLmbuk41fu9VQfxpckKNtUiIJhl8N+l/YgP96kARg1xU+qWuvgEu/k /Bt09btqMZWDD6For+kmlLk+84Rvm7nZbz3GJ0QgJwWb0rWTHFeXaoFTDdHNF0QuJGA== 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.41 Received: from mail-wr1-f41.google.com (mail-wr1-f41.google.com [209.85.221.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 BAA2E606A330 for ; Fri, 4 Dec 2026 11:12:44 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org BAA2E606A330 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-f41.google.com with SMTP id ffacd0b85a97d-4ad6219f7d8so742682f8f.0 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=UMh38grEVbYgcBIuBsWLdssJjjE49hhuWgrvcZ28FOt5Z1jjqf/pllv0LStb44NzM3 q0rS7Zs2rC4h8tPpzueN9sOuNN5u7CPOM8LPduawcVCF0WsUunn7CQmbsfQvFU0QPqrl cuYJ5lB6yCv/j8LBFrS41zCkHcL2wHEYAeIvqGAZEmV1m3uujzhgyWQLhCM40H6EQCcp SNtgGmJ1yo93ktZi0fgLLR8oyTaEtqr3wH5Y4id4TqmqM2F72lbNPPv3Q5jiDbcWpw4c KzKocsDlQNqOp/KvC4vdH/xdBzWqQ6oZ0sZyUF9bvoDkDz6DsEYD+CLr8PgAq7FpS8MI GWFw== X-Forwarded-Encrypted: i=1; AL+hErFdGtXSWNf3QVVlC/tAoFPJ0eqHySr3fE5x75DTMMq/LpQ2EMgpi+HOuNTO6z9ZYwVmu5muDmov4fkMZAs=@vger.kernel.org X-Gm-Message-State: APuU4Z9FHIgrqUyTx2D/hvPjEU7uB7PB7U9oOiW2MerTS4VoJcuPtkAx ifONFqCJ/kADBLGmHCr9DKpRfslLGHwfg0UOGat+31AZHWVNMWRtbAXE X-Gm-Gg: AZFdTZf0I/BCQduezXpThf0XjDIjNX04qUNQN+SiTtp6UDoeQ44rOqkfTux2iE/5bkC sHdaWIaEzl0cjDrN86udFB4ubUVYY8uHZryiHOGmlmSLpV5ylG3vz9UGVmau8IYwl7Sf7jNhQdk wJhJDo2361Ys03rSPfFkJI/nZhMciaHG2ByW7YuSL4GRqIB1dPEbqvXzWIAflLwbWzNpe+wgWVt lNx1xb/GApkDs41OFOeFzWVomETX/5HXoFMFG4E71TmvMeHtU2S2XEnEL+jBsiwJTsn4oTJ3S97 La4Xm+Bs2GqArhpFSko4ZDMBYL7wwuPuo0zRCRITX6tvRKsGTyBmbOpv0Al2mdemNr0O9Y3bmfN 5OQB6tkX9C8CbXA0v9qAX76p0aU1AIF9bGOghEjWFG+jButGjniCx98f/G1lP6Bn58WDPDcIYwn I8eQGH/cvUqc+TJZd+QbTKOoMM9HoicvATYmmeeI3TXYvy6qHkBJGG3b+embWG4TnWjzfmoqdJ5 mrjAbLrmPixYxUwRJ1pXchwiyxIDxupAOpXulM2A5lJqdjW00pAH63m4WxUwZEq2xz2xn86iJXR In3s2h7h8ZiuemldEVFQWDiPT8bcQXg0Ms5ypQrzeA39NORNDokjzV0= 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: 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 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