hfs: fix writes to b-tree nodes larger than a page
Get series with b4
b4 am [email protected]Versions newest first
- v1 Latest3 patches 2 repliesIn review
Patches in v1 No applies recorded yet
| # | Subject and files | Size | Replies | Applied |
|---|---|---|---|---|
| 1/3 | hfs: fix b-tree node writes past the first pagefs/ | +106 | 0 replies | |
| 2/3 | hfs: check the b-tree node size range in hfs_btree_open()fs/ include/ | +8 | 0 replies | |
| 3/3 | hfs: add KUnit tests for b-tree node operationsfs/ fs/ fs/ | +302 | 0 replies |
Reviews trailers per patch
No Reviewed-by, Acked-by or Tested-by trailers for v1 yet.
Cover letter [PATCH 0/3] hfs: fix writes to b-tree nodes larger than a page
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 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
Signature · 1 line
2.53.0