mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH 0/6] hfs/hfsplus: fix endless loop on mount of crafted images
@ 2026-12-05  1:31 Viacheslav Dubeyko
  2026-12-05  1:31 ` [PATCH 1/6] hfsplus: look for the volume header in the order of the on-disk layout Viacheslav Dubeyko
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: Viacheslav Dubeyko @ 2026-12-05  1:31 UTC (permalink / raw)
  To: glaubitz, frank.li
  Cc: linux-fsdevel, linux-kernel, vdubeyko, Viacheslav Dubeyko

Both drivers look for the volume header (HFS+) or MDB (HFS) by
rereading at part_start until they find the signature. An HFS wrapper
or an Apple partition map moves part_start by values from disk
without any check. If such a value is zero, part_start does not move,
the same wrapper or partition map is found again, and the mount loops
forever. The mount(2) caller cannot be killed.

The HFS+ wrapper case was reported with drAlBlSt = 0 and the embedded
extent start = 0. A partition map entry with pmPyPartStart = 0 hangs
both drivers in the same way. On HFS, the reread is served from the
buffer cache, so the mount spins on the CPU without any I/O.

The on-disk layout allows only one order:

  [partition map] -> [HFS wrapper] -> HFS+ volume header (or HFS MDB)

Patches 1 and 4 follow this order step by step instead of rereading
in a loop, so the mount cannot loop, whatever the metadata are. They
are the minimal fix.

Patches 2, 3 and 5 validate the metadata before following it:

- Patch 2: the wrapper's volume bitmap must follow its MDB, the first
  allocation block must follow the volume bitmap, and the embedded
  extent must be non-empty, lie within the allocation blocks and end
  within the wrapper. The embedded volume header must have the
  signature declared in drEmbedSigWord, and the embedded volume must
  fit in the embedded extent.
- Patches 3 and 5: a partition must not overlap the driver descriptor
  and the partition map, must be non-empty and must end within the
  device, for both the old and the new partition map.

Patch 6 fixes an older issue found while working on patch 5: for the
old partition map, hfs_part_find() doesn't stop at the first matching
entry, so every following "TFS1" entry adds its start to part_start
again. Now it stops at the first matching entry, like the new
partition map and the HFS+ code do.

Tested in QEMU (KASAN, lockdep):

- Unpatched: a self-referencing wrapper (hfsplus) and a
  self-referencing partition map (hfsplus and hfs) hang the mount,
  and SIGKILL does not stop it.
- Patched: 26 crafted images are refused, each by the check it breaks
  (self-referencing wrapper, volume bitmap at the MDB, allocation
  blocks before the volume bitmap, empty or out-of-range embedded
  extent, embedded volume beyond the device, nested wrapper, wrapper
  containing a partition map, embedded volume with another signature,
  missing or larger than its extent; self-referencing, overlapping,
  empty and out-of-range partitions in old and new partition maps,
  chained partition maps).
- Patched: plain HFS+, wrapped HFS+ and plain HFS, also inside old and
  new Apple partition maps, mount and a written file survives a
  remount. Wrappers made by mkfs.hfsplus -w for 4 MiB - 8 GiB volumes
  and 512 B - 64 KiB block sizes pass the new checks; their embedded
  volume size equals the embedded extent size.
- Patches 1 and 4 alone: no crafted image hangs the mount either.

Viacheslav Dubeyko (6):
  hfsplus: look for the volume header in the order of the on-disk layout
  hfsplus: validate the HFS wrapper before following it
  hfsplus: validate the partition map entry before following it
  hfs: look for the MDB in the order of the on-disk layout
  hfs: validate the partition map entry before following it
  hfs: stop at the first matching entry of the old partition map

 fs/hfs/mdb.c          |  31 ++++++--
 fs/hfs/part_tbl.c     |  54 +++++++++++--
 fs/hfsplus/part_tbl.c |  48 ++++++++++--
 fs/hfsplus/wrapper.c  | 172 ++++++++++++++++++++++++++++++++++--------
 4 files changed, 256 insertions(+), 49 deletions(-)

-- 
2.53.0


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2026-12-05  1:31 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-12-05  1:31 [PATCH 0/6] hfs/hfsplus: fix endless loop on mount of crafted images Viacheslav Dubeyko
2026-12-05  1:31 ` [PATCH 1/6] hfsplus: look for the volume header in the order of the on-disk layout Viacheslav Dubeyko
2026-12-05  1:31 ` [PATCH 2/6] hfsplus: validate the HFS wrapper before following it Viacheslav Dubeyko
2026-12-05  1:31 ` [PATCH 3/6] hfsplus: validate the partition map entry " Viacheslav Dubeyko
2026-12-05  1:31 ` [PATCH 4/6] hfs: look for the MDB in the order of the on-disk layout Viacheslav Dubeyko
2026-12-05  1:31 ` [PATCH 5/6] hfs: validate the partition map entry before following it Viacheslav Dubeyko
2026-12-05  1:31 ` [PATCH 6/6] hfs: stop at the first matching entry of the old partition map Viacheslav Dubeyko

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®