From nobody Sat Jul 25 21:59:22 2026 Received: from canpmsgout07.his.huawei.com (canpmsgout07.his.huawei.com [113.46.200.222]) (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 72C42369D55 for ; Mon, 13 Jul 2026 07:26:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=113.46.200.222 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783927585; cv=none; b=AGswdPeXo+38CmUHo4vR/khxhzYkLOma+IiRAxc4nqUT016LjBXdJV7ShLgZWh928VM5dHXPOQbIsF/qpE5EM6wi5UAAZdX3nRbcBnyrKlG09mujtzGJ6IPWxvqLKBDmPqcuRrj78WXvQllq42O1hj8e2vzlWlo9Y3hAF2cXSHA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783927585; c=relaxed/simple; bh=9Yg+7PutHpMXu6F5ojkoIX5NYfCjuQr5q+qoHGbzNUE=; h=From:To:CC:Subject:Date:Message-ID:MIME-Version:Content-Type; b=TLuH0l+kKDzgjaY8AiMZ+iMgKShPpnLNFPyzxCt6NlXUCZ5eTsj500ZCFba1CNk9cyQGQPGhzKNUKmgOFIDCXNsrDCl0ob69b8fMaLaJ0XW7QtGorpyg8XC+zYDTFPk8O3bsV1kMAJSx6Cz+u7eWbqAepVSMmf7anPduU6ogJyg= 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=G36H8zGk; arc=none smtp.client-ip=113.46.200.222 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="G36H8zGk" dkim-signature: v=1; a=rsa-sha256; d=huawei.com; s=dkim; c=relaxed/relaxed; q=dns/txt; h=From; bh=uHhzPc51HqV/VWCcpK9VYfCwEtAGgT+9mbXVk57mryg=; b=G36H8zGkGi3fKmbL+TPUCl70+KlpDND9pltAAY1zsQQT3Z26gZA9JTztLpBgaoG/B1jRajL5S MJz3XvZT0CGcOuPZY0cXCcJ9jafCscMAvqOromNn32twzzELt1ZuFbuK4E34rNM3Xyg/xIuel2l h43S3ID7J1HD0xGI7dD48I8= Received: from mail.maildlp.com (unknown [172.19.163.15]) by canpmsgout07.his.huawei.com (SkyGuard) with ESMTPS id 4gzDJs5DjxzLlTg; Mon, 13 Jul 2026 15:17:01 +0800 (CST) Received: from dggpemr200001.china.huawei.com (unknown [7.185.36.96]) by mail.maildlp.com (Postfix) with ESMTPS id C936940578; Mon, 13 Jul 2026 15:26:18 +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 15:26:18 +0800 From: Ran Hongyun To: CC: , , , Subject: [PATCH] squashfs: Add dictionary size range check to prevent shift-out-of-bounds Date: Mon, 13 Jul 2026 15:18:06 +0800 Message-ID: <20260713071806.1690038-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: kwepems200001.china.huawei.com (7.221.188.67) 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 shi= ft 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. --- fs/squashfs/xz_wrapper.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fs/squashfs/xz_wrapper.c b/fs/squashfs/xz_wrapper.c index 6c49481a2f8c..91d832c4259e 100644 --- a/fs/squashfs/xz_wrapper.c +++ b/fs/squashfs/xz_wrapper.c @@ -57,9 +57,9 @@ static void *squashfs_xz_comp_opts(struct squashfs_sb_inf= o *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) + + if (opt->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