* [PATCH] fs/squashfs: fix NULL dereference on failed symlink resolution
@ 2026-10-28 13:44 Oscar Deschamps
2026-10-28 14:27 ` Miquel Raynal
0 siblings, 1 reply; 2+ messages in thread
From: Oscar Deschamps @ 2026-10-28 13:44 UTC (permalink / raw)
To: Joao Marcos Costa, Richard Genoud
Cc: Thomas Petazzoni, Miquel Raynal, Allan ELKAIM, Tom Rini, u-boot,
Oscar Deschamps
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.
Signed-off-by: Oscar Deschamps <odeschamps.mail@gmail.com>
---
fs/squashfs/sqfs.c | 12 ++++++++++++
1 file changed, 12 insertions(+)
diff --git a/fs/squashfs/sqfs.c b/fs/squashfs/sqfs.c
index 0ea6dcaba1a..28d6e64e79c 100644
--- a/fs/squashfs/sqfs.c
+++ b/fs/squashfs/sqfs.c
@@ -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;
--
2.43.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] fs/squashfs: fix NULL dereference on failed symlink resolution
2026-10-28 13:44 [PATCH] fs/squashfs: fix NULL dereference on failed symlink resolution Oscar Deschamps
@ 2026-10-28 14:27 ` Miquel Raynal
0 siblings, 0 replies; 2+ messages in thread
From: Miquel Raynal @ 2026-10-28 14:27 UTC (permalink / raw)
To: Oscar Deschamps
Cc: Joao Marcos Costa, Richard Genoud, Thomas Petazzoni, Allan ELKAIM,
Tom Rini, u-boot
Hi Oscar,
On 28/10/2026 at 14:44:27 +01, Oscar Deschamps <odeschamps.mail@gmail.com> wrote:
> 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.
>
> Signed-off-by: Oscar Deschamps <odeschamps.mail@gmail.com>
Thanks for the patch!
Reviewed-by: Miquel Raynal <miquel.raynal@bootlin.com>
Miquèl
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-10-28 14:50 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-10-28 13:44 [PATCH] fs/squashfs: fix NULL dereference on failed symlink resolution Oscar Deschamps
2026-10-28 14:27 ` Miquel Raynal
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.