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>,
Aymen T <atijari00@gmail.com>,
stable@vger.kernel.org
Subject: [PATCH 4/6] hfs: look for the MDB in the order of the on-disk layout
Date: Fri, 4 Dec 2026 17:31:25 -0800 [thread overview]
Message-ID: <20261205013127.1533652-5-slava@dubeyko.com> (raw)
In-Reply-To: <20261205013127.1533652-1-slava@dubeyko.com>
hfs_mdb_get() looks for the MDB by rereading at part_start until it
finds the HFS signature, calling hfs_part_find() whenever it does not.
hfs_part_find() moves part_start by the start of the found partition,
which comes from disk.
For an Apple_HFS entry with pmPyPartStart = 0, part_start does not
move, the same partition map is found again, and the mount loops
forever. As the MDB sector is read from the buffer cache, the loop
spins on the CPU without any I/O. There is no iteration limit and no
signal check, so the mount(2) caller cannot be killed.
The on-disk layout allows only an optional Apple partition map at the
start of the device, whose partition contains the volume. Follow it
instead of rereading in a loop: look for a partition map only if no
MDB is found at the start of the device, and require the found
partition to contain the MDB. As there is no way back, the mount
cannot loop, whatever the metadata are.
Reported-by: Aymen T <atijari00@gmail.com>
Link: https://lore.kernel.org/linux-fsdevel/45bfa4d7-e9e2-45f2-9e12-a794defae64a@gmail.com/
Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
Signed-off-by: Viacheslav Dubeyko <slava@dubeyko.com>
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
---
fs/hfs/mdb.c | 31 +++++++++++++++++++++++--------
1 file changed, 23 insertions(+), 8 deletions(-)
diff --git a/fs/hfs/mdb.c b/fs/hfs/mdb.c
index 277de712f9d4..d17d7f9ac4f5 100644
--- a/fs/hfs/mdb.c
+++ b/fs/hfs/mdb.c
@@ -142,21 +142,36 @@ int hfs_mdb_get(struct super_block *sb)
if (hfs_get_last_session(sb, &part_start, &part_size))
return -EINVAL;
- while (1) {
- /* See if this is an HFS filesystem */
- bh = sb_bread512(sb, part_start + HFS_MDB_BLK, mdb);
- if (!bh)
- return -EIO;
- if (mdb->drSigWord == cpu_to_be16(HFS_SUPER_MAGIC))
- break;
+ /*
+ * The MDB is in sector HFS_MDB_BLK of the volume. The volume can be
+ * in a partition of an Apple partition map at the start of the
+ * device, so look for the partition map at most once.
+ */
+ bh = sb_bread512(sb, part_start + HFS_MDB_BLK, mdb);
+ if (!bh)
+ return -EIO;
+
+ if (mdb->drSigWord != cpu_to_be16(HFS_SUPER_MAGIC)) {
brelse(bh);
- /* check for a partition block
+ /*
+ * Check for a partition block. The partition found must
+ * contain the volume itself.
+ *
* (should do this only for cdrom/loop though)
*/
if (hfs_part_find(sb, &part_start, &part_size))
return -EIO;
+
+ bh = sb_bread512(sb, part_start + HFS_MDB_BLK, mdb);
+ if (!bh)
+ return -EIO;
+
+ if (mdb->drSigWord != cpu_to_be16(HFS_SUPER_MAGIC)) {
+ brelse(bh);
+ return -EINVAL;
+ }
}
HFS_SB(sb)->alloc_blksz = size = be32_to_cpu(mdb->drAlBlkSiz);
--
2.53.0
next prev parent 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 [PATCH 0/6] hfs/hfsplus: fix endless loop on mount of crafted images Viacheslav Dubeyko
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 ` Viacheslav Dubeyko [this message]
2026-12-05 1:31 ` [PATCH 5/6] hfs: " 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-5-slava@dubeyko.com \
--to=slava@dubeyko.com \
--cc=atijari00@gmail.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®