All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] fs/squashfs: fix NULL dereference on empty-directory lookup
@ 2026-10-29 15:39 Oscar Deschamps
  2026-10-30  9:25 ` Miquel Raynal
  0 siblings, 1 reply; 2+ messages in thread
From: Oscar Deschamps @ 2026-10-29 15:39 UTC (permalink / raw)
  To: joaomarcos.costa, richard.genoud
  Cc: miquel.raynal, trini, thomas.petazzoni, u-boot, Oscar Deschamps

The three directory-search loops in sqfs.c use the local `ret` to tell
whether the requested name was found. When the loop runs zero times
`ret` keeps the 0 left by the preceding sqfs_opendir_nest(),
so the "not found" check is skipped and the NULL dirs->entry
is dereferenced (dirs->entry->inode_offset). A crafted or corrupted image
can thus crash U-Boot (a NULL read) while resolving,
reading or sizing a path.

Treat a loop that produced no entry as "not found" in sqfs_search_dir(),
sqfs_read_nest() and sqfs_size_nest(). Found by fuzzing the SquashFS
parser.

Signed-off-by: Oscar Deschamps <odeschamps.mail@gmail.com>
---
 fs/squashfs/sqfs.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/fs/squashfs/sqfs.c b/fs/squashfs/sqfs.c
index 0ea6dcaba1a..c8d2ade83e4 100644
--- a/fs/squashfs/sqfs.c
+++ b/fs/squashfs/sqfs.c
@@ -581,7 +581,7 @@ static int sqfs_search_dir(struct squashfs_dir_stream *dirs, char **token_list,
 			dirs->entry = NULL;
 		}
 
-		if (ret) {
+		if (ret || !dirs->entry) {
 			printf("** Cannot find directory. **\n");
 			ret = -EINVAL;
 			goto out;
@@ -1501,7 +1501,7 @@ static int sqfs_read_nest(const char *filename, void *buf, loff_t offset,
 		dirs->entry = NULL;
 	}
 
-	if (ret) {
+	if (ret || !dirs->entry) {
 		printf("File not found.\n");
 		*actread = 0;
 		ret = -ENOENT;
@@ -1803,7 +1803,7 @@ static int sqfs_size_nest(const char *filename, loff_t *size)
 		dirs->entry = NULL;
 	}
 
-	if (ret) {
+	if (ret || !dirs->entry) {
 		printf("File not found.\n");
 		*size = 0;
 		ret = -EINVAL;
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] fs/squashfs: fix NULL dereference on empty-directory lookup
  2026-10-29 15:39 [PATCH] fs/squashfs: fix NULL dereference on empty-directory lookup Oscar Deschamps
@ 2026-10-30  9:25 ` Miquel Raynal
  0 siblings, 0 replies; 2+ messages in thread
From: Miquel Raynal @ 2026-10-30  9:25 UTC (permalink / raw)
  To: Oscar Deschamps
  Cc: joaomarcos.costa, richard.genoud, trini, thomas.petazzoni, u-boot

On 29/10/2026 at 16:39:40 +01, Oscar Deschamps <odeschamps.mail@gmail.com> wrote:

> The three directory-search loops in sqfs.c use the local `ret` to tell
> whether the requested name was found. When the loop runs zero times
> `ret` keeps the 0 left by the preceding sqfs_opendir_nest(),
> so the "not found" check is skipped and the NULL dirs->entry
> is dereferenced (dirs->entry->inode_offset). A crafted or corrupted image
> can thus crash U-Boot (a NULL read) while resolving,
> reading or sizing a path.
>
> Treat a loop that produced no entry as "not found" in sqfs_search_dir(),
> sqfs_read_nest() and sqfs_size_nest(). Found by fuzzing the SquashFS
> parser.
>
> Signed-off-by: Oscar Deschamps <odeschamps.mail@gmail.com>

Reviewed-by: Miquel Raynal <miquel.raynal@bootlin.com>

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-10-30 13:00 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-10-29 15:39 [PATCH] fs/squashfs: fix NULL dereference on empty-directory lookup Oscar Deschamps
2026-10-30  9:25 ` 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.