From nobody Sun Feb 8 08:19:33 2026 Received: from sender4-of-o54.zoho.com (sender4-of-o54.zoho.com [136.143.188.54]) (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 5CEAE30F540; Wed, 24 Dec 2025 15:14:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=pass smtp.client-ip=136.143.188.54 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766589281; cv=pass; b=ZHiNX7tIrvv4myL7QbsJv3lsan4FKykImQtXmm3gjivOZMu/QKjof5I6VKvQ6Usa34AB1ew9vbHjeTJV+fUV1aJmkshnZsdY4dB03QBb5qeAf+7lIQCsECzDZRjpe78rEqftaCqtXkHHExcMryXJ+JDskOHCde7w71blb6upkRs= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766589281; c=relaxed/simple; bh=WPGWhm3kolC3HIOnVmDBcTF/0kkr+8NEvNc5vqyq8tc=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=BySK1YSQjhVVkZfvDlGFaaXgl6k7ISTr4OOmrHJG54Egk8mFO3WbpG2n9SbKrl0dv7v2qwCcNf6wZVseNAfmVBna/uKcOLi7yqtalZREuuOLgBOPAmHUupVVYgi7luytLi8sCPWD+XkrpjhmnAK+jDNM0xi9hPW25MxbLCko7oQ= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=mpiricsoftware.com; spf=pass smtp.mailfrom=mpiricsoftware.com; dkim=pass (1024-bit key) header.d=mpiricsoftware.com header.i=shardul.b@mpiricsoftware.com header.b=Nlxx43tU; arc=pass smtp.client-ip=136.143.188.54 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=mpiricsoftware.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=mpiricsoftware.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=mpiricsoftware.com header.i=shardul.b@mpiricsoftware.com header.b="Nlxx43tU" ARC-Seal: i=1; a=rsa-sha256; t=1766589250; cv=none; d=zohomail.com; s=zohoarc; b=jFcwyYS1SIvB06RAl4mUh7plXe9h1VVj3/Eq5nex/ehU9DVfB2eKhXo91mUfmUnCR4zD66Vul0Xq83OBK2R5iYWXjPcRx3tno1rthC4E711LkFSrUrBrbGC/Da35C4fpKOr6Y84Hh+J9qKakOAHKdrZ2Jdd9NGDlGN0E2pUSRVg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1766589250; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:Subject:To:To:Message-Id:Reply-To; bh=w9IsnJ/aVfBvOceN//c8GNS4LLhNppxpUDjXrHQw1rI=; b=aLuyJ/o+NFkraLM+NE6zfGaMYEl2m/0JCSGkBlKls7i7oD6up0lzYqi3ug1r6xbc0ZfN2lGBJFGuON5IDg6xHGGGepyNISkkmrM9oM+bmALRKitdIXBDyW4izAmu463nuioYz6wPA7hs30VmUb5WkVmSptqZkC4gkELZZ06W2hg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=mpiricsoftware.com; spf=pass smtp.mailfrom=shardul.b@mpiricsoftware.com; dmarc=pass header.from= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1766589250; s=mpiric; d=mpiricsoftware.com; i=shardul.b@mpiricsoftware.com; h=From:From:To:To:Cc:Cc:Subject:Subject:Date:Date:Message-Id:Message-Id:In-Reply-To:References:MIME-Version:Content-Transfer-Encoding:Reply-To; bh=w9IsnJ/aVfBvOceN//c8GNS4LLhNppxpUDjXrHQw1rI=; b=Nlxx43tUJGe/t719lYBTnFOLkJaMj0cFYQVoWYY/v37ZXE8nJgSkzGPl3TAesOfA vbwfxLQwR+JtKCbkRq610A9ZL+MtRCPd7Tzv80PQ8orP1tgLmbICoFhgEAZu/SIqg9N 04eZlWvNEv1K73UaHtWweI5yTwmcBDlQydKyIapM= Received: by mx.zohomail.com with SMTPS id 1766589247444212.342196029001; Wed, 24 Dec 2025 07:14:07 -0800 (PST) From: Shardul Bankar To: slava@dubeyko.com, zippel@linux-m68k.org, linux-fsdevel@vger.kernel.org, glaubitz@physik.fu-berlin.de, frank.li@vivo.com Cc: akpm@osdl.org, linux-kernel@vger.kernel.org, janak@mpiricsoftware.com, shardulsb08@gmail.com, stable@vger.kernel.org, syzbot+1c8ff72d0cd8a50dfeaa@syzkaller.appspotmail.com, Shardul Bankar Subject: [PATCH v2 1/2] hfsplus: skip node 0 in hfs_bmap_alloc Date: Wed, 24 Dec 2025 20:43:46 +0530 Message-Id: <20251224151347.1861896-2-shardul.b@mpiricsoftware.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20251224151347.1861896-1-shardul.b@mpiricsoftware.com> References: <20251224151347.1861896-1-shardul.b@mpiricsoftware.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 X-ZohoMailClient: External Content-Type: text/plain; charset="utf-8" Node 0 is the header node in HFS+ B-trees and should always be allocated. However, if a filesystem image has node 0's bitmap bit unset (e.g., due to corruption or a buggy image generator), hfs_bmap_alloc() will find node 0 as free and attempt to allocate it. This causes a conflict because node 0 already exists as the header node, leading to a WARN_ON(1) in hfs_bnode_create() when the node is found already hashed. This issue can occur with syzkaller-generated HFS+ images or corrupted real-world filesystems. Add a guard in hfs_bmap_alloc() to skip node 0 during allocation, providing defense-in-depth against such corruption. Reported-by: syzbot+1c8ff72d0cd8a50dfeaa@syzkaller.appspotmail.com Link: https://syzkaller.appspot.com/bug?extid=3D1c8ff72d0cd8a50dfeaa Signed-off-by: Shardul Bankar --- v2: - Keep the node-0 allocation guard as targeted hardening for corrupted ima= ges. fs/hfsplus/btree.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/fs/hfsplus/btree.c b/fs/hfsplus/btree.c index 229f25dc7c49..60985f449450 100644 --- a/fs/hfsplus/btree.c +++ b/fs/hfsplus/btree.c @@ -411,6 +411,9 @@ struct hfs_bnode *hfs_bmap_alloc(struct hfs_btree *tree) if (byte !=3D 0xff) { for (m =3D 0x80, i =3D 0; i < 8; m >>=3D 1, i++) { if (!(byte & m)) { + /* Skip node 0 (header node, always allocated) */ + if (idx =3D=3D 0 && i =3D=3D 0) + continue; idx +=3D i; data[off] |=3D m; set_page_dirty(*pagep); --=20 2.34.1 From nobody Sun Feb 8 08:19:33 2026 Received: from sender4-of-o54.zoho.com (sender4-of-o54.zoho.com [136.143.188.54]) (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 470F3346AD5; Wed, 24 Dec 2025 15:14:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=pass smtp.client-ip=136.143.188.54 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766589300; cv=pass; b=YF0D8022UGUa/RiqYIHmMZv4rTMjuHCwrbAVyDaWRmM10i6DpNtV86bp1tVQ0dZzubsWavuhxo7OOTV8B1E+U09/0GOIN/HWf7KnuvXmtJ/5bHQ/vRgthxzV9gRAuau9AekpjVCuPhe0fa6NlbaTGwZYzY/mzvx4EJIUej5OHy8= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766589300; c=relaxed/simple; bh=VcIpv93cs+iZCQNZMb5+B7ptBS8sL8Okxk8HsgsphSQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=JrbHw81PpPrVFRK5ddP2XIYdXxSvhoDfk3NNNV+Etr435SfxayC2JARLDoNZWwIqw7KiH7N+/xTTEk5sZnPLQKT+/XPHu1t3PIZOiotENLRvV19QB3NPVXOi6JetLvwfNahmQqPQsbU3C3jqLi48fok7XX+HSEJ9GDr5A9k8efE= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=mpiricsoftware.com; spf=pass smtp.mailfrom=mpiricsoftware.com; dkim=pass (1024-bit key) header.d=mpiricsoftware.com header.i=shardul.b@mpiricsoftware.com header.b=uPUEXpZI; arc=pass smtp.client-ip=136.143.188.54 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=mpiricsoftware.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=mpiricsoftware.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=mpiricsoftware.com header.i=shardul.b@mpiricsoftware.com header.b="uPUEXpZI" ARC-Seal: i=1; a=rsa-sha256; t=1766589258; cv=none; d=zohomail.com; s=zohoarc; b=G/DeQEYHrOMAYl/3ZEvGu+utIxKVXG+UCn0eXBMwXBU95Zlf5AC0mcAZuRQmkXAlT4WvilWegF4uQoY8+QxBg5M0Ond8UgbKt0PIRLhWEuWtdwilkmUlCwg0DE6+lX59P6q9qCE2O3IpR9BMHhyApbkVb2/kZujz1PBhwhJdGvA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1766589258; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:Subject:To:To:Message-Id:Reply-To; bh=9UERILc8qj7pv/Dyd3F97ap3cBIOjg4t7GFeSU5EK6I=; b=duOh47NQ90lEnezBrpHFfEtnPdLBzIdRYOicLsDnw5J1ydXSdudgld9N2F5+RZslBHaKFz8GofBQnBcAbpwNV4kGpT+zplOOOo1LNORxORMf6Nr6ZzRGSbOWwODs2IH0X4ms/DZuOIQN24E2XStkeEUxdOdEd2h4brXlMuR4uXs= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=mpiricsoftware.com; spf=pass smtp.mailfrom=shardul.b@mpiricsoftware.com; dmarc=pass header.from= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1766589258; s=mpiric; d=mpiricsoftware.com; i=shardul.b@mpiricsoftware.com; h=From:From:To:To:Cc:Cc:Subject:Subject:Date:Date:Message-Id:Message-Id:In-Reply-To:References:MIME-Version:Content-Transfer-Encoding:Reply-To; bh=9UERILc8qj7pv/Dyd3F97ap3cBIOjg4t7GFeSU5EK6I=; b=uPUEXpZI+MWj6t06z7EvFwOlSmKs8btpE5o2Q5u0CExK6Is1/LkoovzUusDn+Xcv +AkKsBoX0e31f12kz6jACuSZqzzum2oO044oY5Zj7LhG1iJuGpVn/fxyvulC0mF2n2/ 7ZfWRzr/vzOwxaZxHUQZPapGc9JCl9gSCTHNPZsw= Received: by mx.zohomail.com with SMTPS id 1766589255667993.4447172420538; Wed, 24 Dec 2025 07:14:15 -0800 (PST) From: Shardul Bankar To: slava@dubeyko.com, zippel@linux-m68k.org, linux-fsdevel@vger.kernel.org, glaubitz@physik.fu-berlin.de, frank.li@vivo.com Cc: akpm@osdl.org, linux-kernel@vger.kernel.org, janak@mpiricsoftware.com, shardulsb08@gmail.com, stable@vger.kernel.org, syzbot+1c8ff72d0cd8a50dfeaa@syzkaller.appspotmail.com, Shardul Bankar Subject: [PATCH v2 2/2] hfsplus: return error when node already exists in hfs_bnode_create Date: Wed, 24 Dec 2025 20:43:47 +0530 Message-Id: <20251224151347.1861896-3-shardul.b@mpiricsoftware.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20251224151347.1861896-1-shardul.b@mpiricsoftware.com> References: <20251224151347.1861896-1-shardul.b@mpiricsoftware.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 X-ZohoMailClient: External Content-Type: text/plain; charset="utf-8" When hfs_bnode_create() finds that a node is already hashed (which should not happen in normal operation), it currently returns the existing node without incrementing its reference count. This causes a reference count inconsistency that leads to a kernel panic when the node is later freed in hfs_bnode_put(): kernel BUG at fs/hfsplus/bnode.c:676! BUG_ON(!atomic_read(&node->refcnt)) This scenario can occur when hfs_bmap_alloc() attempts to allocate a node that is already in use (e.g., when node 0's bitmap bit is incorrectly unset), or due to filesystem corruption. Returning an existing node from a create path is not normal operation. Fix this by returning ERR_PTR(-EEXIST) instead of the node when it's already hashed. This properly signals the error condition to callers, which already check for IS_ERR() return values. Reported-by: syzbot+1c8ff72d0cd8a50dfeaa@syzkaller.appspotmail.com Link: https://syzkaller.appspot.com/bug?extid=3D1c8ff72d0cd8a50dfeaa Fixes: 634725a92938 ("[PATCH] hfs: cleanup HFS+ prints") Signed-off-by: Shardul Bankar --- v2: - Return ERR_PTR(-EEXIST) for already-hashed nodes, per Slava's suggestion. fs/hfsplus/bnode.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/hfsplus/bnode.c b/fs/hfsplus/bnode.c index 191661af9677..250a226336ea 100644 --- a/fs/hfsplus/bnode.c +++ b/fs/hfsplus/bnode.c @@ -629,7 +629,7 @@ struct hfs_bnode *hfs_bnode_create(struct hfs_btree *tr= ee, u32 num) if (node) { pr_crit("new node %u already hashed?\n", num); WARN_ON(1); - return node; + return ERR_PTR(-EEXIST); } node =3D __hfs_bnode_create(tree, num); if (!node) --=20 2.34.1