[PATCH 0/6] hfs/hfsplus: fix endless loop on mount of crafted images
From: Viacheslav Dubeyko
Date: Fri Dec 04 2026 - 20:31:38 EST
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