Skip to contentSkip to conversation

erofs: fix potential overflow calculating xattr_isize

PATCH In review Jingbo Xu 3 participants 3 messages Apr 14, 2023 – Apr 16, 2023 EROFS file system

lore
Share & tools
lore

Jingbo Xu

author
#0 lore raw

PATCH 1/1 erofs: fix potential overflow calculating xattr_isize

Given on-disk i_xattr_icount is 16 bits and xattr_isize is calculated from i_xattr_icount multiplying 4, xattr_isize has a theoretical maximum of 256K (64K * 4).

Thus declare xattr_isize as unsigned int to avoid the potential overflow.

Fixes bfb8674dc044 ("staging: erofs: add erofs in-memory stuffs")
---
 fs/erofs/internal.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/erofs/internal.h +1 -1
index 8a563374b518..c86241a32ab3 100644
@@ -306,7 +306,7 @@ struct erofs_inode {
 
 	unsigned char datalayout;
 	unsigned char inode_isize;
-	unsigned short xattr_isize;
+	unsigned int xattr_isize;
 
 	unsigned int xattr_shared_count;
 	unsigned int *xattr_shared_xattrs;
Signature · 1 line
2.19.1.6.gb485710b
Reviewed-by on v1 1/1
#1 lore raw
Quoted 8 lines · Jingbo Xu

Given on-disk i_xattr_icount is 16 bits and xattr_isize is calculated from i_xattr_icount multiplying 4, xattr_isize has a theoretical maximum of 256K (64K * 4).

Thus declare xattr_isize as unsigned int to avoid the potential overflow.

Fixes bfb8674dc044 ("staging: erofs: add erofs in-memory stuffs")

Thanks for catching this!

Thanks,
Gao Xiang

Quoted 17 lines
---
  fs/erofs/internal.h | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
fs/erofs/internal.h +1 -1
index 8a563374b518..c86241a32ab3 100644
@@ -306,7 +306,7 @@ struct erofs_inode {
 
  	unsigned char datalayout;
  	unsigned char inode_isize;
-	unsigned short xattr_isize;
+	unsigned int xattr_isize;
 
  	unsigned int xattr_shared_count;
  	unsigned int *xattr_shared_xattrs;
maintainer Reviewed-by on v1 1/1
#2 lore raw
In reply to Jingbo Xu
Quoted 8 lines · Jingbo Xu

Given on-disk i_xattr_icount is 16 bits and xattr_isize is calculated from i_xattr_icount multiplying 4, xattr_isize has a theoretical maximum of 256K (64K * 4).

Thus declare xattr_isize as unsigned int to avoid the potential overflow.

Fixes bfb8674dc044 ("staging: erofs: add erofs in-memory stuffs")

Good catch!

Thanks,