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=1796298079; b=2OUJ4zf+VsGnf79JMeBLzdC2ug0W8zjp9fxmJi49pQWnIj9mMeFKGFM/ByrGDyChfkXB zGh2RIcuMhKAhxRqh/Bk9qkECrEI4+/fIjw7IUVz9tHLzjWLuzNQV7RvYyCETrelN1/fN 0PcFfoKhk998vJ/037ame1BxNBJJ9ddATxiFX1F6Ud+Gi3oiv87gprldRL42xAD0f5V8N UIgUqUevxX5pQwEBm8dH1AGwYhFFqJqYlRCpwVCXCaExNh08wdU/MZHULDNQDrOJQyxD0 nG5yTpuWiwgN0QaxdSB6sSqjoSmRgKSRqtgdLfdtw077KFBvQkDhkZzBUYzZ4pPTABg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796298079; 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=DEzU2zAD9NNhG+RkbRjZe24FHYLMHhu/LVx4i14kItI=; b=gKTSLRJce0d13A2uw6AOQOuw6KwhGRUqnK6npgSCQnV7az6rqcaREBLulBcSNv7wRqcW srxQxpjuoz6GGv0FnXEbazBmQ14jgR38TMR7WrZ19SRCXLtc5ZdeSgAgp1Y1G6HT3b88r z/wQNRuD/MYwnfyd0XMpYb9RIGuUKg/UpcxvxOZw09Q3gk/yJBMjfoU3CvJb7saSRG3s+ LGMRA4FgD3127kAR47SfFMEafkDo2XP9LJD+ErJDBQPDbiO1FOQNngP4e84HZANj0BlnI pI5YPyXtD+36u5tYaqn8WtvgBlW8tKuHOmEkAjVkpiWkR+Q+qDVmdEdCtib1S6VIIJQ== 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=WsLccNX1; 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 1ED5C606A322; Thu, 3 Dec 2026 11:41:18 +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=WsLccNX1 Received: by smtp.kernel.org (Postfix) with ESMTPSA id E2A5A1F000C1; Thu, 3 Dec 2026 11:41:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796298078; bh=DEzU2zAD9NNhG+RkbRjZe24FHYLMHhu/LVx4i14kItI=; h=From:Date:Subject:References:In-Reply-To:To:Cc; b=WsLccNX1wpYBA0agUb8qzcqsyKJy8R9iqQ23CpcAUUXb0egO9Yceug9MUtL70xao3 mQauEGo1ZA9kp+R/RgNABnwMChXQWQz7iQNvhFct8+4Tr9GR6xlqV+lQwILyGaG2Lt m/2zHulC6JZxsJJIno6d2z+axMSfQdWT2r71niHDgaRFM9dnf3VUw1O2S4zOPhdK7Y fSmvtFh1o9x8FcXIK2VaiNiYFvAWnlBgktEJLFVpgqN2plmjjew4EJ6ESzoDZB6c0c 8I3geIjAPVyW2wQ03OxGQHvxveuZ0PdLcY4b5E9HHZjDFQs2mjkBOM3/nBK6Lcw7n1 e/xlKWvifnhsg== From: "David Hildenbrand (Arm)" Date: Thu, 03 Dec 2026 12:37:37 +0100 Subject: [PATCH v2 14/35] hugetlbfs: fix integer overflow when punching holes 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 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20261203-hugetlb_fixes_2-v2-14-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=1913; i=david@kernel.org; h=from:subject:message-id; bh=mAsXOKRcKA7ewZ5f1afGnJRGNXNb8mMRY2usxE8QpMY=; b=owGbwMvMwCF2/OVpCdfQ3ZWMp9WSGLIFQ6qXnktcFzBLp35Tfc/fzRcKez7s/cHyQul26M7/f sfLOjeZdZSyMIhxMMiKKbIEBd83ePlyXW21Gx8zzBxWJpAhDFycAjCRQBNGhln8Rp/2Z73Q4Z3G E+/g+Wemsc3xqpY7c6f9s9KyyonX+sHIsPjEzNtXtlkf5nfL2+qgkHv66r159ms+1JYwz+lf9Om 5CT8A X-Developer-Key: i=david@kernel.org; a=openpgp; fpr=1BD9CAAD735C4C3A460DFCCA4DDE10F700FF835A hugetlbfs_punch_hole() rounds up the offset to find the first full huge page in the hole, and zeroes the partial huge page before it, starting at the offset. However, if the offset falls into the last possible huge page below LLONG_MAX, but not at its start, rounding up overflows and hole_start becomes LLONG_MIN. Consequently, we will zero from the start of that huge page, not from the offset. Reproduced by allocating that huge page with fallocate(), placing data in it through udmabuf, and punching a hole starting inside it: the data before the hole gets zeroed. Let's fix it by clamping hole_start to offset + len on overflow, as there are no full huge pages in the hole in that case. This has low urgency: hugetlbfs supports neither write() nor mmap() of that last huge page, so only something like udmabuf could place data there, which no reasonable use case does. No need to CC stable. Fixes: 68d32527d340 ("hugetlbfs: zero partial pages during fallocate hole punch") Reported-by: Sashiko Signed-off-by: David Hildenbrand (Arm) --- fs/hugetlbfs/inode.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c index 4a92f31c88e1a..8ac8925d7ad8b 100644 --- a/fs/hugetlbfs/inode.c +++ b/fs/hugetlbfs/inode.c @@ -672,8 +672,12 @@ static long hugetlbfs_punch_hole(struct inode *inode, loff_t offset, loff_t len) /* * hole_start and hole_end indicate the full pages within the hole. + * If rounding up overflows, there are no full pages in the hole. */ - hole_start = round_up(offset, hpage_size); + if (check_add_overflow(offset, hpage_size - 1, &hole_start)) + hole_start = offset + len; + else + hole_start = round_down(hole_start, hpage_size); hole_end = round_down(offset + len, hpage_size); inode_lock(inode); -- 2.56.1