[PATCH 0/5] hfsplus: fix locking and validation of the special files
From: Viacheslav Dubeyko
Date: Thu Nov 19 2026 - 18:41:23 EST
Syzkaller reported a lockdep "possible recursive locking" warning on
the extents_lock in hfsplus_get_block(): deleting a file frees its
blocks, and reading the allocation bitmap took the allocation file's
extents_lock inside the deleted file's one. Looking into it showed
three problems around the special files (extents, catalog, allocation,
startup and attributes file), patches 1-3, and a missing check of the
allocation file's size, patches 4-5.
Patch 1 fixes how syzkaller reached the warning. Its image claims an
allocation file of 0x800000000800 bytes in one allocated block, so the
bitmap read mapped blocks that no extent covers through the extents
B-tree. The mount now fails when the logical size of a special file in
the volume header is larger than its allocation.
Patch 2 fixes a real deadlock on valid volumes. Reading the bitmap with
sbi->alloc_mutex held can search the extents B-tree for an allocation
file extent, while growing the extents B-tree allocates blocks with the
B-tree's tree_lock held. When the allocation file has an extent record
in the extents B-tree (which a fragmented allocation file has), a
single writer deadlocks on the tree_lock it holds. The allocation file
does not change while mounted, so its extent records are now read once
at mount time and its blocks are mapped without the extents B-tree.
This also removes the lock nesting from the syzkaller report.
Patch 3 silences a lockdep false positive on valid volumes: growing
the extents B-tree takes the B-tree file's extents_lock inside the
extents_lock of the file being extended, and with one lockdep class for
every inode read from disk this looks like a circular dependency. Each
special file now gets its own named lockdep class.
Patch 4 rejects at mount an allocation file that is too small to hold
one bit for each block of the volume. The bitmap code looks up any
block below total_blocks in the bitmap, so with a short allocation file
it read and modified bits beyond its end that were never written back;
fsck.hfsplus does not catch such a volume either. Only
hfsplus_file_extend() guarded against it, by failing with -ENOSPC once
the blocks in use approached the bitmap size.
Patch 5 names the two constants of that guard in hfsplus_file_extend()
(bits per byte and a margin of eight bits); no functional change.
Testing (KASAN, lockdep, x86_64 QEMU guest):
- The syzkaller image is rejected at mount, as are images with the size
of the allocation, extents, catalog or attributes file set one byte
beyond its allocation; consistent images still mount.
- The deadlock in patch 2 is reproduced, before the fix, on a volume
created with "mkfs.hfsplus -b 512 -c e=8,d=8" and edited so that the
allocation file has one extent record in the extents B-tree
(fsck.hfsplus reports it as OK), by interleaving 4K appends to two
files. With the fix the writes complete and fsck.hfsplus reports the
volume as OK.
- The lockdep report in patch 3 is reproduced on a volume created with
"mkfs.hfsplus -c e=1,d=1" by fragmenting files created before a
remount, and is gone with the patch.
- A 64M volume whose allocation file size was cut from 4096 to 1024
bytes mounts without patch 4, fails writes with -ENOSPC at half of
the volume and is left with an inconsistent bitmap; with the patch it
is rejected at mount, and it mounts with 2048 bytes (the minimum).
Filling that volume fails with -ENOSPC at 0 free blocks and leaves it
consistent.
- xfstests generic/001, 002, 013, 075 and 112 pass; generic/091 fails
as it does without the series.
Viacheslav Dubeyko (5):
hfsplus: reject special files larger than their allocation at mount
hfsplus: map the allocation file without the extents B-tree
hfsplus: give the special files their own extents_lock lockdep class
hfsplus: reject an allocation bitmap that does not cover the volume
hfsplus: name the constants of the allocation bitmap check
fs/hfsplus/bitmap.c | 4 +-
fs/hfsplus/extents.c | 141 +++++++++++++++++++++++++++++++++++-----
fs/hfsplus/hfsplus_fs.h | 20 +++++-
fs/hfsplus/inode.c | 4 +-
fs/hfsplus/super.c | 89 ++++++++++++++++++++++---
5 files changed, 228 insertions(+), 30 deletions(-)
--
2.53.0