U-Boot Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Oscar Deschamps <odeschamps.mail@gmail.com>
To: joaomarcos.costa@bootlin.com, richard.genoud@bootlin.com
Cc: miquel.raynal@bootlin.com, trini@konsulko.com,
	thomas.petazzoni@bootlin.com, u-boot@lists.u-boot-project.org,
	Oscar Deschamps <odeschamps.mail@gmail.com>
Subject: [PATCH] fs/squashfs: fix NULL dereference on empty-directory lookup
Date: Thu, 29 Oct 2026 16:39:40 +0100	[thread overview]
Message-ID: <20261029153940.461197-1-odeschamps.mail@gmail.com> (raw)

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


             reply	other threads:[~2026-10-29 16:32 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-29 15:39 Oscar Deschamps [this message]
2026-10-30  9:25 ` [PATCH] fs/squashfs: fix NULL dereference on empty-directory lookup Miquel Raynal

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261029153940.461197-1-odeschamps.mail@gmail.com \
    --to=odeschamps.mail@gmail.com \
    --cc=joaomarcos.costa@bootlin.com \
    --cc=miquel.raynal@bootlin.com \
    --cc=richard.genoud@bootlin.com \
    --cc=thomas.petazzoni@bootlin.com \
    --cc=trini@konsulko.com \
    --cc=u-boot@lists.u-boot-project.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox