Skip to contentSkip to conversation

squashfs: Fix sqfs_inode_size() for xattr related SQFS_LSYMLINK_TYPE

PATCH In review [email protected] 2 participants 2 messages Dec 24, 2024 – Jan 18, 2025 SquashFS file system

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 squashfs: Fix sqfs_inode_size() for xattr related SQFS_LSYMLINK_TYPE

From: Norbert van Bolhuis <[email protected]>

A squashfs filesystem with extended attributes (xattrs) may have inodes of type SQFS_LSYMLINK_TYPE. This might cause u-boot to fail to handle the filesystem since it assumes a SYMLINK_TYPE and LSYMLINK_TYPE inode are the same size. This is wrong, see:
https://github.com/plougher/squashfs-tools/blob/master/squashfs-tools/read_fs.c#L421

Using the mksquashfs '-no-xattrs' argument is probably best, but the mksquashfs '-xattrs' argument is the default.
This patch fixes squashfs image handling by making sure parsing the uncompressed inode_table (with sqfs_find_inode) succeeeds. The only change needed is correctly determining the size of a SQFS_LSYMLINK_TYPE inode.

---
 fs/squashfs/sqfs_inode.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
fs/squashfs/sqfs_inode.c +4 -2
index bb3ccd37e3..ce9a8ff8e2 100644
@@ -19,7 +19,9 @@
 
 int sqfs_inode_size(struct squashfs_base_inode *inode, u32 blk_size)
 {
-	switch (get_unaligned_le16(&inode->inode_type)) {
+	u16 inode_type = get_unaligned_le16(&inode->inode_type);
+
+	switch (inode_type) {
 	case SQFS_DIR_TYPE:
 		return sizeof(struct squashfs_dir_inode);
 
@@ -87,7 +89,7 @@ int sqfs_inode_size(struct squashfs_base_inode *inode, u32 blk_size)
 		    get_unaligned_le32(&symlink->symlink_size), &size))
 			return -EINVAL;
 
-		return size;
+		return (inode_type == SQFS_SYMLINK_TYPE) ? size : size + sizeof(u32);
 	}
 
 	case SQFS_BLKDEV_TYPE:
Signature · 1 line
2.47.1
#1 lore raw
Quoted 6 lines · On Tue, 24 Dec 2024 01:49:04 +0100, [email protected] wrote:

A squashfs filesystem with extended attributes (xattrs) may have inodes of type SQFS_LSYMLINK_TYPE. This might cause u-boot to fail to handle the filesystem since it assumes a SYMLINK_TYPE and LSYMLINK_TYPE inode are the same size. This is wrong, see:
https://github.com/plougher/squashfs-tools/blob/master/squashfs-tools/read_fs.c#L421

Quoted 7 lines

Using the mksquashfs '-no-xattrs' argument is probably best, but the mksquashfs '-xattrs' argument is the default.
This patch fixes squashfs image handling by making sure parsing the uncompressed inode_table (with sqfs_find_inode) succeeeds. The only change needed is correctly determining the size of a SQFS_LSYMLINK_TYPE inode.

[...]

Applied to u-boot/master, thanks!

Signature · 1 line
Tom