Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.128.169 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796434295; b=m7uFjAI23KqLEvrpikCE9fcVfJ31JENuDx3j75AlMES8mJ0XgKLrhwbb0VtlPRdLZZT5 8QYBzQUV7SH4L/15QCenT35dVd7fhttDKJ6Lj8JqVQwb0WlNV5DnAYhAgZTfPYHxWiGPD doJ4CjiGygfRUGeakVIW1ayBcId95ksGStWobT1Qehb1XWmHsP1hLXN23mtLjQO1utbGJ UDgNN41cFfRE1+FQnTZejl+QrktjntqT8YQR7jm6EvKnmQA2df8NEQXJyt6dnxtuokaBT tS3rXsvxMV8b3suV0nnpZacKa+FL2borJqdv+IisXmQCmhzeTtjEezENHbgcNAPuWgQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796434295; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: 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=D1E0ilPN4lsNhuLiXc7DHVoIg4iMOJt8dWXRfea8x4PDA8DzO0CCqh/YHQzLt64am+Bc L43tTrLxJjLu3kGSnKbIvcIQXtLRAHVdSRMgGymEgYOlVp4jxfIO31xDUq7VIpfTpWOsu sRZ9QMsFJgHZPNss1hwj/KY3abnkg2ODrY03lrheh+Ts7Bf60yXEgrQHZtlSr+sRPD7Pr inIEomnT6NrJu2FQn8TpVFzW/PxOPMMbwRtDRkXXnqclrW1PrBeYL9q9c982Wz28uDsmp n96v8rDGXBIIm9CqXU9U1Y6PO8Xn9NUJaqqoR04VvaD75kWUZD4N90Y0SubrUExyZvA== 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.169 Received: from mail-yw1-f169.google.com (mail-yw1-f169.google.com [209.85.128.169]) (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 2F21B606A322 for ; Sat, 5 Dec 2026 01:31:33 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 2F21B606A322 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=LRr1IoF8 Received: by mail-yw1-f169.google.com with SMTP id 00721157ae682-8b503e2a87bso15652447b3.3 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=xlbQW+XM4TLHf6fqb1ju8K2qz5OiIcOHu0SGdlpBCcsqg4t3kcTQb8Y/ykJncNObI9 akl1VHLI/BG9NesJg2F33Qjac0k3KKDwi54W8LsxAwwbT5QdD2Nx4H65Jbv8on4tUnTB BeXs1IWj2/8Ref0gX7K9dKPcgibWuYMAfa+xEUwa2U5B5PLU6Cyb/Ssk/8hP+idNI4Yg yod6Pq053Mhb3zBDZb1sGJb6QyoV9WlC3MwYKOQAHuA+4CJcWNjxL7bQE0qfUKXi79Np +qSq+V9IN4hYbBnoz5O3upH8RmEzjqSIaIB6JGG//cHDYzlRA8qZBlVheLj44KVCyzCs zRoQ== X-Gm-Message-State: AB4q+uHaCFQcMhd/tQwnCZiYiXFa3/kUmWCJP0tSy83l00V0USVslam3 RFBNzBytRYpK8lqgjGPeoO7cGiHZNc+pI7wWUEEcqftyCduTYiJa4IaDucm3+++1/4E= X-Gm-Gg: AZFdTZfHgvfXphfbgizyHp+We4fBJoKQkIOzjEDmxrY9JEpVkcvMOpvKTy3FxJ1fpeg BY9ScYEQGfY5UaDV3rXaX1wBubofZWjKiNNLQzvdjscpjpgc7RVRUB1qO0FT6OpCimem2w2qv/i SZVSv+suTWhJfhWeZOaY2ZXKxBHtI3q9QHpguBJu7Rakv+TksN6JIp5ptrNpfeXNCKrzyxmfm6o zQ7smXeNnGExc/cUieItMZiC5imVCzX3lpi5TBmA1E37SwAmkFe9KbOkCPobeASqJtiGbBFdUgI /D0/2r0jp0OGYNpOjFcGkyc/ACyqmnIKpnFGo5o7YoXJBI11pbnImr4pkaLCYZqY6uUEopBZU02 KvetF0yWJM5ALjL0Qh+2TlA00yZaDAjHCxN6N63bFPIITMOuenv4sSIUQTI4vjB8QWUyzhFg2Ua gXQn8pGtONrtk1fF8ctevA663fSu5plgji5a1O07JR6J0xxCuvNXzYyD/hYlnbuoZ3lI6VS7K+9 FUmSPacL+lI8GF8mcBQv8nR7EgOTeJ8Aq3jd0rq9hSUZApLmgT3DKNx02ZC4w3IZ5OWd/+pMbRo MfOr7AfJe2XmIvo3w+TyXGRCtiAOH63jpwWwFnO1wUxGMTLsh4CuQAJwrqkVYpQ8DsJH9ZCu185 sMLznco+tHn9PesFTh4fvpy0wse6vMUcNChe69xHtVBOyzF3JVt5QEoJ1cMqLt0qEwlA8mX8= 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-fsdevel@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