From: Viacheslav Dubeyko <slava@dubeyko.com>
To: Mar Dominguez <mar@talkjune.com>,
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 0/3] hfs: fix writes to b-tree nodes larger than a page
Date: Fri, 04 Dec 2026 11:31:56 -0800 [thread overview]
Message-ID: <e2914a3111777fbc7cabd6e4aa9ddb68f0418017.camel@dubeyko.com> (raw)
In-Reply-To: <MNEd8Lar2cPfPtaOkVL2PispJ3ysmgFipjnu@talkjune.com>
On Fri, 2026-12-04 at 05:36 +0000, Mar Dominguez wrote:
> hfs_btree_open() accepts b-tree node sizes up to 32 KiB, and the read
> side handles nodes that span several pages, but hfs_bnode_write(),
> hfs_bnode_clear(), hfs_bnode_copy() and hfs_bnode_move() only use the
> node's first page. Any change to a catalog or extents tree whose
> nodes
> are larger than PAGE_SIZE then writes past that page.
>
> Patch 1 makes the four helpers walk the node's pages. Patch 2
> rejects
> node sizes below 512 bytes, as hfsplus does. Patch 3 adds KUnit
> tests
> for the four helpers.
>
> Patch 1 fixes the write helpers instead of refusing nodes larger than
> 512 bytes: hfs_btree_open() has accepted them since 2.6.12, and the
> read
> and node creation paths already support them. With patch 1 the write
> helpers do too, as the hfsplus ones do.
>
> Tested with x86_64 KASAN builds under QEMU: hfs/for-next
> (a2c27efbbd43)
> with CONFIG_DEBUG_VM, and mainline (007722b8211f) without it. The
> test
> volumes were made with hformat, with the catalog tree rewritten to
> use
> 8 KiB or 32 KiB nodes. Without the series, mkdir and rmdir on them
Please, correct me if I wrong. Have you implemented support of node
size bigger than 512 bytes in HFS?
Inside Macintosh: Files (the original HFS spec)
Chapter 2, "Data Organization on Volumes", in the B*-Trees section
(Files-104):
- Under Nodes:
▎ "A B*-tree file consists entirely of objects called nodes, each of
which is 512 bytes long."
- Under Header Nodes, describing the BTHdrRec field bthNodeSize:
Integer; {size of a node}:
▎ "The size (in bytes) of a node. Currently, this is always 512."
- Under Map Nodes, the map record size is worked out from the 512-byte
node:
▎ "occupies 494 bytes (512 bytes in the node, less 14 bytes for the
node descriptor and 2 bytes for each of the two record offsets at the
end of the node)."
TN1150 "HFS Plus Volume Format"
TN1150 is Apple's HFS+ spec, and it also restates the HFS rule
(tn1150).
- In B-Trees › HFS and HFS Plus B-Trees Compared › Node Sizes:
▎ "In an HFS B-tree, nodes always have a fixed size of 512 bytes."
▎ "In an HFS Plus B-tree, the node size is determined by a field
(nodeSize) in the header node. The node size must be a power from 512
through 32,768. An implementation must use the nodeSize field to
determine the actual node size."
- Table 1, "HFS and HFS Plus Compared", lists the catalog node size as
512 bytes (HFS) against 4 KB (HFS Plus).
- In the Header Record section, nodeSize is described as "a power of
two, from 512 through 32,768, inclusive". That describes the HFS+
header.
- The format has one valid node size for HFS: 512. TN1150 says it
without any qualifier.
- bthNodeSize is still a field in the header, and Inside Macintosh says
"currently" always 512. So the format left room for other sizes, but no
Apple HFS implementation ever used them.
So, we should support only 512 bytes node size. This a difference
between HFS and HFS+. HFS supports only 512 bytes b-tree nodes and
nodes share memory page. For the case of HFS+, b-tree node cannot be
smaller than 4K, if I remember correctly. I assume that we could have
issue in HFS b-tree nodes management code. But node size should be 512
bytes always for the case of HFS.
Thanks,
Slava.
> hit
> the VM_BUG_ON in memcpy_to_page() with CONFIG_DEBUG_VM. Without
> CONFIG_DEBUG_VM, the volume can't be mounted again after mkdir (8 KiB
> nodes), and rmdir (32 KiB nodes) crashes init through corrupted
> memory. With the series, both work and the volume mounts again with
> the expected directories. A volume with the usual 512-byte nodes
> behaves the same with and without the series. The hfs KUnit suites
> pass on UML with KASAN; without patch 1 the four new cases fail.
>
> I have not tested on 32-bit HIGHMEM, on architectures with pages
> larger
> than 4 KiB, or with volumes written by Mac OS, and I have not run
> xfstests. Patches 1 and 2 also apply to mainline; patch 3 needs the
> KUnit setup in hfs/for-next. I can send the test images privately.
>
> Found and written with an LLM coding assistant.
>
> Mar Dominguez (3):
> hfs: fix b-tree node writes past the first page
> hfs: check the b-tree node size range in hfs_btree_open()
> hfs: add KUnit tests for b-tree node operations
>
> fs/hfs/Makefile | 2 +-
> fs/hfs/bnode.c | 132 ++++++++++++++---
> fs/hfs/bnode_test.c | 293
> +++++++++++++++++++++++++++++++++++++
> fs/hfs/btree.c | 5 +-
> include/linux/hfs_common.h | 6 +-
> 5 files changed, 416 insertions(+), 22 deletions(-)
> create mode 100644 fs/hfs/bnode_test.c
>
>
> base-commit: a2c27efbbd43d2e3756860ebd1bf891d7481f2c5
next prev parent reply other threads:[~2026-12-04 19:31 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-04 5:36 Mar Dominguez
2026-12-04 5:38 ` [PATCH 1/3] hfs: fix b-tree node writes past the first page Mar Dominguez
2026-12-04 5:41 ` [PATCH 2/3] hfs: check the b-tree node size range in hfs_btree_open() Mar Dominguez
2026-12-04 5:43 ` [PATCH 3/3] hfs: add KUnit tests for b-tree node operations Mar Dominguez
2026-12-04 19:31 ` Viacheslav Dubeyko [this message]
2026-12-04 22:22 ` [PATCH 0/3] hfs: fix writes to b-tree nodes larger than a page Mar Dominguez
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=e2914a3111777fbc7cabd6e4aa9ddb68f0418017.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=mar@talkjune.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®