Skip to contentSkip to conversation

erofs-utils: lib: fix xattr prefix offset truncation

PATCH In review bingying lan 2 participants 3 messages Oct 20 Library code

lore
Share & tools
lore
#0 lore raw

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.

Fixes b6b741d8daaf ("erofs-utils: lib: get rid of tmpfile()")
---
 lib/xattr.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/xattr.c +1 -1
index d86d94a..e742bfc 100644
@@ -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
Reviewed-by on v1 1/1
#1 lore raw

Hi Bingying,

Quoted 21 lines · bingying lan

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.

Fixes b6b741d8daaf ("erofs-utils: lib: get rid of tmpfile()")
---
 lib/xattr.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/xattr.c +0 -0
index d86d94a..e742bfc 100644

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

#2 lore raw
In reply to bingying lan
Quoted 21 lines · bingying lan

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.

Fixes b6b741d8daaf ("erofs-utils: lib: get rid of tmpfile()")
---
 lib/xattr.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/xattr.c +0 -0
index d86d94a..e742bfc 100644

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