u-boot/fs
Campbell Suter a1ff2cb4d4 fs/squashfs: Fix some hardlinks reading the wrong inode
In SquashFS, the contents of a directory is stored by
squashfs_directory_entry structures which contain the file's name, inode
and position within the filesystem.

The inode number is not stored directly; instead each directory has one
or more headers which set a base inode number, and files store the
offset from that to the file's inode number.

In mksquashfs, each inode is allocated a number in the same order as
they are written to the directory table; thus the offset from the
header's base inode number to the file's inode number is usually
positive.

Hardlinks are simply stored with two directory entries referencing the
same file. This means the second entry will thus have an inode number
much lower than the surrounding files. Since the header's base inode
number comes from the first entry that uses the header, this delta will
usually be negative.

Previously, U-Boot's squashfs_directory_entry.inode_offset field was
declared as an unsigned value. Thus when a negative value was found, it
would either resolve to an invalid inode number or to that of an
unrelated file.

A squashfs image to test this can be created like so:

    echo hi > sqfs_test_files/001-root-file
    mkdir     sqfs_test_files/002-subdir
    touch     sqfs_test_files/002-subdir/003-file
    ln        sqfs_test_files/{001-root-file,002-subdir/004-link}
    mksquashfs sqfs_test_files/ test.sqfs -noappend

Note that squashfs sorts the files ASCIIbetacally, so we can use the
names to control the order they appear in. The ordering is important -
the first reference to the file must have a lower inode number than the
directory in which the second reference resides, and the second
reference cannot be the first file in the directory.

Listing this sample image in U-Boot results in:

=> sqfsls virtio 2 002-subdir
         0   003-file
Inode not found.
         0   004-link

Signed-off-by: Campbell Suter <campbell@snapit.group>
Reviewed-by: Miquel Raynal <miquel.raynal@bootlin.com>
2021-08-04 15:58:31 -04:00
..
btrfs Use LIB_UUID with ACPIGEN and FS_BTRFS 2021-07-28 14:27:54 -04:00
cbfs cbfs: Check offset range when reading a file 2021-07-15 18:42:05 -04:00
cramfs common: Drop flash.h from common header 2020-05-18 14:53:28 -04:00
ext4 common: Drop log.h from common header 2020-05-18 21:19:18 -04:00
fat fs: fat: add file attributes to struct fs_dirent 2021-07-12 20:30:48 +02:00
jffs2 JFFS2: fix jffs2 summary datacrc status uninitialized 2021-04-07 10:22:22 -04:00
reiserfs common: Drop asm/global_data.h from common header 2021-02-02 15:33:42 -05:00
sandbox common: Drop part.h from common header 2020-05-18 17:33:33 -04:00
squashfs fs/squashfs: Fix some hardlinks reading the wrong inode 2021-08-04 15:58:31 -04:00
ubifs common: Drop asm/global_data.h from common header 2021-02-02 15:33:42 -05:00
yaffs2 common: Drop linux/bug.h from common header 2020-05-18 21:19:23 -04:00
zfs common: Drop log.h from common header 2020-05-18 21:19:18 -04:00
fs.c global: Convert simple_strtoul() with hex to hextoul() 2021-08-02 13:32:14 -04:00
fs_internal.c fs: convert error and debug messages to log 2020-09-06 21:21:41 +02:00
Kconfig fs/squashfs: new filesystem 2020-08-07 22:31:32 -04:00
Makefile fs/squashfs: new filesystem 2020-08-07 22:31:32 -04:00