From nobody Tue Aug 25 14:34:08 2026 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 398BC3D3D16; Fri, 14 Aug 2026 02:31:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.19 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786674717; cv=none; b=WHXp1dozcksEWIeDgNoPJVd7+SYr/N8/0hCziht03oy8fpUwvgaQkfOojG+doIA2kBDox2ZbH0rG2Qks3xvaJir5oZXfIaaUwxNR7crF0xBl16oUF+L81kpwIACXIHE6UryR//squPBZfR5hhurfjhxow43tepsHEA83+FEk9d0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786674717; c=relaxed/simple; bh=HVNN53PvjMc6+P3LJmQhY+c/XRI9+JOUtheL/kQoy3I=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=bFePg4YPse4lkMw4PcY7QaBh/rdyxxHSZ060ACCNmbO5iWOXRjsi7F9DGK9OavwI1aqHX63QmwVbp9SO0971ktHhMIklvH5K/Pd8DLXcRsXtzl22qukzmDO8YmIX5y+BU83a3ato7aHZpkqKndm36LG/jeIWeALBru0PB/pAZB8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=K7j7+EE6; arc=none smtp.client-ip=198.175.65.19 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="K7j7+EE6" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1786674715; x=1818210715; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=HVNN53PvjMc6+P3LJmQhY+c/XRI9+JOUtheL/kQoy3I=; b=K7j7+EE6rAdLmjq9ZZ9808HDSzKc3WwfOZMaIqd1B8ljc5DNW9kXtJfz LnJMsGGjGNqqw+TOhzpZyTPRFPL6JOJ8nuhUosYGVdPKh2OPMmQSEkHC6 6fvY+hSJU2qEo7jWh8MJkmJGEdT3/ler0e6ebYGQ+89+4GDy7D/BYY2sl P8p9PWTBRz1OT1HvFWYg0/i7ytGic+kHqVRcALJT0QcamoNt4jen+wRsl QwhBaWwV/OT8CRIs1i/A5B+axsDgYVAjvrqxOcmnCdrsEVsj5gQ66kUFq OOqPqw3AT6c4sSeSF8IPrzqvwL+T3E9QsPlsSEMcx4ljVWN4U63DIAEp3 A==; X-CSE-ConnectionGUID: avJRTz4bSIS5EUdjBf7sRw== X-CSE-MsgGUID: 15nC+3+aToeCz8fZzT/V8w== X-IronPort-AV: E=McAfee;i="6800,10657,11874"; a="87181988" X-IronPort-AV: E=Sophos;i="6.25,222,1779174000"; d="scan'208";a="87181988" Received: from orviesa001.jf.intel.com ([10.64.159.141]) by orvoesa111.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Aug 2026 19:31:55 -0700 X-CSE-ConnectionGUID: fi4IclvAS+mLSJaJzTuXLQ== X-CSE-MsgGUID: qN0HOCWCSX6iDAEq/Sa0Nw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.25,222,1779174000"; d="scan'208";a="302339622" Received: from tester.sh.intel.com ([10.112.106.126]) by orviesa001.jf.intel.com with ESMTP; 13 Aug 2026 19:31:54 -0700 From: Tao Yu To: linux-fsdevel@vger.kernel.org Cc: slava@dubeyko.com, glaubitz@physik.fu-berlin.de, frank.li@vivo.com, linux-kernel@vger.kernel.org, syzbot+2bf21610eea63cb2ce93@syzkaller.appspotmail.com, Tao Yu Subject: [PATCH 1/2] hfs: detect node 0 btree map corruption at mount time Date: Fri, 14 Aug 2026 10:31:49 +0800 Message-Id: <20260814023150.3482810-2-tao1.yu@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260814023150.3482810-1-tao1.yu@intel.com> References: <20260814023150.3482810-1-tao1.yu@intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" HFS+ already validates that the btree map keeps node 0 marked as in-use when the tree is opened. HFS lacks the same check, so a corrupted volume can proceed past mount with a broken node bitmap and only fail later in write paths. Port the node 0 bitmap validation to HFS. If the header node is not marked as allocated in the on-disk map, warn that the btree bitmap is corrupted and force the filesystem read-only so users can repair it with fsck.hfs. This keeps the HFS mount-time behavior aligned with HFS+ and catches the corruption closer to where it becomes observable. Signed-off-by: Tao Yu --- fs/hfs/btree.c | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/fs/hfs/btree.c b/fs/hfs/btree.c index 2eb37a2f64e86..14114318ec724 100644 --- a/fs/hfs/btree.c +++ b/fs/hfs/btree.c @@ -15,12 +15,59 @@ =20 #include "btree.h" =20 +static bool hfs_bmap_test_bit(struct hfs_bnode *node, u32 node_bit_idx) +{ + u16 rec_idx, off, len; + u32 byte_offset; + u8 byte, mask; + + if (node->this =3D=3D 0) { + if (node->type !=3D HFS_NODE_HEADER) { + pr_err("hfs: invalid btree header node\n"); + return false; + } + rec_idx =3D 2; + } else { + if (node->type !=3D HFS_NODE_MAP) { + pr_err("hfs: invalid btree map node\n"); + return false; + } + rec_idx =3D 0; + } + + len =3D hfs_brec_lenoff(node, rec_idx, &off); + if (!len) + return false; + + byte_offset =3D node_bit_idx / BITS_PER_BYTE; + if (byte_offset >=3D len) + return false; + + byte =3D hfs_bnode_read_u8(node, off + byte_offset); + mask =3D 1 << (7 - (node_bit_idx % BITS_PER_BYTE)); + + return byte & mask; +} + +static const char *hfs_btree_name(u32 cnid) +{ + switch (cnid) { + case HFS_EXT_CNID: + return "Extents Overflow File"; + case HFS_CAT_CNID: + return "Catalog File"; + default: + return "Unknown B-tree"; + } +} + /* Get a reference to a B*Tree and do some initial checks */ struct hfs_btree *hfs_btree_open(struct super_block *sb, u32 id, btree_key= cmp keycmp) { struct hfs_btree *tree; struct hfs_btree_header_rec *head; struct address_space *mapping; + struct hfs_bnode *node; struct folio *folio; struct buffer_head *bh; unsigned int size; @@ -155,6 +202,19 @@ struct hfs_btree *hfs_btree_open(struct super_block *s= b, u32 id, btree_keycmp ke kunmap_local(head); folio_unlock(folio); folio_put(folio); + + node =3D hfs_bnode_find(tree, 0); + if (IS_ERR(node)) + goto free_inode; + + if (!hfs_bmap_test_bit(node, 0)) { + pr_warn("(%s): %s (cnid 0x%x) map record invalid or bitmap corruption de= tected, forcing read-only.\n", + sb->s_id, hfs_btree_name(id), id); + pr_warn("Run fsck.hfs to repair.\n"); + sb->s_flags |=3D SB_RDONLY; + } + + hfs_bnode_put(node); return tree; =20 fail_folio: --=20 2.34.1 From nobody Tue Aug 25 14:34:08 2026 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7A0653D7D75; Fri, 14 Aug 2026 02:31:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.19 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786674725; cv=none; b=TahQziEjWxjv+H5yVphZ/5JxKchRRPtp200QcL0lyJuXsoIhwyVFZS7rSrOiktKKE575VtIXkMr7PXnkU119YY/xPZPwExyP6l2YuC+Uip+iKTbCUeghFuDBJcT6O72DixXDpuMzyEXP20sAcoa5gEnG8PPHsTEIwxquvuwx6O8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786674725; c=relaxed/simple; bh=yZZ20gEfX/mgtu21SNsSoMy2ldceVKlooYLOCpsLcXY=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=HCXRZMs7iJ8kQiu9n6URmG3Yn9h9zPlc6BIEMBVlWheEQ/l/AOR7iA+Cusu0jtkvO38vck1sH75JBEDM1AEX11szatXSzM8WMCNXYKTS0ftalp/NIw9V6823hfp3SaxylFi7yfQHP4FxmftWlXqpu8IHYI70aofEUYT+0rrfDKA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=kpPbP8BN; arc=none smtp.client-ip=198.175.65.19 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="kpPbP8BN" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1786674717; x=1818210717; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=yZZ20gEfX/mgtu21SNsSoMy2ldceVKlooYLOCpsLcXY=; b=kpPbP8BN+xOfGScrG40MmLN3badO3XV4s2HE1Zyq9omHhiRPjR0fNcV+ zXstHu7c4WbzoAqKzXghvT01lswNnqYc59pZM4/vuDDRXuHsmwomNL3HR 1ONAXYuTRCDwGMhgviltYNYo2ORzFy4Fjs2bGHT7Dkvvy7Nuw/htD/IBm PTqRzl2vyisFVx4DK9qmST91MWzDpX26zEi4WxNLVZfReOkuhTj2j8A9x 1IafY8c2ZShgB3NK/mWTx4e6rPoLHHFbOycmr5FasWxreHOczm4C+terZ iPg/+VFE2xgRxY3HmYx6uh6Nyhhw3ruKOSil6J9tHdWTLSn8Kgfj1HeiH Q==; X-CSE-ConnectionGUID: ect4OGqGRGiAwTqkIVy/wQ== X-CSE-MsgGUID: fN7hmp92SqKRrzwE6YLdhg== X-IronPort-AV: E=McAfee;i="6800,10657,11874"; a="87181993" X-IronPort-AV: E=Sophos;i="6.25,222,1779174000"; d="scan'208";a="87181993" Received: from orviesa001.jf.intel.com ([10.64.159.141]) by orvoesa111.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Aug 2026 19:31:57 -0700 X-CSE-ConnectionGUID: U9mtIp3DSx+8I6Ua8ieTzw== X-CSE-MsgGUID: 1o+lvJ99Qr2+wyO7dWK9nA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.25,222,1779174000"; d="scan'208";a="302339630" Received: from tester.sh.intel.com ([10.112.106.126]) by orviesa001.jf.intel.com with ESMTP; 13 Aug 2026 19:31:56 -0700 From: Tao Yu To: linux-fsdevel@vger.kernel.org Cc: slava@dubeyko.com, glaubitz@physik.fu-berlin.de, frank.li@vivo.com, linux-kernel@vger.kernel.org, syzbot+2bf21610eea63cb2ce93@syzkaller.appspotmail.com, Tao Yu Subject: [PATCH 2/2] hfs/hfsplus: stop btree allocators from reusing node 0 Date: Fri, 14 Aug 2026 10:31:50 +0800 Message-Id: <20260814023150.3482810-3-tao1.yu@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260814023150.3482810-1-tao1.yu@intel.com> References: <20260814023150.3482810-1-tao1.yu@intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The btree header node is permanently reserved as node 0. If the on-disk bitmap ever presents node 0 as free, the filesystem is already corrupted and the allocator must not try to instantiate it again. Both HFS and HFS+ currently keep scanning the bitmap, set the bit, and hand node 0 to hfs_bnode_create()/hfsplus_bnode_create(). HFS+ then hits the "new node 0 already hashed?" warning reported by syzbot, while HFS risks continuing after the same corruption pattern. Teach both allocators to treat attempts to allocate node 0 as btree map corruption. Force the filesystem read-only, emit the existing repair hint, and abort the allocation before the code reaches the hashed-node warning. Reported-by: syzbot+2bf21610eea63cb2ce93@syzkaller.appspotmail.com Closes: https://syzkaller.appspot.com/bug?extid=3D2bf21610eea63cb2ce93 Signed-off-by: Tao Yu --- fs/hfs/btree.c | 11 +++++++++++ fs/hfsplus/btree.c | 11 +++++++++++ 2 files changed, 22 insertions(+) diff --git a/fs/hfs/btree.c b/fs/hfs/btree.c index 14114318ec724..9b0b7418ddbd5 100644 --- a/fs/hfs/btree.c +++ b/fs/hfs/btree.c @@ -376,6 +376,17 @@ struct hfs_bnode *hfs_bmap_alloc(struct hfs_btree *tre= e) if (byte !=3D 0xff) { for (m =3D 0x80, i =3D 0; i < 8; m >>=3D 1, i++) { if (!(byte & m)) { + if (unlikely(!(idx + i))) { + pr_warn("(%s): %s (cnid 0x%x) map record invalid or bitmap corrupti= on detected, forcing read-only.\n", + tree->sb->s_id, + hfs_btree_name(tree->cnid), + tree->cnid); + pr_warn("Run fsck.hfs to repair.\n"); + tree->sb->s_flags |=3D SB_RDONLY; + kunmap_local(data); + hfs_bnode_put(node); + return ERR_PTR(-EIO); + } idx +=3D i; data[off] |=3D m; set_page_dirty(*pagep); diff --git a/fs/hfsplus/btree.c b/fs/hfsplus/btree.c index 394542a47e600..3ee92248b2409 100644 --- a/fs/hfsplus/btree.c +++ b/fs/hfsplus/btree.c @@ -561,6 +561,17 @@ struct hfs_bnode *hfs_bmap_alloc(struct hfs_btree *tre= e) if (byte !=3D 0xff) { for (m =3D 0x80, i =3D 0; i < 8; m >>=3D 1, i++) { if (!(byte & m)) { + if (unlikely(!(idx + i))) { + pr_warn("(%s): %s (cnid 0x%x) map record invalid or bitmap corrupti= on detected, forcing read-only.\n", + tree->sb->s_id, + hfs_btree_name(tree->cnid), + tree->cnid); + pr_warn("Run fsck.hfsplus to repair.\n"); + tree->sb->s_flags |=3D SB_RDONLY; + kunmap_local(data); + hfs_bnode_put(node); + return ERR_PTR(-EIO); + } idx +=3D i; data[ctx.off] |=3D m; set_page_dirty(page); --=20 2.34.1