mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Zhihao Cheng <chengzhihao1@huawei.com>
To: Ran Hongyun <ranhongyun1@huawei.com>, <phillip@squashfs.org.uk>
Cc: <linux-kernel@vger.kernel.org>, <yangerkun@huawei.com>,
	<yi.zhang@huawei.com>
Subject: Re: [PATCH v2] squashfs: Add dictionary size range check to prevent shift-out-of-bounds
Date: Thu, 16 Jul 2026 21:32:36 +0800	[thread overview]
Message-ID: <92aa853b-2b56-8716-2993-47daab4fdc6c@huawei.com> (raw)
In-Reply-To: <20260713115525.2661734-1-ranhongyun1@huawei.com>

在 2026/7/13 19:55, Ran Hongyun 写道:
> When an abnormal SquashFS image (COMP_OPTS flag is 1 but dictionary size
> is 0) is mounted, and performs shift operations using dictionarysize, the
> shift exponent is -1, causing a shift-out-of-bounds.
> 
> Detail as below:
> squashfs_comp_opts(msblk, buffer, length)
>    squashfs_xz_comp_opts()
>      if (comp_opts)
>        n = ffs(opts->dict_size) - 1;<----opts->dict_size=0, n=-1
>        if (opts->dict_size != (1 << n) && opts->dict_size !=
> 	  	(1 << n) + (1 << (n + 1))) <----shift-out-of-bounds
> 
> Fix it by adding a dictionary size range check before the shift operation.
> 
> Fixes: ff750311d30a ("Squashfs: add compression options support to xz decompressor")
> Signed-off-by: Ran Hongyun <ranhongyun1@huawei.com>
> ---
>   fs/squashfs/xz_wrapper.c | 6 +++---
>   1 file changed, 3 insertions(+), 3 deletions(-)

Reviewed-by: Zhihao Cheng <chengzhihao1@huawei.com>
> 
> diff --git a/fs/squashfs/xz_wrapper.c b/fs/squashfs/xz_wrapper.c
> index 6c49481a2f8c..7d54cd524d6d 100644
> --- a/fs/squashfs/xz_wrapper.c
> +++ b/fs/squashfs/xz_wrapper.c
> @@ -57,10 +57,10 @@ static void *squashfs_xz_comp_opts(struct squashfs_sb_info *msblk,
>   
>   		opts->dict_size = le32_to_cpu(comp_opts->dictionary_size);
>   
> -		/* the dictionary size should be 2^n or 2^n+2^(n+1) */
> +		/* the dictionary size should be positive and 2^n or 2^n+2^(n+1) */
>   		n = ffs(opts->dict_size) - 1;
> -		if (opts->dict_size != (1 << n) && opts->dict_size != (1 << n) +
> -						(1 << (n + 1))) {
> +		if (opts->dict_size <= 0 || (opts->dict_size != (1 << n) &&
> +			opts->dict_size != (1 << n) + (1 << (n + 1)))) {
>   			err = -EIO;
>   			goto out;
>   		}
> 


  reply	other threads:[~2026-07-16 13:32 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-13 11:55 Ran Hongyun
2026-07-16 13:32 ` Zhihao Cheng [this message]
2026-07-22  6:21 ` Phillip Lougher
2026-09-16  7:43   ` [PATCH 0/2] lockd: fix two bugs on nlmclnt_find_lockowner() failure path Ran Hongyun
2026-09-16  8:27 ` [PATCH v2] squashfs: Add dictionary size range check to prevent shift-out-of-bounds Christian Brauner
2026-09-16  8:38   ` Ran Hongyun

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=92aa853b-2b56-8716-2993-47daab4fdc6c@huawei.com \
    --to=chengzhihao1@huawei.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=phillip@squashfs.org.uk \
    --cc=ranhongyun1@huawei.com \
    --cc=yangerkun@huawei.com \
    --cc=yi.zhang@huawei.com \
    /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®