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/5] hfsplus: fix locking and validation of the special files
Date: Thu, 19 Nov 2026 15:41:07 -0800 [thread overview]
Message-ID: <20261119234112.720963-1-slava@dubeyko.com> (raw)
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
next reply other threads:[~2026-11-19 23:41 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-19 23:41 Viacheslav Dubeyko [this message]
2026-11-19 23:41 ` [PATCH 1/5] hfsplus: reject special files larger than their allocation at mount Viacheslav Dubeyko
2026-11-19 23:41 ` [PATCH 2/5] hfsplus: map the allocation file without the extents B-tree Viacheslav Dubeyko
2026-11-19 23:41 ` [PATCH 3/5] hfsplus: give the special files their own extents_lock lockdep class Viacheslav Dubeyko
2026-11-19 23:41 ` [PATCH 4/5] hfsplus: reject an allocation bitmap that does not cover the volume Viacheslav Dubeyko
2026-11-19 23:41 ` [PATCH 5/5] hfsplus: name the constants of the allocation bitmap check 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=20261119234112.720963-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®