fs/squashfs: fix NULL dereference on failed symlink resolution
PATCH 1/1 fs/squashfs: fix NULL dereference on failed symlink resolution
sqfs_resolve_symlink() can return NULL, on its symlink_size overflow guard or on an allocation failure. sqfs_read_nest() and sqfs_size_nest() use the result without checking it, unlike sqfs_search_dir(), and the NULL reaches sqfs_split_path() which dereferences path[0]. A crafted or corrupted image can thus crash U-Boot (a NULL read) while reading or sizing a file through a symlink.
Check the result in both callers and guard sqfs_split_path() against a NULL path. Found by fuzzing the SquashFS parser.
--- fs/squashfs/sqfs.c | 12 ++++++++++++ 1 file changed, 12 insertions(+)
fs/squashfs/sqfs.c +12 -0
@@ -1295,6 +1295,10 @@ static int sqfs_split_path(char **file, char **dir, const char *path) *file =NULL ; *dir =NULL ; + +if (!path) +return -EINVAL ; + dirc =NULL ; basec =NULL ; bname =NULL ;
@@ -1561,6 +1565,10 @@ static int sqfs_read_nest(const char *filename, void *buf, loff_t offset, dirs->entry =NULL ;sqfs_closedir (dirsp); dirsp =NULL ; +if (!resolved) { + ret = -EINVAL ; + goto out; + } ret =sqfs_read_nest (resolved, buf, offset, len, actread);free (resolved); goto out;
@@ -1848,6 +1856,10 @@ static int sqfs_size_nest(const char *filename, loff_t *size)*/ sqfs_closedir (dirsp); dirsp =NULL ; +if (!resolved) { + ret = -EINVAL ; +break ; + } ret =sqfs_size (resolved, size);free (resolved);break ;
Signature · 1 line
2.43.0
Hi Oscar,
Quoted 11 lines · Oscar Deschamps
sqfs_resolve_symlink()can return NULL, on itssymlink_sizeoverflow guard or on an allocation failure.sqfs_read_nest()andsqfs_size_nest()use the result without checking it, unlikesqfs_search_dir(), and the NULL reachessqfs_split_path()which dereferences path[0]. A crafted or corrupted image can thus crash U-Boot (a NULL read) while reading or sizing a file through a symlink.Check the result in both callers and guard
sqfs_split_path()against a NULL path. Found by fuzzing the SquashFS parser.Signed-off-by Oscar Deschamps <[email protected]>
Thanks for the patch!
Miquèl
Quoted 8 lines · Oscar Deschamps
sqfs_resolve_symlink()can return NULL, on itssymlink_sizeoverflow guard or on an allocation failure.sqfs_read_nest()andsqfs_size_nest()use the result without checking it, unlikesqfs_search_dir(), and the NULL reachessqfs_split_path()which dereferences path[0]. A crafted or corrupted image can thus crash U-Boot (a NULL read) while reading or sizing a file through a symlink.[...]
Applied to u-boot/main, thanks!
[1/1] fs/squashfs: fix NULL dereference on failed symlink resolution
commit: 351e0e1e4c8dee49e24868a2e7bb624d5f8bf0fe
Signature · 1 line
Tom