linux/fs/squashfs
Ran Hongyun 1f7745fb35
squashfs: Add dictionary size range check to prevent shift-out-of-bounds
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: ff750311d3 ("Squashfs: add compression options support to xz decompressor")
Signed-off-by: Ran Hongyun <ranhongyun1@huawei.com>
Link: https://patch.msgid.link/20260713115525.2661734-1-ranhongyun1@huawei.com
Reviewed-by: Phillip Lougher <phillip@squashfs.org.uk>
Reviewed-by: Zhihao Cheng <chengzhihao1@huawei.com>
Signed-off-by: Christian Brauner (Amutable) <brauner@kernel.org>
2026-09-16 10:26:47 +02:00
..
block.c treewide: Replace kmalloc with kmalloc_obj for non-scalar types 2026-02-21 01:02:28 -08:00
cache.c squashfs: avoid thundering-herd cache wakeups 2026-08-19 19:55:06 -07:00
decompressor_multi_percpu.c squashfs: fix percpu address space issues in decompressor_multi_percpu.c 2024-09-09 16:47:41 -07:00
decompressor_multi.c Convert 'alloc_obj' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00
decompressor_single.c Convert 'alloc_obj' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00
decompressor.c
decompressor.h
dir.c squashfs: add setlease file operation 2026-01-12 10:55:47 +01:00
export.c exportfs: make ->encode_fh() a mandatory method for NFS export 2023-10-28 16:15:15 +02:00
file_cache.c squashfs; convert squashfs_copy_cache() to take a folio 2025-01-24 22:47:22 -08:00
file_direct.c squashfs: convert squashfs_readpage_block() to take a folio 2025-01-24 22:47:22 -08:00
file.c Convert remaining multi-line kmalloc_obj/flex GFP_KERNEL uses 2026-02-22 08:26:33 -08:00
fragment.c
id.c
inode.c Coccinelle-based conversion to use ->i_state accessors 2025-10-20 20:22:26 +02:00
Kconfig squashfs: add optional full compressed block caching 2025-05-27 19:40:33 -07:00
lz4_wrapper.c Convert 'alloc_obj' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00
lzo_wrapper.c Convert 'alloc_obj' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00
Makefile
namei.c Squashfs: remove deprecated strncpy by not copying the string 2024-04-25 21:07:05 -07:00
page_actor.c Convert 'alloc_obj' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00
page_actor.h Squashfs: Ensure all readahead pages have been used 2024-08-23 13:11:36 +02:00
squashfs_fs_i.h Squashfs: fix uninit-value in squashfs_get_parent 2025-09-28 11:36:12 -07:00
squashfs_fs_sb.h squashfs: avoid thundering-herd cache wakeups 2026-08-19 19:55:06 -07:00
squashfs_fs.h Squashfs: add SEEK_DATA/SEEK_HOLE support 2025-09-28 11:36:14 -07:00
squashfs.h Squashfs: add SEEK_DATA/SEEK_HOLE support 2025-09-28 11:36:14 -07:00
super.c Convert 'alloc_obj' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00
symlink.c squashfs: convert squashfs_symlink_read_folio to use folio APIs 2024-05-08 08:41:28 -07:00
xattr_id.c
xattr.c squashfs: move squashfs_xattr_handlers to .rodata 2023-10-10 13:49:20 +02:00
xattr.h
xz_wrapper.c squashfs: Add dictionary size range check to prevent shift-out-of-bounds 2026-09-16 10:26:47 +02:00
zlib_wrapper.c Convert 'alloc_obj' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00
zstd_wrapper.c Convert 'alloc_obj' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00