From nobody Mon Jun 8 12:13:19 2026 Received: from mail-pj1-f52.google.com (mail-pj1-f52.google.com [209.85.216.52]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 53F073CC7C5 for ; Fri, 29 May 2026 10:34:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.52 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780050878; cv=none; b=YNGTptGLyvVTvOYk/uQGwUCwvaV4L2+FTWhzoLeVVV6dJZZYSyxHY0NChNCR8p0sTtpOTqCmQoeev1Lms5gH0WuRuRxVCIg6LRpy5kWhqfaf/MDN7a3bRNwhef5IumS7EHibL+XK9cOaY3RdaEkpct86HtD3kbF5y5Iy9QgVLcs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780050878; c=relaxed/simple; bh=D4zfUYIEN/mIaPy6DoDtc6mWSSCyswWUAMZ2tPkZ+ac=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=IEqayvfOFL6xut5JHKZdTqN9EOtg9Qq+u6TyXKUIqGPQ2Ddw7WoiqKtRuJ/7oxPwIFOLtBq9AMuS+dgwSEiopFIiTJLi7/4MiSB1eC7PJJroO/Kex5NU+FNy89IcfVl/+KSEqvvcscYwypYAhDOofm/PYTghUd1ick/k/nvJ51Y= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=DRIthMbR; arc=none smtp.client-ip=209.85.216.52 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="DRIthMbR" Received: by mail-pj1-f52.google.com with SMTP id 98e67ed59e1d1-36ba285e98bso1293886a91.2 for ; Fri, 29 May 2026 03:34:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1780050875; x=1780655675; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=c3Z726G551crwtbnFq7Jxy9FfHStJjoYfTJWDW9cd50=; b=DRIthMbRhkXBf2hLHm93qxXWpAQlzz5do8v6lH6toRZ+QtmmLM6Wr1Hs3vzS/qSW8k CorBA+mGc9hYtmwG2cNj/YYps+oJd1veKQk/wAIuqREd+xKWLwhYm4AZ9KsNmsdnP6/h WOb860HroBlB4LE6C7zs6g4YsoWcr8UwB9CIgTpMiy0/grCKfBspuCy3GtkG4KLBG4ej SYndR+ttxB0rVNNlWVBr6gv6zBNMjjHoElnFFaR3K7q+Vp8IcOo8PORAsHTxYovwKPpH XSEA439TFnSjVLlZ2oOQzDlD4WPv07W16IKrFXV4DJDkQVSgTH3ZMzvXWEQmf5IMKy82 TLzA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780050875; x=1780655675; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=c3Z726G551crwtbnFq7Jxy9FfHStJjoYfTJWDW9cd50=; b=a01VLMsV8SxiKk10HIIOhs6KvY8K4EpV/cJeEe1Q9dYPgdGJ1y0d1dE3hJsQqyylU9 enAIUTQYral9tG46cVZtjWE7uTHKfVH8V9Nh83ydWQL/MJYSCFsLGKotPjPr9qeICsXk KaOqGgkCiVZVyAX6NE+jDoBGuQnZA2XpyJVH0yNcuo0n3VFtERZQ+I1IiJWL79DjJj/X 84YbvbFYEOTAqTC0abNJ/Pq7iou3QAL28iCXJSA1z0Q9QOnzyHqQubBXh5r5TYgPNSkQ YbUA+rrWO4hZO8VoRhD+oOw2DHtV9jNjmPnpIuLm7dGCbbag7Vr80fvVwwgko1q80JdR ZcZA== X-Forwarded-Encrypted: i=1; AFNElJ/zfaWJnKAZFbXJjUIak2KAT+vBQs30c1zCGJZat2kWwu7lD+irPHPR9RfXG5YGaim3J2468tPwms/JckI=@vger.kernel.org X-Gm-Message-State: AOJu0YxN3GKiQlUEp+en1VxADg0dMORBXn+3Iz/vvaQSLA1aPr1579oe f83KxpHLlHFg3KNhFoM0+lh2VhaiuyNmM8XcVYSdyx3fEBGzQ6ERVFiz1n6Bw5Em X-Gm-Gg: Acq92OGPmGRWn9l0c8xTTz3KdOn5WwGnAYyv70FXpxWtKjbKndQ0dUNQe0P9GzE3pQs 9bLdiYK4Ur4kM1rJX4+dAkvLvdD9I+skVefUFhG++q2yhPfgpEA0iYVbPSFahDB0CqE4Fo6PhTa IKKOUkbRDhwE4UznJI3aAWK0eo6EQZPUruomN1Qc7VGEwMVNvOgF3wbt3VDJ6YTYItnEH33euri iGUXo7OxgaCQQuMbHs8G7Q29uta9VE4szQKsSffiiJwglH4fTzGS5eLLORUcMgC0cMGP6g/z2d6 6YCJQvU9lBE97GHR21R7ob92GUH/vsjWSeWLMnhuB+v0B2kTnQfTmtV2y9LM4IUtZGOaEz7OwmN QzA3n9DxlaCioz+z9y0v/16u/KNYroFfiFdl9XpUpx9lKO8mzk0GPkmyAS7sbsvv4a3YgNSAk/K ejuNnFgsZo2UR4nPE0/RodzWoRwhJBVPgN9odsWIYO/U6TLw== X-Received: by 2002:a17:90b:3a50:b0:369:a359:b192 with SMTP id 98e67ed59e1d1-36bbcc160damr2878751a91.10.1780050875433; Fri, 29 May 2026 03:34:35 -0700 (PDT) Received: from gmail.com ([218.106.182.247]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-36bbfc90570sm1827392a91.4.2026.05.29.03.34.33 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Fri, 29 May 2026 03:34:35 -0700 (PDT) From: Yue Sun To: slava@dubeyko.com, glaubitz@physik.fu-berlin.de, frank.li@vivo.com Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Yue Sun Subject: [PATCH v2] hfs: prevent MDB and bitmap buffer_head aliasing Date: Fri, 29 May 2026 18:34:17 +0800 Message-ID: <20260529103428.99099-1-samsun1006219@gmail.com> X-Mailer: git-send-email 2.54.0 In-Reply-To: <1d26872db999da42b2d8452ace8a98b79e569cc8.camel@dubeyko.com> References: <1d26872db999da42b2d8452ace8a98b79e569cc8.camel@dubeyko.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_mdb_commit() writes the volume bitmap while HFS_SB(sb)->mdb_bh is locked. A crafted image can set drVBMSt so that the bitmap block resolves to the same buffer_head as the MDB. When writeback later calls lock_buffer() for that bitmap block, the task tries to lock mdb_bh again and self-deadlocks in __lock_buffer(). Reject images whose volume bitmap starts at or before the MDB during mount. Also guard the bitmap writeback path itself: if the bitmap block would resolve to mdb_bh, force the filesystem read-only and stop bitmap writeback before taking the buffer lock. This keeps the deadlock fix in the MDB commit path and reuses the existing bitmap size/writeback logic. Reported-by: Yue Sun Closes: https://lore.kernel.org/all/CAEkJfYMB47v1yOWHB8q2dc8kf=3Duj-rLO=3D+= yMyudwPguJ8Kd3jA@mail.gmail.com/ Signed-off-by: Yue Sun --- Changes in v2: - Add a commit-time guard before locking bitmap buffer_heads. - Replace the mount-time byte-range check with a simple drVBMSt check. - Reuse the existing bitmap writeback size calculation. fs/hfs/mdb.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/fs/hfs/mdb.c b/fs/hfs/mdb.c index a97cea35ca2e..53cd137892b5 100644 --- a/fs/hfs/mdb.c +++ b/fs/hfs/mdb.c @@ -185,6 +185,11 @@ int hfs_mdb_get(struct super_block *sb) sb->s_flags |=3D SB_RDONLY; } =20 + if (be16_to_cpu(mdb->drVBMSt) <=3D HFS_MDB_BLK) { + pr_err("volume bitmap overlaps MDB\n"); + return -EIO; + } + /* TRY to get the alternate (backup) MDB. */ sect =3D part_start + part_size - 2; bh =3D sb_bread512(sb, sect, mdb2); @@ -341,6 +346,11 @@ void hfs_mdb_commit(struct super_block *sb) size =3D (HFS_SB(sb)->fs_ablocks + 7) / 8; ptr =3D (u8 *)HFS_SB(sb)->bitmap; while (size) { + if (unlikely(block =3D=3D HFS_SB(sb)->mdb_bh->b_blocknr)) { + pr_err("volume bitmap overlaps MDB, forcing read-only\n"); + sb->s_flags |=3D SB_RDONLY; + break; + } bh =3D sb_bread(sb, block); if (!bh) { pr_err("unable to read volume bitmap\n"); --=20 2.34.1