Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.128.174 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796412720; b=wqmgXzL4vqfHYY0WtOALepQafVBgYEp0AqI5YgFCk6juNR0YegL0vAdOVv7dygztpSaP 53HENNGjVog/I08C2dD2phSuSZTRA+k2IxOaHcccUOAOPAs3mlzv3W17IynCpbFiHz8jm /VaEAKyodtsRGNAC+Dd+D6J2K82G7KKj/tdPobL5LzM073l787qdiB1nVS8mEPUBXhyD6 8i27NjMz9Zq7s5Z5of/7BwQ0mZvLASrygRnW0ELJOQehRm7PilevFD23YgR7slgEEoOQZ dSQRCr/jyqRd1O9Km88OTA0/Z2xwwavqNAddPV4MOU6bn9SdarS33u9Bs1M3T/XSB3Q== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796412720; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: Message-ID:Subject:From:To:Date:In-Reply-To:References:Autocrypt: Content-Type:Content-Transfer-Encoding:User-Agent:MIME-Version; bh=bdoStnQHy+xo8tGqm/ElRhrGW02a82tRruKDNM3Apjg=; b=bvgZ/5zWtWUormjPRzmlvYKAHUUc0d7iXQiXH1cBuP25M9nYZ9dAV9olYovpeWPgMn/J vy1ez42AU5FtoyFmTGL0GBaGuKtZscspJMEBzivd3yHpRfIgTund8g4nECxWXnyYkomvy WVCveEiHZmkW2NembGfGhxnV7k6U7KgimDVBBcKhWKQeGl3nrCfbNv36zz13FFesflDdj TplciIJoX7Ha2LOI/yPdg1UxYOii8uiVCsk3BoNo9+I2BxbEmSdVLSGfzOo89ngl2nD1Y IrPtt5F/cnOqwgbrtJqLkUWZvtrhePUtyUZkwmY/8tvujd9F2im4JyZ/du7eP8wkJXg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none header.from=dubeyko.com; spf=pass smtp.mailfrom=dubeyko.com; dkim=pass header.d=dubeyko-com.20260707.gappssmtp.com header.i=@dubeyko-com.20260707.gappssmtp.com header.a=rsa-sha256 header.s=20260707 header.b=MtOWTJnu; arc=none smtp.remote-ip=209.85.128.174 Received: from mail-yw1-f174.google.com (mail-yw1-f174.google.com [209.85.128.174]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CDB92606A322 for ; Fri, 4 Dec 2026 19:31:59 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org CDB92606A322 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=dubeyko.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=dubeyko.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=dubeyko-com.20260707.gappssmtp.com header.i=@dubeyko-com.20260707.gappssmtp.com header.a=rsa-sha256 header.s=20260707 header.b=MtOWTJnu Received: by mail-yw1-f174.google.com with SMTP id 00721157ae682-8b4fb5d96b3so20318627b3.1 for ; Fri, 04 Dec 2026 11:31:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dubeyko-com.20260707.gappssmtp.com; s=20260707; t=1796412719; x=1797017519; darn=vger.kernel.org; h=mime-version:user-agent:content-transfer-encoding:content-type :autocrypt:references:in-reply-to:date:to:from:subject:message-id :from:to:cc:subject:date:message-id:reply-to:content-type; bh=bdoStnQHy+xo8tGqm/ElRhrGW02a82tRruKDNM3Apjg=; b=MtOWTJnufHdAaxdWAxA/DujuDEpDHYYAf5yaOk3rLBnTfhXGQRJrlpZLiHdnVS5C4d BEWIwgtZZPQ5b6jZSQf0ZudGZfFPLHu8iabpG+2PzJnqD8eJN9qAp6Tr+x/hki3897ec Mz5TzvcPW/xgx+efQlgEGZjnHOaMDwMBu0udD9AqWI07mOKgrpzrIRo3t+9YN7vJpubb cUOQTU1hNhs0tGvy0NiPISF0CfDfMoX5Ojefj3sYRFJY6Va9nzmnTwhoWC0BL4BbA9pC u0eXZFo80kuUOGlRJu5knRkcD6vfH/0xvwCOxB/HI6rX5VhFhI0voUpaYEd0LM0W1QCR V08Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796412719; x=1797017519; h=mime-version:user-agent:content-transfer-encoding:content-type :autocrypt:references:in-reply-to:date:to:from:subject:message-id :x-gm-gg:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to:content-type; bh=bdoStnQHy+xo8tGqm/ElRhrGW02a82tRruKDNM3Apjg=; b=12/GhuCZlQRIqN0LhowNXDry4DiEBcFkWtuSbqRiQuCBFlqi3JJkEi8ENXtM3tJEwp PDJ36v0qn1/0q9PAa4zODes3ZGn53J94rOOvYtfg+JJ7JMhBwWneG8yx4xrtVYvgfqEG RBk6fOP5DMZ/q25ZWxTze7llr+aieC9+y9y0sED+whaBUde5YmTp9w0fSXOLa00EEuu7 6uZe8BeMnek8eHJPfK5RRo4by9s7od5lGgiHkn5XwW9GApmfpdG4MMDheYC/g043I7AN npS7kcOk6xQ7YwSn7PRXCdU3WPU7ZAP7UqQp4ATDYTrp/q0BNV8jKYVryOM8jk7XUbFO EOjQ== X-Forwarded-Encrypted: i=1; AL+hErHZJbyKK0js6IWnGmm1B7iBhyJzf5WiyNT5ty4li9x88MNwO6hetvHnjVaz3GW5fddoBAVWWbPHnJcrv1/U@vger.kernel.org X-Gm-Message-State: AB4q+uHVtdhXL/bCdXbeeIJaehLMw8VOSGIqPUx/pBHyUZw3ZWxw4nEj 1OrEnq44r/0ovRJ/MnZzaPylv1OQTwWtWxEoYb/VhCtVHYTuwtlxNrif6B/NfS/8mF1Y6VH86zI hmb/Dj4Y= X-Gm-Gg: AZFdTZej9FgxYCioY9ujKoWssSiSV1TNvGqCDyX0HO086qJ++jrs3qYbuzJTpVkoPfL /3wZY8yMtI3FvubxNL6c7rGehHcyyeVTpJYhslpMPFNT9Na4eZDjLAqPFgdHBpGN+LV9Z81PhgK BtBEItfLHk/PQ80ZY66fDQUyipRj74d8onEOjkhL2tu6IhziiolNb1KbRS7+UsyF5JwAJ0FzjBH 6mG+pCOlwt6KBWl7I3Szh6obXswpx/68oFKiyu6ivVPdKq/wQYZGtVHaMRG2vHA1yH1uXUt6edb 3g0v7YnrAHpAIPCX+coM+WbpUdq30IjPpnAMNMslDYE93Wj9BkkJPOerqYeKGtdrdLdj7Ac7b7H QFwsIo8lCzkF9l7sw63wPHxUjvPqOoAtwLlpsT7r5DkcyGxWWhqlqVvnjshP26345xEUrf9ptgR an3p1nXJHOb6q/kj+EKq8I0X2W3/fydZRCaIUhbc5rIJ3ghFbb+7iRn2bqwauO5w4KForrHrKy9 R6rZ9Iub6FWz83MtvZJmIXlDltMbd2Mkx9p88vMJMerj86pflc/EmIWz3Z1q7PEVFYYVB8cqgKo nwlYVEKHFjre+EooGHrF+QLOLSP8yNFoJhDA/qeL1reWspiKjfylZ8lCp0QVoL5wxcSBCC+X+wT nEq3fluw1z3lWBeozhYq4ot5sP2Gmcbt4b0HayG/wSCrAjoiAvrhRmO/Uh3147aQkS462lm0aB0 +KlUcSRmY96tZK44ogbXY= X-Received: by 2002:a05:690c:7286:b0:8b3:8d86:3ecb with SMTP id 00721157ae682-8b660dd866emr14976577b3.30.1796412718743; Fri, 04 Dec 2026 11:31:58 -0800 (PST) Received: from ?IPv6:2600:1700:6476:1430:8a82:9efd:4df6:308d? ([2600:1700:6476:1430:8a82:9efd:4df6:308d]) by smtp.gmail.com with ESMTPSA id 00721157ae682-8b660ddc487sm14180387b3.35.2026.12.04.11.31.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Dec 2026 11:31:58 -0800 (PST) Message-ID: Subject: Re: [PATCH 0/3] hfs: fix writes to b-tree nodes larger than a page From: Viacheslav Dubeyko To: Mar Dominguez , John Paul Adrian Glaubitz , Yangtao Li , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Date: Fri, 04 Dec 2026 11:31:56 -0800 In-Reply-To: References: Autocrypt: addr=slava@dubeyko.com; prefer-encrypt=mutual; keydata=mQINBGgaTLYBEADaJc/WqWTeunGetXyyGJ5Za7b23M/ozuDCWCp+yWUa2GqQKH40dxRIR zshgOmAue7t9RQJU9lxZ4ZHWbi1Hzz85+0omefEdAKFmxTO6+CYV0g/sapU0wPJws3sC2Pbda9/eJ ZcvScAX2n/PlhpTnzJKf3JkHh3nM1ACO3jzSe2/muSQJvqMLG2D71ccekr1RyUh8V+OZdrPtfkDam V6GOT6IvyE+d+55fzmo20nJKecvbyvdikWwZvjjCENsG9qOf3TcCJ9DDYwjyYe1To8b+mQM9nHcxp jUsUuH074BhISFwt99/htZdSgp4csiGeXr8f9BEotRB6+kjMBHaiJ6B7BIlDmlffyR4f3oR/5hxgy dvIxMocqyc03xVyM6tA4ZrshKkwDgZIFEKkx37ec22ZJczNwGywKQW2TGXUTZVbdooiG4tXbRBLxe ga/NTZ52ZdEkSxAUGw/l0y0InTtdDIWvfUT+WXtQcEPRBE6HHhoeFehLzWL/o7w5Hog+0hXhNjqte fzKpI2fWmYzoIb6ueNmE/8sP9fWXo6Av9m8B5hRvF/hVWfEysr/2LSqN+xjt9NEbg8WNRMLy/Y0MS p5fgf9pmGF78waFiBvgZIQNuQnHrM+0BmYOhR0JKoHjt7r5wLyNiKFc8b7xXndyCDYfniO3ljbr0j tXWRGxx4to6FwARAQABtCpWaWFjaGVzbGF2IER1YmV5a28gPFNsYXZhLkR1YmV5a29AaWJtLmNvbT 6JAlQEEwEKAD4WIQRVwwtrZ87KC0La2wQ5XNnC34RAdQUCaBpd7AIbAQUJA8JnAAULCQgHAgYVCgk ICwIEFgIDAQIeAQIXgAAKCRA5XNnC34RAdYjFEACiWBEybMt1xjRbEga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o08c3jcJMOAEc2vBI08Fij9o1gHwP2suFaG0X6jUN sy6KPOKg7TVMXtMzxNsKGyFxC1pG7lv+oaEBT6TJSVs/pm71ZrOezQANRzvBeXNUixWienTdAEG8a x4uOf3EF5WvYUhDiY8XBJyRv2ZnKJmBxZ3jPStadSuh3Bmo4mNgRVpFXrfb7h8oJC1l1WGdJa9aWi xUedku0/nH+nZMTqrtWYkXoLxaMswVM5S4f3pYKd7VlHxtlZiQ95RqQd5uWYcEN6xaSvAO3Cs4Co8 D6etTHtKPcx1+d0x6BvkBvqNJ5yCiuzPPnKE6E0ss52KKvQt3injPyfe8ffofbW4s2nlEL1s0DoBv JslCebuQ6+Orb/Sl6zictIsv3XMq3jGFeZcDg2hXzngOC255+b0Z/To7jINTxYQot8jCOJQOLplxc NFdvziOa4FgUBC4X71upsZIoZJeii2V/Jtc3B4g== Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.56.2-9 X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 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.=C2=A0 Any change to a catalog or extents tree whose > nodes > are larger than PAGE_SIZE then writes past that page. >=20 > Patch 1 makes the four helpers walk the node's pages.=C2=A0 Patch 2 > rejects > node sizes below 512 bytes, as hfsplus does.=C2=A0 Patch 3 adds KUnit > tests > for the four helpers. >=20 > 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.=C2=A0 With patch 1 the writ= e > helpers do too, as the hfsplus ones do. >=20 > Tested with x86_64 KASAN builds under QEMU: hfs/for-next > (a2c27efbbd43) > with CONFIG_DEBUG_VM, and mainline (007722b8211f) without it.=C2=A0 The > test > volumes were made with hformat, with the catalog tree rewritten to > use > 8 KiB or 32 KiB nodes.=C2=A0 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: =E2=96=8E "A B*-tree file consists entirely of objects called nodes, each o= f which is 512 bytes long." - Under Header Nodes, describing the BTHdrRec field bthNodeSize: Integer; {size of a node}: =E2=96=8E "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: =E2=96=8E "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 =E2=80=BA HFS and HFS Plus B-Trees Compared =E2=80=BA Node Siz= es: =E2=96=8E "In an HFS B-tree, nodes always have a fixed size of 512 bytes." =E2=96=8E "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:=C2=A0512. TN1150 says it without any qualifier. - bthNodeSize is still a field in the header, and Inside Macintosh says "currently" always=C2=A0512. So the format left room for other sizes, but n= o 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.=C2=A0 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.=C2=A0 With the series, both work and the volume mounts again with > the expected directories.=C2=A0 A volume with the usual 512-byte nodes > behaves the same with and without the series.=C2=A0 The hfs KUnit suites > pass on UML with KASAN; without patch 1 the four new cases fail. >=20 > 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.=C2=A0 Patches 1 and 2 also apply to mainline; patch 3 needs the > KUnit setup in hfs/for-next.=C2=A0 I can send the test images privately. >=20 > Found and written with an LLM coding assistant. >=20 > Mar Dominguez (3): > =C2=A0 hfs: fix b-tree node writes past the first page > =C2=A0 hfs: check the b-tree node size range in hfs_btree_open() > =C2=A0 hfs: add KUnit tests for b-tree node operations >=20 > =C2=A0fs/hfs/Makefile=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0 |=C2=A0=C2=A0 2 +- > =C2=A0fs/hfs/bnode.c=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0 | 132 ++++++++++++++--- > =C2=A0fs/hfs/bnode_test.c=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 | 293 > +++++++++++++++++++++++++++++++++++++ > =C2=A0fs/hfs/btree.c=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0 |=C2=A0=C2=A0 5 +- > =C2=A0include/linux/hfs_common.h |=C2=A0=C2=A0 6 +- > =C2=A05 files changed, 416 insertions(+), 22 deletions(-) > =C2=A0create mode 100644 fs/hfs/bnode_test.c >=20 >=20 > base-commit: a2c27efbbd43d2e3756860ebd1bf891d7481f2c5