Skip to content

squashfs: harden fragment index table sizing

Karl Mehltretter linux-fsdevel lkml stable 1 version In review

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 Latest2 patches 3 repliesIn review

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/2squashfs: fix fragment index table sizing overflow on 32-bitfs/squashfs/squashfs_fs.h+1 -10 replies
2/2squashfs: make the fragment index table bounds check overflow-safefs/squashfs/fragment.c+4 -20 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v1 yet.

Read the v1 thread

Cover letter [PATCH 0/2] squashfs: harden fragment index table sizing

Two integer overflows undermine fragment index table handling. One is in the original fragment sizing macros. The other is in a bounds check added by commit 1cac63cc9b2f ("Squashfs: add sanity checks to fragment reading at mount time").

Patch 1: the fragment byte count wraps on 32-bit, so the index table is allocated too small and squashfs_frag_lookup() reads out of bounds. A crafted image triggers a KASAN out-of-bounds read on a 32-bit build. With the fix the same image fails cleanly at mount.

Patch 2: the check that the table fits before the next one adds two u64 values controlled by the filesystem image and can wrap.

Built W=1 with gcc (x86_64, i386) and clang (x86_64). Strict checkpatch is clean.

Karl Mehltretter (2):
squashfs: fix fragment index table sizing overflow on 32-bit
squashfs: make the fragment index table bounds check overflow-safe

 fs/squashfs/fragment.c    | 6 ++++--
 fs/squashfs/squashfs_fs.h | 2 +-
 2 files changed, 5 insertions(+), 3 deletions(-)
Signature · 1 line
2.53.0