From: Viacheslav Dubeyko <slava@dubeyko.com>
To: glaubitz@physik.fu-berlin.de, frank.li@vivo.com
Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org,
vdubeyko@coreweave.com, Viacheslav Dubeyko <slava@dubeyko.com>
Subject: [PATCH 0/6] hfs/hfsplus: fix endless loop on mount of crafted images
Date: Fri, 4 Dec 2026 17:31:21 -0800 [thread overview]
Message-ID: <20261205013127.1533652-1-slava@dubeyko.com> (raw)
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
next reply other threads:[~2026-12-05 1:31 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-05 1:31 Viacheslav Dubeyko [this message]
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261205013127.1533652-1-slava@dubeyko.com \
--to=slava@dubeyko.com \
--cc=frank.li@vivo.com \
--cc=glaubitz@physik.fu-berlin.de \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=vdubeyko@coreweave.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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®