From nobody Sat Jul 25 21:23:04 2026 Received: from canpmsgout04.his.huawei.com (canpmsgout04.his.huawei.com [113.46.200.219]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BBE1F381EBE for ; Mon, 13 Jul 2026 12:03:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=113.46.200.219 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783944231; cv=none; b=aOaZ+FfeJz2ba+fcZ9SViZCDiwNi4p4yqgtYjaSN8X//nRuSlokpKMo2iz2DB168LRob9fiBHiQa2OImsaIunaZKTO0wonTFHSutQVlbswi9Bu/v8GqpaGZWGOLpthzCjGTo8OGDIuMXK4F3bPHTc12gzbnq/6XSwfXOnKtE4dA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783944231; c=relaxed/simple; bh=XpHd5qCVRYZ+KBQ9iVVoF58AqK2I4uJjQ6aE7q3koUs=; h=From:To:CC:Subject:Date:Message-ID:MIME-Version:Content-Type; b=RS9QuDUVRUVXK3a8Pj6wvTvBAOPkFBpvXjjKI4C2TBJfqHO6oL2HCSXev8wd5BH4iTFUqsg8IgC5Mb2l5JnSgiYXB6ZQjxvG/dh2qvzdhDU/fsDykMofqaxbleIbdkZj1cefGhYmkhwA/1XDkHSdAuOtzrXqMwsd0sIeeWQrqVw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; dkim=pass (1024-bit key) header.d=huawei.com header.i=@huawei.com header.b=IExODWr7; arc=none smtp.client-ip=113.46.200.219 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=huawei.com header.i=@huawei.com header.b="IExODWr7" dkim-signature: v=1; a=rsa-sha256; d=huawei.com; s=dkim; c=relaxed/relaxed; q=dns/txt; h=From; bh=bvXwlpugpu8cijzg+GP++aQ1DKKzmSIl+KL3kKv0Cog=; b=IExODWr7WYInceL7+9fSNs4ftkBZB2tbBKhGiM1+UpEJJGFpb4nXqdLSIkyFlxaRRmgivzqeZ LrcOhYPQISPOuzIX6NalbzYAqXLNpQygOuk7WY9sP7oaA14rFoUJI9lUxI8BjCSPgNqyyGmjPSS 3wpy4smk20/mDzjnhs/d8Gw= Received: from mail.maildlp.com (unknown [172.19.162.140]) by canpmsgout04.his.huawei.com (SkyGuard) with ESMTPS id 4gzLSq2vQtz1prL6; Mon, 13 Jul 2026 19:54:19 +0800 (CST) Received: from dggpemr200001.china.huawei.com (unknown [7.185.36.96]) by mail.maildlp.com (Postfix) with ESMTPS id 9A8C52025F; Mon, 13 Jul 2026 20:03:38 +0800 (CST) Received: from huawei.com (10.50.85.155) by dggpemr200001.china.huawei.com (7.185.36.96) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Mon, 13 Jul 2026 20:03:38 +0800 From: Ran Hongyun To: CC: , , , Subject: [PATCH v2] squashfs: Add dictionary size range check to prevent shift-out-of-bounds Date: Mon, 13 Jul 2026 19:55:25 +0800 Message-ID: <20260713115525.2661734-1-ranhongyun1@huawei.com> X-Mailer: git-send-email 2.52.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: kwepems100001.china.huawei.com (7.221.188.238) To dggpemr200001.china.huawei.com (7.185.36.96) Content-Type: text/plain; charset="utf-8" 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 =3D ffs(opts->dict_size) - 1;<----opts->dict_size=3D0, n=3D-1 if (opts->dict_size !=3D (1 << n) && opts->dict_size !=3D (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 decom= pressor") Signed-off-by: Ran Hongyun Reviewed-by: Phillip Lougher Reviewed-by: Zhihao Cheng --- fs/squashfs/xz_wrapper.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) 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_i= nfo *msblk, =20 opts->dict_size =3D le32_to_cpu(comp_opts->dictionary_size); =20 - /* 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 =3D ffs(opts->dict_size) - 1; - if (opts->dict_size !=3D (1 << n) && opts->dict_size !=3D (1 << n) + - (1 << (n + 1))) { + if (opts->dict_size <=3D 0 || (opts->dict_size !=3D (1 << n) && + opts->dict_size !=3D (1 << n) + (1 << (n + 1)))) { err =3D -EIO; goto out; } --=20 2.52.0