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=1796434294; b=K0CJJUgprALlJdKMCUPaQagKK4IsF6eTx4zndT1V/bQ688ieyVacdrNvfDEEfmEEJMk+ nxb5NcNIR6ZLyu+lxv//WlnXw0iXnDrtCSuzvupGUGfvIGaD9uLMkpl61hrcikVybx91q zst1jEcV6VRE2ooIvrd9cdwlcWWDqRM0SCXCh5qfhXBiJ1TKaqjaQBNZ4YReHQ8Y7nMeU rph3zZ6cECl+e/OgLnp+yHC4NXcnsttxb6PtTNN2NAisvtQlOC1c5B0QrnjalVQzufQrp Tjdp6k+6mcbJeGtlDM+fs9497KS/psh8UL+LeJxmTqj/wk5uuVvu0k7ShQhBBqSQlUg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796434294; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: From:To:Cc:Subject:Date:Message-ID:X-Mailer:MIME-Version: Content-Transfer-Encoding; bh=hSTvMSNUgOKrUWKwYXW7FhgzCLg0V1qe0nL5Qq3wsJQ=; b=GO6avZU7zOlYic9wIPJ6YrGG68sEgXpTGtCXheLIz80qu62uP+ZSmuThPyfKljTMc5oY M0WXZxQqTWv39U4zU0dSO5a2gMYAsALq5l/OPPMlJPH8aPZjhK2V47+a7RdaspjE4G+9w uadQaSznqvrlRDWp1P6b95auUQkklwTtUbNhneNmUNkrUXT9hIyuI5nXMaPTWThImAEvA EjuUyDfbhrPvOZS//+aIud7QAClWxibu5Wocv6vb948L/cddz9GYknpQ+U04KMriLcPEb uCRjxWLLTaKUeha2KbZpA82+WBzfb/RJhCrIKlr4oPhJikUPe+/aJJS7CwIFmH6slag== 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=LRr1IoF8; 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 3A7EE606A32C for ; Sat, 5 Dec 2026 01:31:33 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 3A7EE606A32C 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, unprotected) header.d=dubeyko-com.20260707.gappssmtp.com header.i=@dubeyko-com.20260707.gappssmtp.com header.a=rsa-sha256 header.s=20260707 header.b=LRr1IoF8 Received: by mail-yw1-f176.google.com with SMTP id 00721157ae682-8b4d86f5328so11509567b3.0 for ; Fri, 04 Dec 2026 17:31:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dubeyko-com.20260707.gappssmtp.com; s=20260707; t=1796434293; x=1797039093; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to:content-type; bh=hSTvMSNUgOKrUWKwYXW7FhgzCLg0V1qe0nL5Qq3wsJQ=; b=LRr1IoF8gZxvwXyc0GU/ImcnNm3Ltk0+qvlepIhgNYQeKqv7alb8dC6UlRqJgfZNT3 DA1q37RJv20eEwBMeG3nA2XSOLEl36KkSM9WOdrcSgwyg2RpOn+99fOJzNhqDpuz/MDn w8L3KmQ53cHm6lWUqLGMZ9ZuHNIDtJLpZ7HPrMeV8hKoWdyoo37fHY3voAgbX9Lr/3VF EuDUOZcHFw1Q/nXpKj/nqkElpHqrlx+qFtcDypfSuhLx4dgMyPNEjGMOQz+BXk7m9Fky 8z5sd/pSJX7RS2L6fBVycSFXZPeBF0YV64b+4cO41bES0j4jY7DkgfC64oxv0c07ns2Z /vDQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796434293; x=1797039093; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=hSTvMSNUgOKrUWKwYXW7FhgzCLg0V1qe0nL5Qq3wsJQ=; b=sUYU3CRnchrxwII/Hmk1zU7sHeO8KUzt91/WtaSTvNe0J82FoZ7NkmKfUffl3F749c Y2OuDmgXA1d/3KmkgtF+buYoi6rH01JikopqZYv505sqS1cmU7NvQPjD/Arku6L9WiNG 0OLPFUaCK1RDRwAI6QiVDsBRngrcP7GIkbXZ5Aj3fW5vF+U9FoA4gdhuRQRfwsZ9snAk oTrqHoepXFxlO7/oADwksG/FTxpRtx+H8xlyRsUvBW7CXS5erbRRzndnr3SzzV0pCjfu 3a+i+JJQg4uPASpZDPxZhDXiCo1o0a2vJlwa7QooMBAbZuxfYkMG1petVELIFZG0runr R0CA== X-Forwarded-Encrypted: i=1; AL+hErFqsX2gRagq9lVpxLPXBzTMZ6q/Cgcm3cquaTuMNrXV1zDxgPxONzGzNv319pnh0RLY3V/Puu5eS8cA4ZQ=@vger.kernel.org X-Gm-Message-State: AB4q+uHvfYuKDllpR+wCRb2ZqLO7/PPZhqaLVfBxWKjcbIiWvtn2CB9u WBlB4pCod6CbBpmfUE8z9CuEgCe2t36Ofa+MKT6DjBlaC5TShmQI7ltEwK9HRTE57VmwBVjVSuP LLBSbJaM= X-Gm-Gg: AZFdTZdUhKR6/w+T52Fauw5Rt2S0mR1m3kj0bwfg1XY0sI9jGK0YrRboHGuP21xDrXY 7S052+uUpDVaEvJY8B4dUc/5m8LlIf2vjtTsmP3kSC5r2nk5f52mONWAHARq46IOpmTIGmAC4pq 46btab78tAS9CDWRFG9ShzBZU+zEGmGFlWB6v0viVDeUKSN+7XuP7P8/ngDMAZ6KZaQD7HWrMyx Vs59OoLVMS6eHeGhtLnE2qxqvJ7VKsZGIbdHN/EnHLz/O2PSgWdmZTDBeL6nkhcnEK6CtxJBSm4 QlYL/rujmNGYsjlQyUUIDPJQeyZE9T3Te7Wegl2WXJtmmTaZOVbzGo8WuK3/79ZGP9LuZOplWJK 09WYM/29CbIFr07Y04G5uC+c577EInqslcSX1gqoBxYuD8ka2usgcwj7j+CdI3ORPUgjSxi8xzs 9GLHFTxW4SNWAiUbkhv2+VhumTXl1JVnZqU7wL2kEI2TLwigoB4WC1zV6P7kUIubuJeL4uxtVGC o99loR2DVvBHjRodjXRS7bPBhLJgHZVqqXGiKPkDYfQt7xUezQ0P4vGJRLltL7oRmy4MYL/UdEL IssKC3Wjk966mTJmP5G2gZqY3jsoiw4t51Oo8vFqYwfXPus04jwfAT8L2QtEJbDPz+NoXdPwxQX cMEZzjJudV7PclIvsOryRZUWeT6IZ03ZZReAZ4aRhYzlUC3xuzILjx9YF0VYo3ClR4fBoxEM= X-Received: by 2002:a05:690c:31c:b0:8b4:d584:6182 with SMTP id 00721157ae682-8b660d93149mr19314677b3.41.1796434293057; Fri, 04 Dec 2026 17:31:33 -0800 (PST) Received: from system76-laptop.attlocal.net ([2600:1700:6476:1430:d9f4:eaa9:479c:5d66]) by smtp.gmail.com with ESMTPSA id 00721157ae682-8b660e183acsm17228137b3.45.2026.12.04.17.31.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Dec 2026 17:31:32 -0800 (PST) From: Viacheslav Dubeyko To: glaubitz@physik.fu-berlin.de, frank.li@vivo.com Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, vdubeyko@coreweave.com, Viacheslav Dubeyko Subject: [PATCH 0/6] hfs/hfsplus: fix endless loop on mount of crafted images Date: Fri, 4 Dec 2026 17:31:21 -0800 Message-ID: <20261205013127.1533652-1-slava@dubeyko.com> X-Mailer: git-send-email 2.53.0 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 Content-Transfer-Encoding: 8bit Both drivers look for the volume header (HFS+) or MDB (HFS) by rereading at part_start until they find the signature. An HFS wrapper or an Apple partition map moves part_start by values from disk without any check. If such a value is zero, part_start does not move, the same wrapper or partition map is found again, and the mount loops forever. The mount(2) caller cannot be killed. The HFS+ wrapper case was reported with drAlBlSt = 0 and the embedded extent start = 0. A partition map entry with pmPyPartStart = 0 hangs both drivers in the same way. On HFS, the reread is served from the buffer cache, so the mount spins on the CPU without any I/O. The on-disk layout allows only one order: [partition map] -> [HFS wrapper] -> HFS+ volume header (or HFS MDB) Patches 1 and 4 follow this order step by step instead of rereading in a loop, so the mount cannot loop, whatever the metadata are. They are the minimal fix. Patches 2, 3 and 5 validate the metadata before following it: - Patch 2: the wrapper's volume bitmap must follow its MDB, the first allocation block must follow the volume bitmap, and the embedded extent must be non-empty, lie within the allocation blocks and end within the wrapper. The embedded volume header must have the signature declared in drEmbedSigWord, and the embedded volume must fit in the embedded extent. - Patches 3 and 5: a partition must not overlap the driver descriptor and the partition map, must be non-empty and must end within the device, for both the old and the new partition map. Patch 6 fixes an older issue found while working on patch 5: for the old partition map, hfs_part_find() doesn't stop at the first matching entry, so every following "TFS1" entry adds its start to part_start again. Now it stops at the first matching entry, like the new partition map and the HFS+ code do. Tested in QEMU (KASAN, lockdep): - Unpatched: a self-referencing wrapper (hfsplus) and a self-referencing partition map (hfsplus and hfs) hang the mount, and SIGKILL does not stop it. - Patched: 26 crafted images are refused, each by the check it breaks (self-referencing wrapper, volume bitmap at the MDB, allocation blocks before the volume bitmap, empty or out-of-range embedded extent, embedded volume beyond the device, nested wrapper, wrapper containing a partition map, embedded volume with another signature, missing or larger than its extent; self-referencing, overlapping, empty and out-of-range partitions in old and new partition maps, chained partition maps). - Patched: plain HFS+, wrapped HFS+ and plain HFS, also inside old and new Apple partition maps, mount and a written file survives a remount. Wrappers made by mkfs.hfsplus -w for 4 MiB - 8 GiB volumes and 512 B - 64 KiB block sizes pass the new checks; their embedded volume size equals the embedded extent size. - Patches 1 and 4 alone: no crafted image hangs the mount either. Viacheslav Dubeyko (6): hfsplus: look for the volume header in the order of the on-disk layout hfsplus: validate the HFS wrapper before following it hfsplus: validate the partition map entry before following it hfs: look for the MDB in the order of the on-disk layout hfs: validate the partition map entry before following it hfs: stop at the first matching entry of the old partition map fs/hfs/mdb.c | 31 ++++++-- fs/hfs/part_tbl.c | 54 +++++++++++-- fs/hfsplus/part_tbl.c | 48 ++++++++++-- fs/hfsplus/wrapper.c | 172 ++++++++++++++++++++++++++++++++++-------- 4 files changed, 256 insertions(+), 49 deletions(-) -- 2.53.0