erofs-utils: lib: fix xattr prefix offset truncation
PATCH 1/1 erofs-utils: lib: fix xattr prefix offset truncation
xattr_prefix_start stores the long xattr prefix table offset in 4-byte units. Casting the byte offset to u32 before shifting discards its upper bits, even though the overflow check accepts offsets whose shifted value fits in u32. The table is written at the full offset, but the superblock points to the truncated location.
Shift the offset before narrowing it to u32. This prevents corrupted images when incremental builds place the prefix table at or beyond 4 GiB.
--- lib/xattr.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
lib/xattr.c +1 -1
@@ -921,7 +921,7 @@ int erofs_xattr_flush_name_prefixes(struct erofs_importer *im, bool plain)return -EOVERFLOW ; start = offset; - sbi->xattr_prefix_start = (u32 )offset >>2 ; + sbi->xattr_prefix_start = (u32)(offset >>2 ); sbi->xattr_prefix_count = ea_prefix_count;list_for_each_entry (tnode, &ea_name_prefixes, list) {
Signature · 1 line
2.53.0.apsara
Hi Bingying,
Quoted 21 lines · bingying lan
xattr_prefix_startstores the long xattr prefix table offset in 4-byte units. Casting the byte offset to u32 before shifting discards its upper bits, even though the overflow check accepts offsets whose shifted value fits in u32. The table is written at the full offset, but the superblock points to the truncated location.Shift the offset before narrowing it to u32. This prevents corrupted images when incremental builds place the prefix table at or beyond 4 GiB.
Fixes b6b741d8daaf ("erofs-utils: lib: get rid of tmpfile()")Signed-off-by bingying lan <[email protected]>--- lib/xattr.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)lib/xattr.c +0
-0
lib/xattr.c int erofs_xattr_flush_name_prefixes(struct erofs_importer *im, bool plain) · line 924
Quoted 5 lines
lib/xattr.c +1
-1@@ -921,7 +921,7 @@ int erofs_xattr_flush_name_prefixes(struct erofs_importer *im, bool plain)return -EOVERFLOW ; start = offset; - sbi->xattr_prefix_start = (u32 )offset >>2 ; + sbi->xattr_prefix_start = (u32)(offset >>2 );
Good catch:
will move to -fixes after -rc1 is out.
Thanks,
Gao Xiang
Quoted 21 lines · bingying lan
xattr_prefix_startstores the long xattr prefix table offset in 4-byte units. Casting the byte offset to u32 before shifting discards its upper bits, even though the overflow check accepts offsets whose shifted value fits in u32. The table is written at the full offset, but the superblock points to the truncated location.Shift the offset before narrowing it to u32. This prevents corrupted images when incremental builds place the prefix table at or beyond 4 GiB.
Fixes b6b741d8daaf ("erofs-utils: lib: get rid of tmpfile()")Signed-off-by bingying lan <[email protected]>--- lib/xattr.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)lib/xattr.c +0
-0
lib/xattr.c int erofs_xattr_flush_name_prefixes(struct erofs_importer *im, bool plain) · line 924
Quoted 5 lines
lib/xattr.c +1
-1@@ -921,7 +921,7 @@ int erofs_xattr_flush_name_prefixes(struct erofs_importer *im, bool plain)return -EOVERFLOW ; start = offset; - sbi->xattr_prefix_start = (u32 )offset >>2 ; + sbi->xattr_prefix_start = (u32)(offset >>2 );
oh, it seems an erofs-utils one, merging now.
Thanks,
Gao Xiang