mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Guo Zihao <guozh23@xiaopeng.com>
To: Phillip Lougher <phillip@squashfs.org.uk>
Cc: linux-kernel@vger.kernel.org, stable@vger.kernel.org
Subject: [PATCH] squashfs: fix signed overflow in get_dir_index_using_name()
Date: Thu, 29 Oct 2026 15:25:33 +0800	[thread overview]
Message-ID: <20261029072533.4130922-1-guozh23@xiaopeng.com> (raw)

The index field of the squashfs_dir_index entries is a u32 taken
from the image and stored in the int length:

length = le32_to_cpu(index->index);

Both later uses of length do signed arithmetic that a crafted image
can overflow:

*next_offset = (length + *next_offset) % SQUASHFS_METADATA_SIZE;
return length + 3;

Keep length unsigned so the additions wrap instead of invoking
undefined behaviour.  The wrapped offset only degrades the lookup:
squashfs_read_metadata() already rejects offsets outside the
metadata block.

Fixes: c88da2c97936 ("Squashfs: directory lookup operations")
Cc: stable@vger.kernel.org
Signed-off-by: Guo Zihao <guozh23@xiaopeng.com>
---
UBSan replica of get_dir_index_using_name(): index = 0x7fffffff reports
"signed integer overflow: 2147483647 + 100 cannot be represented in type
'int'".  QEMU boot with patched and unpatched kernels: a normal image
mounts identically; a crafted image with index = 0x7fffffff returns EIO
from lookup on both kernels (no behavioural change, only the UB removed).

 fs/squashfs/namei.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/fs/squashfs/namei.c b/fs/squashfs/namei.c
index 65aae7e2a..ffc23eef8 100644
--- a/fs/squashfs/namei.c
+++ b/fs/squashfs/namei.c
@@ -65,7 +65,8 @@ static int get_dir_index_using_name(struct super_block *sb,
 			int index_offset, int i_count, const char *name)
 {
 	struct squashfs_sb_info *msblk = sb->s_fs_info;
-	int i, length = 0, err;
+	int i, err;
+	unsigned int length = 0;
 	unsigned int size;
 	struct squashfs_dir_index *index;
 
-- 
2.50.1


                 reply	other threads:[~2026-10-29  7:25 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20261029072533.4130922-1-guozh23@xiaopeng.com \
    --to=guozh23@xiaopeng.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=phillip@squashfs.org.uk \
    --cc=stable@vger.kernel.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

all inboxes | Powered by JetHome®