Re: [PATCH 0/2] fs: fix readdir position truncation on 32-bit kernels

From: Theodore Ts'o

Date: Thu Nov 19 2026 - 09:56:21 EST



On Thu, 06 Aug 2026 10:20:42 +0800, Zhan Xusheng wrote:
> Both ext4 and ocfs2 rebuild the directory cookie in ->iterate with
>
> ctx->pos = (ctx->pos & ~(sb->s_blocksize - 1)) | offset;
>
> ctx->pos is loff_t (64-bit) but sb->s_blocksize is unsigned long. On
> 32-bit kernels unsigned long is 32-bit, so ~(sb->s_blocksize - 1) is a
> 32-bit value (e.g. 0xfffff000 for 4 KiB) and, under the usual arithmetic
> conversions, is zero-extended to 0x00000000fffff000 in the AND with the
> 64-bit ctx->pos. The high 32 bits of ctx->pos are silently cleared even
> though a directory may exceed 4 GiB.
>
> [...]

Applied, thanks!

[1/2] ext4: fix readdir position truncation on 32-bit kernels
commit: c966757ff80fe8407e2e3acdd720964769ddf937
[2/2] ocfs2: fix readdir position truncation on 32-bit kernels
Not applicable for the ext4 tree

Best regards,
--
Theodore Ts'o <tytso@xxxxxxx>