From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=167.99.218.202 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796426775; b=Cxp0FKZn+vuAYbGhN7A/r5vTzwvK1teSbmdVE9DfNb9ZB3qV+DO90GM52mxZur+f60SD EJkvgMnoftr0Viii3JxnebmKCX6kEb8sZiHJxF5DyGv9NbIF+z05cgEK//ZCOBhaKU5E6 csYNqeJJeaq/yonMFMfZTKlvnPxKAe7/MUJcDX50cIWfUfwqTqCtRPegchoMmM2TiK/5+ fWgG3kpTvl1yiLi/EwzBYbOQXBGMWBSbE/a260gw3wX7xVD9HVWCPczJvzshAplKJzb9c +a094TQQjqFLRzcOc1Xktm1ywi3269rYB1H3jnJ6Woe5WUWx58/Fr3AVjwEpgFVaBWg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796426775; h=DMARC-Filter:DKIM-Signature:Received:From:To:Cc:Subject:Date: Message-ID:X-Mailer:MIME-Version:Content-Transfer-Encoding; bh=3ZyNugyzzdHF8w5b3GhLHF1TYHIWsceAVUw8pZACsNk=; b=XulD9gHEgB9KVDS8IYk+CBNxG7p5c3kTfpObwZN9fGiJE+Cut63kU4C/iSetpcLoQOTu mYNC5AWQ9P3TK1iW1D3o+VCwB3k+9ZZZ5MaLiitZetYEpc8M3kJNvZ7XkM7/QXUijpnB5 XN2IXHskQ1dWsh3nc7tPlTmZJTmmmsc3vHRfwYAJ/pSOqTkoOhCBFvW/44d8njSLL54yg EyRchjljihoES+30p4D2Dbxb6jaz7aDX/iZFJwBbr1twv0W5pg77Wtc7x8NvN4lqp1Orn HsE6aN8SyJAN1jIogNp5yw6Oar41EaMGFm79bNZSLO4Uq/HUkg4/3b4KbjJjJ35HCIA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=lunar-linux.org; spf=pass smtp.mailfrom=lunar-linux.org; dkim=pass header.d=lunar-linux.org header.i=@lunar-linux.org header.a=rsa-sha256 header.s=liberica header.b=Execx0oN; arc=none smtp.remote-ip=167.99.218.202 Received: from liberica.lunar-linux.org (liberica.lunar-linux.org [167.99.218.202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B739B606A322; Fri, 4 Dec 2026 23:26:14 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org B739B606A322 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=lunar-linux.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=lunar-linux.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=lunar-linux.org header.i=@lunar-linux.org header.a=rsa-sha256 header.s=liberica header.b=Execx0oN DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=lunar-linux.org; s=liberica; t=1796426766; bh=3VS54vnUpq+oalj3YrZTh1UoVokrodHOH03JsICJ0JA=; h=From:To:Cc:Subject:Date:From; b=Execx0oN8mMx94dZ4UA54uF6g40sNklZJzv1UVL5oWJZHffyYua9FlauoB/SgnYs4 eyLmKL6K1301si93u1VKRHOntWptBGgo7snpHI2+UeRSBzf/SCEuP1dCnWOBSM9McG bhtfnvXoeuKzx2LefkKAEKgZ7mLJoT3Pi1J0hnqq/x1meD6g/XxNO/U/p9w3iF0yME c1b7A0ClSJYoNPvKXVM5DenOf3IDIZFMXzZuZc2lK1towAZBn71qXpHeWXQ77Psqwt iYuWj2uqsqwpWNld4inHJFTdN3cknFjBbXw2+VkO34BaUPW2A29GNFklXrYrIVOgmD orfCFtHNmUV3w== Received: by liberica.lunar-linux.org (Postfix, from userid 0) id C2812C193D; Fri, 04 Dec 2026 23:26:06 +0000 (UTC) From: Stefan Wold To: Phillip Lougher , Andrew Morton Cc: Hsin-Yi Wang , linux-kernel@vger.kernel.org, stable@vger.kernel.org Subject: [PATCH] squashfs: fix readahead start on 32-bit for files larger than 4 GiB Date: Fri, 4 Dec 2026 23:26:06 +0000 Message-ID: <20261204232606.1078776-1-ratler@lunar-linux.org> X-Mailer: git-send-email 2.53.0 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-Transfer-Encoding: 8bit In squashfs_readahead() the block mask is a size_t: size_t mask = (1UL << msblk->block_log) - 1; loff_t start = readahead_pos(ractl) & ~mask; On 32-bit architectures size_t is 32 bits wide, so ~mask is a 32-bit value (e.g. 0xfffe0000 for 128 KiB blocks). It is zero-extended when promoted to loff_t, which clears the upper 32 bits of the readahead position. For a read at or beyond 4 GiB, start then points into the first 4 GiB of the file, a multiple of 4 GiB below the block being read. readahead_expand() extends the request downwards towards start, adding locked pages to the page cache for everything in between. It stops early only if it finds a page that is already cached or an allocation fails. Reproducer, on a 32-bit kernel: truncate -s 16G big mksquashfs big test.sqsh mount -t squashfs -o loop test.sqsh /mnt dd if=/mnt/big of=/dev/null bs=64k count=1 skip=81920 On i686 with 2 GiB of RAM this 64 KiB read at offset 5 GiB takes 3 to 4 seconds and uses more than 1.6 GiB of memory while it runs (most of what was free). The same read below 4 GiB (skip=49152) takes less than a millisecond and uses well under 1 MiB. A live ISO that stores its root filesystem as a 16 GiB sparse ext4 image inside squashfs (dracut dmsquash-live layout) runs out of memory during boot as soon as udev probes the end of the loop device, and panics with "System is deadlocked on memory". Widen the mask to loff_t before inverting it. With this change the read at 5 GiB behaves like the one below 4 GiB, and that live ISO boots to its installer. Tested on i686 (PAE) under QEMU with 7.4-rc5 and 7.3.6. The bug was found with the help of an AI coding assistant (Claude Code), which also drafted the patch and this changelog. Fixes: 8fc78b6fe24c ("squashfs: implement readahead") Cc: stable@vger.kernel.org Signed-off-by: Stefan Wold --- Notes: "Squashfs: very large files can exceed an int or size_t" [1], currently in mm-nonmm-unstable, changes mask to s64 and with that also fixes this bug. That patch is a larger change and carries no Fixes: or stable tag, so this one-liner is intended as the fix that can be backported. It applies to mainline, mm-hotfixes-unstable and linux-6.1.y through linux-7.3.y. The two patches conflict in one place: the line changed here is a context line in the squashfs_readahead() hunk of [1]. With both applied the cast is redundant and can be dropped. Tool use: I noticed that the i686 live ISO I build panicked in the initrd during boot, and directed the debugging in a Claude Code session. The session narrowed the failure down by experiment (RAM size, THP, SMP, an x86_64 comparison, reads at offsets around 4 GiB) and then found the cause by reading squashfs_readahead(). It wrote the one-line change and drafted the changelog. A second session reviewed both, and I reviewed the result. The kernel builds and test runs below were also carried out in those sessions. Testing: i686 PAE kernels built from 7.4-rc5 and 7.3.6, with and without the change, run in QEMU (qemu32). Both patched kernels boot the live ISO. The reproducer above was run on 7.4-rc5 with 2 GiB of RAM; the image was made with squashfs-tools 4.7.2 on an x86_64 host. 64 KiB reads, with MemFree sampled while dd runs: offset unpatched patched 3 GiB 0 kB, 0.0004 s 456 kB, 0.0005 s 4 GiB - 64 KiB 0 kB, 0.0002 s 224 kB, 0.0004 s 5 GiB 1.62 GiB, 3.88 s 252 kB, 0.0002 s 16 GiB - 64 KiB 1.73 GiB, 1.02 s 456 kB, 0.0009 s With this fully sparse file the memory is released when the read returns and nothing panics. Equivalent reads from the live ISO's image, which contains data, ended in the OOM panic at 16 GiB - 64 KiB on the unpatched kernel. Not tested: other 32-bit architectures. [1] https://patch.msgid.link/20261125014737.347231-15-phillip@squashfs.org.uk fs/squashfs/file.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/squashfs/file.c b/fs/squashfs/file.c index d83594ce9..6fa04f988 100644 --- a/fs/squashfs/file.c +++ b/fs/squashfs/file.c @@ -577,7 +577,7 @@ static void squashfs_readahead(struct readahead_control *ractl) struct squashfs_sb_info *msblk = inode->i_sb->s_fs_info; size_t mask = (1UL << msblk->block_log) - 1; unsigned short shift = msblk->block_log - PAGE_SHIFT; - loff_t start = readahead_pos(ractl) & ~mask; + loff_t start = readahead_pos(ractl) & ~(loff_t)mask; size_t len = readahead_length(ractl) + readahead_pos(ractl) - start; struct squashfs_page_actor *actor; unsigned int nr_pages = 0; base-commit: 5dff0c81e94cd72d52bdfbb6044462c1be10f8d0 -- 2.51.1