From: Tom Rini <trini@konsulko.com>
To: Campbell Suter <campbell@snapit.group>
Cc: u-boot@lists.denx.de,
Joao Marcos Costa <joaomarcos.costa@bootlin.com>,
Thomas Petazzoni <thomas.petazzoni@bootlin.com>,
Miquel Raynal <miquel.raynal@bootlin.com>
Subject: Re: [PATCH] fs/squashfs: Fix some hardlinks reading the wrong inode
Date: Wed, 4 Aug 2021 21:18:54 -0400 [thread overview]
Message-ID: <20210805011854.GE858@bill-the-cat> (raw)
In-Reply-To: <d482bb9d-19d2-c4e9-08a0-1c0b9d58776c@snapit.group>
[-- Attachment #1: Type: text/plain, Size: 2233 bytes --]
On Fri, Apr 30, 2021 at 04:45:46PM +1200, Campbell Suter wrote:
> 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>
Applied to u-boot/master, thanks!
--
Tom
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 659 bytes --]
prev parent reply other threads:[~2021-08-05 1:19 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-04-30 4:45 [PATCH] fs/squashfs: Fix some hardlinks reading the wrong inode Campbell Suter
2021-05-04 7:30 ` Miquel Raynal
2021-08-05 1:18 ` Tom Rini [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210805011854.GE858@bill-the-cat \
--to=trini@konsulko.com \
--cc=campbell@snapit.group \
--cc=joaomarcos.costa@bootlin.com \
--cc=miquel.raynal@bootlin.com \
--cc=thomas.petazzoni@bootlin.com \
--cc=u-boot@lists.denx.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox