From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.128.176 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796412720; b=zDR+YGkGUlMgBZKfFxSP0WNZv62frHwZcaWAjBVmELYbLPj8r953nmr2Rxbob6+gv5mi sowqrjYM9EXZ8etCQX8qapOVNfTJ0/DM4aML6JXQ1fF/eYpOiIbPfm/xidzZ+pbrzLk4Z d9QSZwEgqJDQh8HzcB7nFz0/La06Fn+fzfMbD5/DQBvwqhDi3pB4DKMh6ijtWtPBeXhth rrDrRF2/l1MGyxZz9QcCS65vhGEjYDKg2ewMxNILbcanKFLN1ZW/s0lP3CuqciglGptU6 7XziJvXsqQY958n2YbnvDDGObsg2cwmCIcDKjzMhtaIh4XrKaUY/AhMI1Tk53OyxwCg== 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=W+BYddzr415q56yRuRdGYZrMamvg4VMOC8f8OgVPSrIu8CFxRbZNUUEnuniaPTPoZWst tKvxxEVlWLHX9WEavWoWFOLaP7TIPnHcV6oIpXSVnISJQpW91NyG7P7qzDS/XfcuyfVlE +wkVrxkbi5aU4fSXbMzPlssKLJPUxS/MuxHunN+/zYDHDhvWXZW3n1GosOZgsdMYdwhiU 2NAV2/vB/ZMKHTyU0v1g9ZcqPMBtDX1PX1MQk3eFPe3I5tNwiL5mNa8PMAsYvlkpGQWLO fr9+iyf4PPyKSCe3nF4adtTuMEy2XAOc2+9LK4JAkawy+3iy3IUPk4h6Ux6zQLbUWlg== 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.176 Received: from mail-yw1-f176.google.com (mail-yw1-f176.google.com [209.85.128.176]) (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 CF375606A32C for ; Fri, 4 Dec 2026 19:31:59 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org CF375606A32C 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-f176.google.com with SMTP id 00721157ae682-8b32daac9d7so10037607b3.0 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=kbVWazs6BfGYsOTPvk3k4pl/re2Lirne7XFWsWm85clmRJEEFLfPycGAuDx5MzSFSO PzHCcxGRx0Me7dI7q7QcAcD6LBeHlQGhPbkXfo9xKewmvWI7cpisLh4XOmaxkAzAAccW g21stnWceSws5bif/U4rJ+yoafzOGgo4Zng1pRmheoZXFyVMOladveXfwWguwYA1zrJr ShHpNJPXg04Ga4RZ9RkyX8///li2xs9hK7aoxilDpN+7nA7BSSn3VC5chZdS6hMPL6uc pVH8Hr7dLPxEjDZUac4uU0GgKUmqmKNVFSVUbjLfwi1P3sNbYCVg3YfNPfTPysM0rZ89 iDDg== X-Forwarded-Encrypted: i=1; AL+hErHLbDEMRk6oRnAu8Wj/VyNPrMWchSGPZaEz+PFgbGl55DPEbcV30kwF+h7+tkGlf1ngNNbESrQlgokeG3k=@vger.kernel.org X-Gm-Message-State: AB4q+uFjVpAmt/OvAgi8Bv8hG/H0fhaKwHKqW79CWfT5nK4TEZwiobot h1Ofgf23SI3nqHx/gT/caNHVNQvZPT9DPSJpRcwq7AkDRog2QAPsEBkCTfVi9u/qJwE= X-Gm-Gg: AZFdTZdJsctk/n9sTT6q3OqbPr/jw6lG1fx6vgaOEbr6ZAcL9b4X33G48rf+irwSyHX HxO6flSTgF74oWUNb4Z1HAA8YcdWYPXXH+vur72SzfTRCWgJ/XIIu6EhQgqgiXBP/VkQSKLAVyV ZPx4kuARvaMiUbzilHc6K+y8P1PalAGt4xHNnC7UxhlWeyluknQgzCzIFvr2/WU/tPhBiYmmBtz wj9gylrJo5jQhYrsvah7gdrYt/30NHyR1R8OPdrctTgd8/1R/iD10DXVs5vDJH1dqK6F/qAd16Y Lfqkaj8bzPdegQCFGjWDzZT6j70r63+OFJ81iwbpNBF97RjqnRmN+GMpswIQfBoeH+3N8ihmbuv j2VK5X+zWOgulwZs2mY0uPauY+4eQMwjnZ2Nx0T2kYayErododTprKuN6SxxLE6ABMfseYL05Ye SAcDLM5OoiWMHCImobqYkiUhyu3qv/YSQgvMSF7fvKhrfWNb2S5TNwpJuGPjtch64MUVvPbEOMa 1VCk+4Oqwx15O9dMng4Uq/xhsZOrJb9fwd9BjD8w8wV3qlgbr6qKCpTpzVghojEQh+5sRo0a9Xc 4yCyhPf1wX1qJUuEAlIbW4KC7oBPqzwKUOvAnnLxFUPqOLwZu4a4a1CVlCg1r1r7dgdIBzohoRW doMwJWudpw6ogKhAtKFKRGK/RzvjFaHYqByI9/hunUUeb6ubOgPwVTfJAWu/I67i0XmNCCIM3vM I1/uYTH72io8nCyztxYuA= 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 ICwIEFgIDAQIeAQIXgAAKCRA5XNnC34R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mkwIfrQWBkr0OGD2AXFfPqo08c3jcJMOAEc2vBI08Fij9o1gHwP2suFaG0X6jUN 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-kernel@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