diff options
author | Campbell Suter <campbell@snapit.group> | 2021-04-30 16:45:46 +1200 |
---|---|---|
committer | Tom Rini <trini@konsulko.com> | 2021-08-04 15:58:31 -0400 |
commit | a1ff2cb4d433f983b25a2b2920dbfcea5dc4555c (patch) | |
tree | 29d7a6031621af2407122072e812e058ac08c363 /fs/squashfs | |
parent | 8edecd3110e65ca96a50a37bf7ca65ed45070452 (diff) | |
download | u-boot-a1ff2cb4d433f983b25a2b2920dbfcea5dc4555c.tar.gz u-boot-a1ff2cb4d433f983b25a2b2920dbfcea5dc4555c.tar.bz2 u-boot-a1ff2cb4d433f983b25a2b2920dbfcea5dc4555c.zip |
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>
Diffstat (limited to 'fs/squashfs')
-rw-r--r-- | fs/squashfs/sqfs_filesystem.h | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/fs/squashfs/sqfs_filesystem.h b/fs/squashfs/sqfs_filesystem.h index 856cd15e34..5440b6c0e0 100644 --- a/fs/squashfs/sqfs_filesystem.h +++ b/fs/squashfs/sqfs_filesystem.h @@ -231,7 +231,7 @@ union squashfs_inode { struct squashfs_directory_entry { u16 offset; - u16 inode_offset; + s16 inode_offset; u16 type; u16 name_size; char name[0]; |