<feed xmlns='http://www.w3.org/2005/Atom'>
<title>u-boot.git/fs/squashfs, branch v2022.07</title>
<subtitle>Unnamed repository; edit this file 'description' to name the repository.</subtitle>
<id>http://cgit.235523.xyz/u-boot.git/atom/fs/squashfs?h=v2022.07</id>
<link rel='self' href='http://cgit.235523.xyz/u-boot.git/atom/fs/squashfs?h=v2022.07'/>
<link rel='alternate' type='text/html' href='http://cgit.235523.xyz/u-boot.git/'/>
<updated>2022-06-28T19:51:56Z</updated>
<entry>
<title>fs/squashfs: Use kcalloc when relevant</title>
<updated>2022-06-28T19:51:56Z</updated>
<author>
<name>Miquel Raynal</name>
<email>miquel.raynal@bootlin.com</email>
</author>
<published>2022-06-27T10:20:03Z</published>
<link rel='alternate' type='text/html' href='http://cgit.235523.xyz/u-boot.git/commit/?id=7f7fb9937c6cb49dd35153bd6708872b390b0a44'/>
<id>urn:sha1:7f7fb9937c6cb49dd35153bd6708872b390b0a44</id>
<content type='text'>
A crafted squashfs image could embed a huge number of empty metadata
blocks in order to make the amount of malloc()'d memory overflow and be
much smaller than expected. Because of this flaw, any random code
positioned at the right location in the squashfs image could be memcpy'd
from the squashfs structures into U-Boot code location while trying to
access the rearmost blocks, before being executed.

In order to prevent this vulnerability from being exploited in eg. a
secure boot environment, let's add a check over the amount of data
that is going to be allocated. Such a check could look like:

if (!elem_size || n &gt; SIZE_MAX / elem_size)
	return NULL;

The right way to do it would be to enhance the calloc() implementation
but this is quite an impacting change for such a small fix. Another
solution would be to add the check before the malloc call in the
squashfs implementation, but this does not look right. So for now, let's
use the kcalloc() compatibility function from Linux, which has this
check.

Fixes: c5100613037 ("fs/squashfs: new filesystem")
Reported-by: Tatsuhiko Yasumatsu &lt;Tatsuhiko.Yasumatsu@sony.com&gt;
Signed-off-by: Miquel Raynal &lt;miquel.raynal@bootlin.com&gt;
Tested-by: Tatsuhiko Yasumatsu &lt;Tatsuhiko.Yasumatsu@sony.com&gt;
</content>
</entry>
<entry>
<title>fs/squashfs: sqfs_read: Prevent arbitrary code execution</title>
<updated>2022-06-16T19:22:55Z</updated>
<author>
<name>Miquel Raynal</name>
<email>miquel.raynal@bootlin.com</email>
</author>
<published>2022-06-09T14:02:06Z</published>
<link rel='alternate' type='text/html' href='http://cgit.235523.xyz/u-boot.git/commit/?id=2ac0baab4aff1a0b45067d0b62f00c15f4e86856'/>
<id>urn:sha1:2ac0baab4aff1a0b45067d0b62f00c15f4e86856</id>
<content type='text'>
Following Jincheng's report, an out-of-band write leading to arbitrary
code execution is possible because on one side the squashfs logic
accepts directory names up to 65535 bytes (u16), while U-Boot fs logic
accepts directory names up to 255 bytes long.

Prevent such an exploit from happening by capping directory name sizes
to 255. Use a define for this purpose so that developers can link the
limitation to its source and eventually kill it some day by dynamically
allocating this array (if ever desired).

