summaryrefslogtreecommitdiffstats
path: root/fs/squashfs
Commit message (Collapse)AuthorAgeFilesLines
* fs/squashfs: fix reading of fragmented filesJoao Marcos Costa2021-06-091-10/+6
| | | | | | | | | | | | | | | | | | | | | | | 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 <jmcosta944@gmail.com> Tested-by: Richard Genoud <richard.genoud@posteo.net> Reviewed-by: Miquel Raynal <miquel.raynal@bootlin.com>
* fs/squashfs: zero out unused fields in fs_direntHeinrich Schuchardt2021-05-261-1/+1
| | | | | | | | | | 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 <xypron.glpk@gmx.de> Reviewed-by: Miquel Raynal <miquel.raynal@bootlin.com>
* fs/squashfs: Fix compilation errorPali Rohár2021-03-041-0/+1
| | | | | | | | | | | | | | | Commit 401d1c4f5d2d29c4bc4beaec95402ca23eb63295 ("common: Drop asm/global_data.h from common header") broke compilation of squashfs filesystem when CONFIG_CMD_SQUASHFS=y is enabled. Compilation is failing on error: aarch64-linux-gnu-ld.bfd: u-boot/fs/squashfs/sqfs_inode.c:121: undefined reference to `le32_to_cpu' Fixes: 401d1c4f5d2d29c4bc4beaec95402ca23eb63295 ("common: Drop asm/global_data.h from common header") Suggested-by: Tom Rini <trini@konsulko.com> Signed-off-by: Pali Rohár <pali@kernel.org> Reviewed-by: Tom Rini <trini@konsulko.com>
* fs/squashfs: NULL dereference in sqfs_closedir()Heinrich Schuchardt2021-02-241-0/+3
| | | | | | | sqfs_opendir() called in sqfs_size(), sqfs_read(), sqfs_exists() may fail leading to sqfs_closedir(NULL) being called. Do not dereference NULL. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
* Fix squashfs failing to load sparse filesCampbell Suter2021-01-201-19/+35
| | | | | | | | | | | | | | | | | SquashFS supports sprase blocks in files - that is, if a given block is composed only of zeros, it's not written to the output file to save space and it's on-disk length field is set to zero to indicate that. Previously the squashfs driver did not recognise that, and would attempt to read and decompress a zero-sized block, which obviously failed. The following command may be used to create a file for testing: cat <(dd if=/dev/urandom of=/dev/stdout bs=1M count=1) \ <(dd if=/dev/zero of=/dev/stdout bs=1M count=1) \ <(dd if=/dev/urandom of=/dev/stdout bs=1k count=200) >test_file Signed-off-by: Campbell Suter <campbell@snapit.group>
* fs/squashfs: sqfs_close/sqfs_read_sblk: set ctxt.sblk to NULL after freeRichard Genoud2020-12-021-1/+3
| | | | | | This will prevent a double free error if sqfs_close() is called twice. Signed-off-by: Richard Genoud <richard.genoud@posteo.net>
* fs/squashfs: implement exists() functionRichard Genoud2020-11-191-0/+38
| | | | | | | This permits to find a file and use the distro_bootcmd Reviewed-by: Joao Marcos Costa <jmcosta944@gmail.com> Signed-off-by: Richard Genoud <richard.genoud@posteo.net>
* fs/squashfs: sqfs_read: remove buggy offset functionalityRichard Genoud2020-11-191-4/+12
| | | | | | | | | offset is the offset in the file read, not the offset in the destination buffer. If the offset is not null, this will lead to a memory corruption. So, for now, we are returning an error if the offset is used. Signed-off-by: Richard Genoud <richard.genoud@posteo.net>
* fs/squashfs: sqfs_read: don't write beyond buffer sizeRichard Genoud2020-11-191-0/+8
| | | | | | | The length of the buffer wasn't taken into account when writing to the given buffer. Signed-off-by: Richard Genoud <richard.genoud@posteo.net>
* fs/squashfs: sqfs_probe: use sqfs_decompressor_init() return valueRichard Genoud2020-11-191-2/+0
| | | | | | | | sqfs_decompressor_init() returns a value, so it's better to use it than to force the return value to EINVAL (it could be ENOMEM) Reviewed-by: Joao Marcos Costa <jmcosta944@gmail.com> Signed-off-by: Richard Genoud <richard.genoud@posteo.net>
* fs/squashfs: sqfs_probe: reset cur_dev/cur_part_info to NULL on errorRichard Genoud2020-11-191-1/+1
| | | | | | | | Resetting the context on error will prevent some checks like: if (!ctx.cur_dev) To pass when the probe method has failed Signed-off-by: Richard Genoud <richard.genoud@posteo.net>
* fs/squashfs: sqfs_probe: fix possible memory leak on errorRichard Genoud2020-11-191-5/+9
| | | | | | | If SquashFS magic number is invalid, there's a memory leak. Reviewed-by: Joao Marcos Costa <jmcosta944@gmail.com> Signed-off-by: Richard Genoud <richard.genoud@posteo.net>
* fs/squashfs: sqfs_read: fix memory leak on finfo.blk_sizesRichard Genoud2020-11-191-26/+22
| | | | | | | | | finfo.blk_sizes may not be freed in case of error in the for loop Setting it to null and freeing it at the end makes prevents that from happening. Reviewed-by: Joao Marcos Costa <jmcosta944@gmail.com> Signed-off-by: Richard Genoud <richard.genoud@posteo.net>
* fs/squashfs: sqfs_get_abs_path: fix possible memory leak on errorRichard Genoud2020-11-191-14/+18
| | | | | | | | if sqfs_tokenize(rel_tokens, rc, rel); fails, the function exits without freeing the array base_tokens. Reviewed-by: Joao Marcos Costa <jmcosta944@gmail.com> Signed-off-by: Richard Genoud <richard.genoud@posteo.net>
* fs/squashfs: sqfs_get_abs_path: fix error checkRichard Genoud2020-11-191-1/+1
| | | | | | | | | the return value of sqfs_tokenize(rel_tokens, rc, rel); wasn't checked. (but "ret" value was !) This is obviouly a typo. Reviewed-by: Joao Marcos Costa <jmcosta944@gmail.com> Signed-off-by: Richard Genoud <richard.genoud@posteo.net>
* fs/squashfs: sqfs_frag_lookup: simplify error handlingRichard Genoud2020-11-191-12/+16
| | | | | | | For consistency with other functions. Reviewed-by: Joao Marcos Costa <jmcosta944@gmail.com> Signed-off-by: Richard Genoud <richard.genoud@posteo.net>
* fs/squashfs: sqfs_read: fix another memory leakRichard Genoud2020-11-191-0/+2
| | | | | | data_buffer was allocated in a loop and freed only once. Signed-off-by: Richard Genoud <richard.genoud@posteo.net>
* fs/squashfs: sqfs_read: fix memory leakRichard Genoud2020-11-191-1/+1
| | | | | | | | sqfs_closedir() should be called to free memory allocated by sqfs_opendir() Reviewed-by: Joao Marcos Costa <jmcosta944@gmail.com> Signed-off-by: Richard Genoud <richard.genoud@posteo.net>
* fs/squashfs: sqfs_read: remove useless sqfs_closedir()Richard Genoud2020-11-191-1/+0
| | | | | | as sqfs_opendir failed, there's no need to call sqfs_closedir Signed-off-by: Richard Genoud <richard.genoud@posteo.net>
* fs/squashfs: sqfs_read: fix dangling pointer dirs->entryRichard Genoud2020-11-191-0/+1
| | | | | | dirs->entry shouldn't be left dangling as it could be freed twice. Signed-off-by: Richard Genoud <richard.genoud@posteo.net>
* fs/squashfs: sqfs_size: remove useless sqfs_closedir()Richard Genoud2020-11-191-1/+0
| | | | | | as sqfs_opendir failed, there's no need to call sqfs_closedir Signed-off-by: Richard Genoud <richard.genoud@posteo.net>
* fs/squashfs: sqfs_size: fix dangling pointer dirs->entryRichard Genoud2020-11-191-0/+2
| | | | | | dirs->entry shouldn't be left dangling as it could be freed twice. Signed-off-by: Richard Genoud <richard.genoud@posteo.net>
* fs/squashfs: sqfs_concat_tokens: check if malloc succeedsRichard Genoud2020-11-191-0/+3
| | | | | | | memory allocation should always be checked Reviewed-by: Joao Marcos Costa <jmcosta944@gmail.com> Signed-off-by: Richard Genoud <richard.genoud@posteo.net>
* fs/squashfs: sqfs_read_inode_table: fix dangling pointerRichard Genoud2020-11-191-0/+1
| | | | | | inode_table should not be left dangling as it may be freed in sqfs_opendir Signed-off-by: Richard Genoud <richard.genoud@posteo.net>
* fs/squashfs: sqfs_search_dir: fix memory leaksRichard Genoud2020-11-191-13/+51
| | | | | | | path, target, res, rem and sym_tokens were not free on error nor success. Reviewed-by: Joao Marcos Costa <jmcosta944@gmail.com> Signed-off-by: Richard Genoud <richard.genoud@posteo.net>
* fs/squashfs: sqfs_search_dir: fix dangling pointerRichard Genoud2020-11-191-0/+5
| | | | | | dirs->entry shouldn't be left dangling as it could be freed twice. Signed-off-by: Richard Genoud <richard.genoud@posteo.net>
* fs/squashfs: sqfs_read_directory_table: fix memory leakRichard Genoud2020-11-191-14/+17
| | | | | | | pos_list wasn't freed on every error Reviewed-by: Joao Marcos Costa <jmcosta944@gmail.com> Signed-off-by: Richard Genoud <richard.genoud@posteo.net>
* fs/squashfs: sqfs_split_path: fix memory leak and dangling pointersRichard Genoud2020-11-191-12/+28
| | | | | | | *file and *dir were not freed on error Reviewed-by: Joao Marcos Costa <jmcosta944@gmail.com> Signed-off-by: Richard Genoud <richard.genoud@posteo.net>
* fs/squashfs: sqfs_closedir: fix memory leakRichard Genoud2020-11-191-0/+1
| | | | | | | sqfs_dirs wasn't freed anywhere. Reviewed-by: Joao Marcos Costa <jmcosta944@gmail.com> Signed-off-by: Richard Genoud <richard.genoud@posteo.net>
* fs/squashfs: sqfs_opendir: simplify error handlingRichard Genoud2020-11-191-15/+12
| | | | | | | Using only one label permits to prevents bugs when moving code around. Reviewed-by: Joao Marcos Costa <jmcosta944@gmail.com> Signed-off-by: Richard Genoud <richard.genoud@posteo.net>
* fs/squashfs: sqfs_opendir: fix some memory leaks and dangling pointersRichard Genoud2020-11-191-8/+29
| | | | | | When trying to load an non-existing file, the cpu hangs! Signed-off-by: Richard Genoud <richard.genoud@posteo.net>
* fs/squashfs: Fix index off by 1 for inode SQFS_LDIR_TYPEGerard Koskamp2020-11-191-2/+2
| | | | | | | | | | | | | | I've created a squashfs file system with Yocto (it use squashfs-tools) and u-boot command sqfsls give the error:'Error while searching inode: unknown type.' After some digging in the code I found that the index is off by 1. This patch fix this issue and I can successful use the sqfsls command. After search for the squashfs format I found a link talk about a similar issue but this time in the documentation. The link is: https://github.com/AgentD/squashfs-tools-ng/commit/e6588526838caece9529 Signed-off-by: Gerard Koskamp <gerard.koskamp@nedap.com> Tested-by: Joao Marcos Costa <joaomarcos.costa@bootlin.com>
* fs/squashfs: parameter check sqfs_read_metablock()Heinrich Schuchardt2020-09-291-2/+2
| | | | | | | | | We should check if the incoming parameter file_mapping is not NULL instead of checking after adding an offset. Reported-by: Coverity CID 307210 Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de> Acked-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
* fs/squashfs: Fix Coverity Scan defectsJoao Marcos Costa2020-09-183-10/+18
| | | | | | Fix control flow issues and null pointer dereferences. Signed-off-by: Joao Marcos Costa <jmcosta944@gmail.com>
* fs/squashfs: Fix Coverity Scan defectsJoao Marcos Costa2020-08-243-12/+36
| | | | | | | | | Fix defects such as uninitialized variables and untrusted pointer operations. Most part of the tainted variables and the related defects actually comes from Linux's macro get_unaligned_le**, extensively used in SquashFS code. Add sanity checks for those variables. Signed-off-by: Joao Marcos Costa <joaomarcos.costa@bootlin.com>
* fs/squashfs: add support for LZO decompressionJoao Marcos Costa2020-08-241-0/+25
| | | | | | | | | | Add call to lzo's lzo1x_decompress_safe() into sqfs_decompress(). U-Boot's LZO sources may still have some unsolved issues that could make the decompression crash when dealing with fragmented files, so those should be avoided. The "-no-fragments" option can be passed to mksquashfs. Signed-off-by: Joao Marcos Costa <joaomarcos.costa@bootlin.com>
* fs/squashfs: add support for ZSTD decompressionJoao Marcos Costa2020-08-242-0/+45
| | | | | | | | | Add call to ZSTD's ZSTD_decompressDCtx(). In this use case, the caller can upper bound the decompressed size, which will be the SquashFS data block (or metadata block) size, so there is no need to use streaming API. Add ZSTD's worskpace to squashfs_ctxt structure. Signed-off-by: Joao Marcos Costa <joaomarcos.costa@bootlin.com>
* fs/squashfs: replace sqfs_decompress() parameterJoao Marcos Costa2020-08-243-20/+14
| | | | | | Replace 'u16 comp_type' by a reference to squashfs_ctxt structure. Signed-off-by: Joao Marcos Costa <joaomarcos.costa@bootlin.com>
* fs/squashfs: Add init and clean-up functions to decompressionJoao Marcos Costa2020-08-244-10/+51
| | | | | | | | | | | | | Add sqfs_decompressor_init() and sqfs_decompressor_cleanup(). These functions are called respectively in sqfs_probe() and sqfs_close(). For now, only ZSTD requires an initialization logic. ZSTD support will be added in a follow-up commit. Move squashfs_ctxt definition to sqfs_filesystem.h. This structure is passed to sqfs_decompressor_init() and sqfs_decompressor_cleanup(), so it can no longer be local to sqfs.c. Signed-off-by: Joao Marcos Costa <joaomarcos.costa@bootlin.com>
* fs/squashfs: add support for zlib decompressionJoao Marcos Costa2020-08-071-0/+30
| | | | | | | Add call to zlib's 'uncompress' function. Add function to display the right error message depending on the decompression's return value. Signed-off-by: Joao Marcos Costa <joaomarcos.costa@bootlin.com>
* include/u-boot, lib/zlib: add sources for zlib decompressionJoao Marcos Costa2020-08-071-0/+1
| | | | | | | | | Add zlib (v1.2.11) uncompr() function to U-Boot. SquashFS depends on this function to decompress data from a raw disk image. The actual support for zlib into SquashFS sources will be added in a follow-up commit. Signed-off-by: Joao Marcos Costa <joaomarcos.costa@bootlin.com>
* fs/squashfs: new filesystemJoao Marcos Costa2020-08-079-0/+2237
Add support for SquashFS filesystem. Right now, it does not support compression but support for zlib will be added in a follow-up commit. Signed-off-by: Joao Marcos Costa <joaomarcos.costa@bootlin.com>