* [PATCH] udf: Fix i_lenExtents truncation on 32-bit kernels
@ 2026-07-22 8:24 Zhan Xusheng
2026-07-27 15:53 ` Jan Kara
0 siblings, 1 reply; 2+ messages in thread
From: Zhan Xusheng @ 2026-07-22 8:24 UTC (permalink / raw)
To: Jan Kara; +Cc: linux-fsdevel, linux-kernel, Zhan Xusheng
In udf_do_extend_file() the total extent length is rounded up to a block
boundary with:
iinfo->i_lenExtents = (iinfo->i_lenExtents + sb->s_blocksize - 1) &
~(sb->s_blocksize - 1);
i_lenExtents is a __u64, 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. 0xfffff800 for a 2 KiB block) that is zero-extended in the AND,
clearing the upper 32 bits of i_lenExtents. For UDF files whose total
extent length exceeds 4 GiB this truncates i_lenExtents when the file is
extended, corrupting the tracked extent length.
Cast the block size to 64-bit before forming the mask. 64-bit kernels are
unaffected.
Fixes: 48d6d8ff7dca ("udf: cache struct udf_inode_info")
Cc: stable@vger.kernel.org
Signed-off-by: Zhan Xusheng <zhanxusheng@xiaomi.com>
---
fs/udf/inode.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/fs/udf/inode.c b/fs/udf/inode.c
index 67bcf83758c8..c519644acfd7 100644
--- a/fs/udf/inode.c
+++ b/fs/udf/inode.c
@@ -531,7 +531,7 @@ static int udf_do_extend_file(struct inode *inode,
sb->s_blocksize - 1) & ~(sb->s_blocksize - 1));
iinfo->i_lenExtents =
(iinfo->i_lenExtents + sb->s_blocksize - 1) &
- ~(sb->s_blocksize - 1);
+ ~((u64)sb->s_blocksize - 1);
}
add = 0;
--
2.43.0
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] udf: Fix i_lenExtents truncation on 32-bit kernels
2026-07-22 8:24 [PATCH] udf: Fix i_lenExtents truncation on 32-bit kernels Zhan Xusheng
@ 2026-07-27 15:53 ` Jan Kara
0 siblings, 0 replies; 2+ messages in thread
From: Jan Kara @ 2026-07-27 15:53 UTC (permalink / raw)
To: Zhan Xusheng; +Cc: Jan Kara, linux-fsdevel, linux-kernel, Zhan Xusheng
On Wed 22-07-26 16:24:25, Zhan Xusheng wrote:
> In udf_do_extend_file() the total extent length is rounded up to a block
> boundary with:
>
> iinfo->i_lenExtents = (iinfo->i_lenExtents + sb->s_blocksize - 1) &
> ~(sb->s_blocksize - 1);
>
> i_lenExtents is a __u64, 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. 0xfffff800 for a 2 KiB block) that is zero-extended in the AND,
> clearing the upper 32 bits of i_lenExtents. For UDF files whose total
> extent length exceeds 4 GiB this truncates i_lenExtents when the file is
> extended, corrupting the tracked extent length.
>
> Cast the block size to 64-bit before forming the mask. 64-bit kernels are
> unaffected.
>
> Fixes: 48d6d8ff7dca ("udf: cache struct udf_inode_info")
> Cc: stable@vger.kernel.org
> Signed-off-by: Zhan Xusheng <zhanxusheng@xiaomi.com>
Thanks. I've added the patch to my tree.
Honza
> ---
> fs/udf/inode.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/fs/udf/inode.c b/fs/udf/inode.c
> index 67bcf83758c8..c519644acfd7 100644
> --- a/fs/udf/inode.c
> +++ b/fs/udf/inode.c
> @@ -531,7 +531,7 @@ static int udf_do_extend_file(struct inode *inode,
> sb->s_blocksize - 1) & ~(sb->s_blocksize - 1));
> iinfo->i_lenExtents =
> (iinfo->i_lenExtents + sb->s_blocksize - 1) &
> - ~(sb->s_blocksize - 1);
> + ~((u64)sb->s_blocksize - 1);
> }
>
> add = 0;
> --
> 2.43.0
>
--
Jan Kara <jack@suse.com>
SUSE Labs, CR
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-07-27 15:53 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-07-22 8:24 [PATCH] udf: Fix i_lenExtents truncation on 32-bit kernels Zhan Xusheng
2026-07-27 15:53 ` Jan Kara
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®