Link: https://lore.kernel.org/all/CALO=DHFB+yBoXxVr5KcsK0iFdg+e7ywko4-e+72kjbcS8JBfPw@mail.gmail.com
Reported-by: Jincheng Wang &lt;jc.w4ng@gmail.com&gt;
Signed-off-by: Miquel Raynal &lt;miquel.raynal@bootlin.com&gt;
Tested-by: Jincheng Wang &lt;jc.w4ng@gmail.com&gt;
</content>
</entry>
<entry>
<title>squashfs: Fix compilation on big endian systems</title>
<updated>2022-06-03T15:15:24Z</updated>
<author>
<name>Pali Rohár</name>
<email>pali@kernel.org</email>
</author>
<published>2022-04-06T21:31:53Z</published>
<link rel='alternate' type='text/html' href='http://cgit.235523.xyz/u-boot.git/commit/?id=9320db0926ae4c2a24015298e3b374a07023267e'/>
<id>urn:sha1:9320db0926ae4c2a24015298e3b374a07023267e</id>
<content type='text'>
Signed-off-by: Pali Rohár &lt;pali@kernel.org&gt;
Reviewed-by: Miquel Raynal &lt;miquel.raynal@bootlin.com&gt;
</content>
</entry>
<entry>
<title>fs/squashfs: use lldiv function for math</title>
<updated>2022-05-23T13:33:10Z</updated>
<author>
<name>Sean Nyekjaer</name>
<email>sean.nyekjaer.ext@siemensgamesa.com</email>
</author>
<published>2022-05-12T18:37:14Z</published>
<link rel='alternate' type='text/html' href='http://cgit.235523.xyz/u-boot.git/commit/?id=92080c6ef6c753ca69c53f191a6baef53f98bd6b'/>
<id>urn:sha1:92080c6ef6c753ca69c53f191a6baef53f98bd6b</id>
<content type='text'>
When compling for x86:
ld.bfd: fs/squashfs/sqfs.o: in function `sqfs_read':
u-boot/fs/squashfs/sqfs.c:1443: undefined reference to `__udivmoddi4'
ld.bfd: u-boot/fs/squashfs/sqfs.c:1521: undefined reference to `__udivmoddi4'

Signed-off-by: Sean Nyekjaer &lt;sean.nyekjaer.ext@siemensgamesa.com&gt;
Reviewed-by: Miquel Raynal &lt;miquel.raynal@bootlin.com&gt;
Reviewed-by: Pali Rohár &lt;pali@kernel.org&gt;
</content>
</entry>
<entry>
<title>fs/squashfs: simplify sqfs_read()</title>
<updated>2022-04-19T18:51:11Z</updated>
<author>
<name>Heinrich Schuchardt</name>
<email>heinrich.schuchardt@canonical.com</email>
</author>
<published>2022-04-11T20:54:44Z</published>
<link rel='alternate' type='text/html' href='http://cgit.235523.xyz/u-boot.git/commit/?id=9bd89bbd71b12030294210be7c54da4b7cc77f00'/>
<id>urn:sha1:9bd89bbd71b12030294210be7c54da4b7cc77f00</id>
<content type='text'>
* Don't check argument of free(). Free does this itself.
* Reduce scope of data_buffer. Remove duplicate free().
* Avoid superfluous NULL assignment.

Signed-off-by: Heinrich Schuchardt &lt;heinrich.schuchardt@canonical.com&gt;
Reviewed-by: Miquel Raynal &lt;miquel.raynal@bootlin.com&gt;
</content>
</entry>
<entry>
<title>squashfs: show an error message if the inode_table can't be, allocated</title>
<updated>2022-01-29T12:46:46Z</updated>
<author>
<name>Lars Weber</name>
<email>weber@weber-software.com</email>
</author>
<published>2022-01-13T13:28:45Z</published>
<link rel='alternate' type='text/html' href='http://cgit.235523.xyz/u-boot.git/commit/?id=1e69db57e64249f7f7a5a282a3a2f1b053be3f6f'/>
<id>urn:sha1:1e69db57e64249f7f7a5a282a3a2f1b053be3f6f</id>
<content type='text'>
Signed-off-by: Lars Weber &lt;weber@weber-software.com&gt;
</content>
</entry>
<entry>
<title>sqfs: Suppress the message about missing filesystem</title>
<updated>2021-09-16T17:19:25Z</updated>
<author>
<name>Simon Glass</name>
<email>sjg@chromium.org</email>
</author>
<published>2021-08-19T03:40:27Z</published>
<link rel='alternate' type='text/html' href='http://cgit.235523.xyz/u-boot.git/commit/?id=ad6ddc57eeecbcad62177b47b1e2b63027bcf6a9'/>
<id>urn:sha1:ad6ddc57eeecbcad62177b47b1e2b63027bcf6a9</id>
<content type='text'>
This message comes up a lot when scanning filesystems. It suggests to the
user that there is some sort of error, but in fact there is no reason to
expect that a particular partition has a sqfs filesystem. Other
filesystems don't print this error.

Turn it into a debug message.

Signed-off-by: Simon Glass &lt;sjg@chromium.org&gt;
Reviewed-by: Miquel Raynal &lt;miquel.raynal@bootlin.com&gt;
</content>
</entry>
<entry>
<title>fs/squashfs: Fix some hardlinks reading the wrong inode</title>
<updated>2021-08-04T19:58:31Z</updated>
<author>
<name>Campbell Suter</name>
<email>campbell@snapit.group</email>
</author>
<published>2021-04-30T04:45:46Z</published>
<link rel='alternate' type='text/html' href='http://cgit.235523.xyz/u-boot.git/commit/?id=a1ff2cb4d433f983b25a2b2920dbfcea5dc4555c'/>
<id>urn:sha1:a1ff2cb4d433f983b25a2b2920dbfcea5dc4555c</id>
<content type='text'>
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 &gt; 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:

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

Signed-off-by: Campbell Suter &lt;campbell@snapit.group&gt;
Reviewed-by: Miquel Raynal &lt;miquel.raynal@bootlin.com&gt;
</content>
</entry>
<entry>
<title>fs/squashfs: fix reading of fragmented files</title>
<updated>2021-06-10T00:58:20Z</updated>
<author>
<name>Joao Marcos Costa</name>
<email>jmcosta944@gmail.com</email>
</author>
<published>2021-05-17T21:20:38Z</published>
<link rel='alternate' type='text/html' href='http://cgit.235523.xyz/u-boot.git/commit/?id=0008d8086649d3bb3afd0c4697f5b73ccf6f293d'/>
<id>urn:sha1:0008d8086649d3bb3afd0c4697f5b73ccf6f293d</id>
<content type='text'>
The fragmented files were not correctly read because of two issues:

- The squashfs_file_info struct has a field named 'comp', which tells if
the file's fragment is compressed or not. This field was always set to
'true' in sqfs_get_regfile_info and sqfs_get_lregfile_info. It should
actually take sqfs_frag_lookup's return value. This patch addresses
these two assignments.

- In sqfs_read, the fragments (compressed or not) were copied to the
output buffer through a for loop which was reading data at the wrong
offset. Replace these loops by equivalent calls to memcpy, with the
right parameters.

I tested this patch by comparing the MD5 checksum of a few fragmented
files with the respective md5sum output in sandbox, considering both
compressed and uncompressed fragments.

Signed-off-by: Joao Marcos Costa &lt;jmcosta944@gmail.com&gt;
Tested-by: Richard Genoud &lt;richard.genoud@posteo.net&gt;
Reviewed-by: Miquel Raynal &lt;miquel.raynal@bootlin.com&gt;
</content>
</entry>
<entry>
<title>fs/squashfs: zero out unused fields in fs_dirent</title>
<updated>2021-05-26T21:26:07Z</updated>
<author>
<name>Heinrich Schuchardt</name>
<email>xypron.glpk@gmx.de</email>
</author>
<published>2021-05-17T06:21:39Z</published>
<link rel='alternate' type='text/html' href='http://cgit.235523.xyz/u-boot.git/commit/?id=53ba2c21c2df142b37bb2f0d6850d79dcfd8976f'/>
<id>urn:sha1:53ba2c21c2df142b37bb2f0d6850d79dcfd8976f</id>
<content type='text'>
When reading directories the UEFI sub-system must supply file attributes
and timestamps. These fields will have to be added to struct fs_dirent.
SquashFS should not fill these fields with random data. Ensure that they
are zeroed out.

Signed-off-by: Heinrich Schuchardt &lt;xypron.glpk@gmx.de&gt;
Reviewed-by: Miquel Raynal &lt;miquel.raynal@bootlin.com&gt;
</content>
</entry>
</feed>
