From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796298124; b=IQ2NK1DVnXUAfK4Ao1Q/Ec3kbVQlNO+qSyhl81A5ZQfOPOu7JLlBc8vIxZQY8Ah9GBXb 8mwkko3PvVsBnv0FLNjhYwwmJuXczMuqZSSaXXvbJ3vIBo20kYcxAika0HT6oCCOFgPaO 3o6imQQ8FHJmWtBzMAzDijWWqmp9k4Oz6WJvIdnILVtjrmJvbItwTH8PXFMv/oVeywyr7 DrVTIjKMeP6fMIKXi9Trz7QMWJjqLqwk8Cru3PVJzTLWZ6x/RRS7KPkq/vEPWLqTpVL7E PZbVNF76BTxeqoKLRMCtl2mPgw0XwL+MHYdNbH2RD4XFNzIplFcAQOZppQjVRaZXXqw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796298124; h=Received:DKIM-Signature:From:Date:Subject:MIME-Version:Content-Type: Content-Transfer-Encoding:Message-Id:References:In-Reply-To:To:Cc: X-Mailer:X-Developer-Signature:X-Developer-Key; bh=one2Xhm0MMH9WIZcExgON7qrLd4BC9Q/nEgqMZPpkSY=; b=cjZHyKwrBewQn1WwfO7kRZTGn/KpVtAxveJB8b/Qlgpe8YdtX7ZP2eZoWX0l1W77cbWR S2D2WumgmslT1ItCI0gqJefMngN6ODRrF9hABCor4XEm7zlA469rqhL1HsM2j1PyYXRn0 lbME4wuKW3QtBzNWSNRtwNY1+Voq4Ro+v7FqpZ1QgC3VjKSrMdHCm+2MuQU8GckMT1Yuw F4AspgkmBqKuR6fLAilGiGvfoBNogTc8pmiD5/wVPLxI22YgssXdn5DgGL76VqmSteitK Zt/sg7GnMZh4Kvf114Cnu5+YPXuilH8c5L5qpTHCInY+loPYbiQNSTzrWj79rU01HLw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=l7WHUWpp; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A94A0606A322; Thu, 3 Dec 2026 11:42:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=l7WHUWpp Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2E9E81F0089A; Thu, 3 Dec 2026 11:41:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796298124; bh=one2Xhm0MMH9WIZcExgON7qrLd4BC9Q/nEgqMZPpkSY=; h=From:Date:Subject:References:In-Reply-To:To:Cc; b=l7WHUWpplDzTfmE5S2rMd/g5CZJLG54pwfjr/n6WMySGSYUJGcdZXvjHtdtKtm+SU tuf6tki3LjysEI0fBHJLD1Tl9yH/cdmZXalaTCqK4WhNuqvvnEvNLBwG/Gjg7bw2Ym f/pDnXns29eoUS7gr6cVJAJ1Vcu59DT/WKi/NwEgqCwib7QJfeHjCMR8UQhzgjd1KG EbtNxC1rGM7SBWWHBjE0qZYXFOLxonyHKgU9rdHNNbUbcNMXeWnjbiK6D2v8hdyUUR sElWoOBJoX+yp785eRUJISajybYxxeL8urKBcwtgh84uAEZzP6/qkNmuH7gHHQ3zR3 C6bbYdvejyPfg== From: "David Hildenbrand (Arm)" Date: Thu, 03 Dec 2026 12:37:40 +0100 Subject: [PATCH v2 17/35] hugetlbfs: don't overflow the pseudo VMA address in fallocate() 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 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20261203-hugetlb_fixes_2-v2-17-9bbeabb555d2@kernel.org> References: <20261203-hugetlb_fixes_2-v2-0-9bbeabb555d2@kernel.org> In-Reply-To: <20261203-hugetlb_fixes_2-v2-0-9bbeabb555d2@kernel.org> To: 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 , Sashiko , "David Hildenbrand (Arm)" X-Mailer: b4 0.16.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=2462; i=david@kernel.org; h=from:subject:message-id; bh=Pb3PDrF1NMF/4OeNBILQOqDZeS5Ujgkkd9fYX7WN7MU=; b=owGbwMvMwCF2/OVpCdfQ3ZWMp9WSGLIFQ6ovB+kXVZdfONb46oXpqgnLt2jbreXQOWbzQn3jb L21ZWE3OkpZGMQ4GGTFFFmCgu8bvHy5rrbajY8ZZg4rE8gQBi5OAZiIiBkjw8JvnjvE3zgkz1nE 8Wzf/bS2Hqknvy/Xss9YFJLk2yt9tZnhn87aLf8Or1p+d+8CC9lDG2rTXJSSpa/IzBbYqveGTS1 ajxcA X-Developer-Key: i=david@kernel.org; a=openpgp; fpr=1BD9CAAD735C4C3A460DFCCA4DDE10F700FF835A hugetlbfs_fallocate() allocates folios through a pseudo VMA that starts at address 0 and file offset 0. It passes the file offset of the folio as the address. The reservation code then derives the reserve map index of the folio from that address. Confusing. However, on 32-bit, that address overflows for file offsets at or above 4 GiB, while we still add the folio to the page cache at the real index. Consequently, fallocate() of a single hugetlb folio at offset 4 GiB consumes or restores the reservation at index 0, messing up the reservation accounting on truncation and eviction. Let's fix it by setting the file offset of the folio in the pseudo VMA instead, and passing address 0. This has low urgency, as it only affects 32-bit kernels with hugetlb. No need to CC stable. Fixes: 70c3547e36f5 ("hugetlbfs: add hugetlbfs_fallocate()") Reported-by: Sashiko Signed-off-by: David Hildenbrand (Arm) --- fs/hugetlbfs/inode.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c index 4290e88f23c5b..81c5a3efdc4dc 100644 --- a/fs/hugetlbfs/inode.c +++ b/fs/hugetlbfs/inode.c @@ -727,7 +727,6 @@ static long hugetlbfs_fallocate(struct file *file, int mode, loff_t offset, struct hstate *h = hstate_inode(inode); struct vm_area_struct pseudo_vma; struct mm_struct *mm = current->mm; - loff_t hpage_size = huge_page_size(h); unsigned long hpage_shift = huge_page_shift(h); pgoff_t start, index, end; int error; @@ -774,10 +773,11 @@ static long hugetlbfs_fallocate(struct file *file, int mode, loff_t offset, for (index = start; index < end; index++) { /* * This is supposed to be the vaddr where the page is being - * faulted in, but we have no vaddr here. + * faulted in, but we have no vaddr here. Let the pseudo VMA + * map the folio at address 0 to avoid overflows. */ + const unsigned long addr = 0; struct folio *folio; - unsigned long addr; cond_resched(); @@ -790,8 +790,7 @@ static long hugetlbfs_fallocate(struct file *file, int mode, loff_t offset, break; } - /* addr is the offset within the file (zero based) */ - addr = index * hpage_size; + pseudo_vma.vm_pgoff = index << huge_page_order(h); /* mutex taken here, fault path and hole punch */ hash = hugetlb_fault_mutex_hash(mapping, index); -- 2.56.1