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>,
stable@vger.kernel.org
Subject: [PATCH 4/5] hfsplus: reject an allocation bitmap that does not cover the volume
Date: Thu, 19 Nov 2026 15:41:11 -0800 [thread overview]
Message-ID: <20261119234112.720963-5-slava@dubeyko.com> (raw)
In-Reply-To: <20261119234112.720963-1-slava@dubeyko.com>
The allocation file is a bitmap with one bit per allocation block, so
it has to be at least DIV_ROUND_UP(total_blocks, 8) bytes long. This is
not checked at mount. hfsplus_block_allocate() and hfsplus_block_free()
look up any block below total_blocks in the bitmap, so with a shorter
allocation file they read and modify bitmap bits beyond its end, which
are never written back.
The only guard is in hfsplus_file_extend(), which fails with -ENOSPC
("extend alloc file!") once the blocks in use approach the bitmap size,
and hfsplus_block_free() has none. On a 64M volume created with
"mkfs.hfsplus -b 4096" whose allocation file size in the volume header
was changed from 4096 to 1024 bytes (fsck.hfsplus reports the volume as
OK), writing two 24M files fails with -ENOSPC at half of the volume,
and after unmount fsck.hfsplus reports:
Volume bitmap needs minor repair for under-allocation
Fail the mount if the allocation file is too small for the volume.
Tested on a KASAN and lockdep kernel: the volume above is rejected at
mount with "allocation file size 1024 is too small for 16384 blocks",
the same volume with an allocation file of 2048 bytes (the minimum) or
4096 bytes mounts.
Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
Cc: stable@vger.kernel.org
cc: John Paul Adrian Glaubitz <glaubitz@physik.fu-berlin.de>
cc: Yangtao Li <frank.li@vivo.com>
cc: linux-fsdevel@vger.kernel.org
Signed-off-by: Viacheslav Dubeyko <slava@dubeyko.com>
---
fs/hfsplus/super.c | 13 +++++++++++++
1 file changed, 13 insertions(+)
diff --git a/fs/hfsplus/super.c b/fs/hfsplus/super.c
index d23594d12064..6e4068e53b4f 100644
--- a/fs/hfsplus/super.c
+++ b/fs/hfsplus/super.c
@@ -777,6 +777,19 @@ static int hfsplus_fill_super(struct super_block *sb, struct fs_context *fc)
}
sbi->alloc_file.inode = inode;
+ /*
+ * The allocation bitmap has one bit per allocation block. The
+ * bitmap code looks up any block below total_blocks in it, so it
+ * must cover all of them.
+ */
+ if (inode->i_size < DIV_ROUND_UP((u64)sbi->total_blocks,
+ BITS_PER_BYTE)) {
+ pr_err("allocation file size %lld is too small for %u blocks\n",
+ inode->i_size, sbi->total_blocks);
+ err = -EIO;
+ goto out_put_alloc_file;
+ }
+
err = hfsplus_ext_load_alloc_file(sb);
if (err)
goto out_put_alloc_file;
--
2.53.0
next prev parent 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 [PATCH 0/5] hfsplus: fix locking and validation of the special files Viacheslav Dubeyko
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 ` Viacheslav Dubeyko [this message]
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-5-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=stable@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®