From: Viacheslav Dubeyko <slava@dubeyko.com>
To: Matthias Goergens <matthias.goergens@gmail.com>
Cc: John Paul Adrian Glaubitz <glaubitz@physik.fu-berlin.de>,
Yangtao Li <frank.li@vivo.com>,
linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 1/2] hfs: bound the partition-table hop in hfs_mdb_get()
Date: Mon, 28 Sep 2026 13:57:01 -0700 [thread overview]
Message-ID: <a30d61829abae665aec2faf5db93ab6e59bf1c3c.camel@dubeyko.com> (raw)
In-Reply-To: <20260926084010.569552-2-matthias.goergens@gmail.com>
On Sat, 2026-09-26 at 16:40 +0800, Matthias Goergens wrote:
> hfs_mdb_get() loops "while (1)" around hfs_part_find(), rereading the
> volume header wherever the partition table points. A partition entry
> with a zero start (pdStart or pmPyPartStart) leaves part_start where
> it
> was, and the loop reads the same blocks forever.
>
> An Apple partition map sits at the start of the raw device: the boot
> ROM
> reads it from block 1 (TN1189), and nothing Apple documents nests one
> inside a partition. Follow at most one partition-table hop and fail
> with -EIO after that, as for a table that cannot be parsed. A zero
> start is caught on the second pass, when the loop comes round again.
>
> Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
> Cc: stable@vger.kernel.org
> Signed-off-by: Matthias Goergens <matthias.goergens@gmail.com>
> ---
> A partition entry pointing at its own table hangs the mount forever
> without this patch and fails at once with it:
>
> img=hfs-partmap-loop.img
> put() { printf "$2" | dd of=$img bs=1 seek=$1 conv=notrunc
> status=none; }
> truncate --size=64K $img
> put $((512+0x00)) '\x50\x4d' # pmSig 'PM'
> put $((512+0x04)) '\x00\x00\x00\x01' # pmMapBlkCnt 1
> put $((512+0x08)) '\x00\x00\x00\x00' # pmPyPartStart 0 (self)
> put $((512+0x0c)) '\x00\x00\x00\x64' # pmPartBlkCnt 100
> put $((512+0x30)) 'Apple_HFS' # pmPartType
> mount -o ro,loop -t hfs $img /mnt
> ---
> fs/hfs/mdb.c | 10 +++++++++-
> 1 file changed, 9 insertions(+), 1 deletion(-)
>
> diff --git a/fs/hfs/mdb.c b/fs/hfs/mdb.c
> index 277de712f9d4..1704f332e28d 100644
> --- a/fs/hfs/mdb.c
> +++ b/fs/hfs/mdb.c
> @@ -134,6 +134,7 @@ int hfs_mdb_get(struct super_block *sb)
> sector_t part_start, part_size;
> loff_t off;
> __be16 attrib;
> + bool part_hop_done = false;
>
> /* set the device driver to 512-byte blocks */
> size = sb_min_blocksize(sb, HFS_SECTOR_SIZE);
> @@ -152,11 +153,18 @@ int hfs_mdb_get(struct super_block *sb)
> break;
> brelse(bh);
>
> - /* check for a partition block
> + /*
> + * check for a partition block
> * (should do this only for cdrom/loop though)
> + *
> + * The partition map is at the start of the device:
> follow
> + * it once, or an entry pointing at itself loops
> forever.
> */
> + if (part_hop_done)
> + return -EIO;
> if (hfs_part_find(sb, &part_start, &part_size))
If I understood the problem correctly, then we have issue in
hfs_part_find(). This method should have the proper sanity check.
Thanks,
Slava.
> return -EIO;
> + part_hop_done = true;
> }
>
> HFS_SB(sb)->alloc_blksz = size = be32_to_cpu(mdb-
> >drAlBlkSiz);
>
> base-commit: 6812ce4e4379ffc99c52401ec28f0d7ffbc36206
next prev parent reply other threads:[~2026-09-28 20:57 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-26 8:40 [PATCH 0/2] hfs, hfsplus: bound the partition-table and wrapper hops Matthias Goergens
2026-09-26 8:40 ` [PATCH 1/2] hfs: bound the partition-table hop in hfs_mdb_get() Matthias Goergens
2026-09-28 20:57 ` Viacheslav Dubeyko [this message]
2026-09-26 8:40 ` [PATCH 2/2] hfsplus: bound the wrapper and partition-table hops in hfsplus_read_wrapper() Matthias Goergens
2026-09-28 21:00 ` 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=a30d61829abae665aec2faf5db93ab6e59bf1c3c.camel@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=matthias.goergens@gmail.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®