Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.224.42 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796434303; b=yyIDpoiwpM0gkBL57u1CbeobVCi4BwkQzHftX0m/Y1nP97j256sZm0r0AD9m7DPH57nJ 7pMNiJQY8W+pwzygluKIv6JnVoMNZlo0itBMIeb3p81bp8wPkXmAI+f08ShnqKl7UAak5 7uJfcSg7qDvj+uEYeS3N9npYlVZ0E9QLyZZS9f5RlQjFE2N6wLdSvabtNRix2s4NnZxrI jWPpW20Bha4wScIhOd+2mZxIsutxxykjsNyo+GAgtMROyypx3iWG/1nSYGMwRQQRY2jBh JL7GC6DZCtM5EaBnFPlTS41k7xGCmJ5hsRbMiE2ePO4uU36mZEXu3W7BN/yNZ01vGOg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796434303; 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:In-Reply-To:References:MIME-Version: Content-Transfer-Encoding; bh=7rAuG1yncFvGvj7SkIG4E0tpkWPeWfXnqC3pza8P4EA=; b=FLEwbg+k1uWylK+PNe4I7gCOr95JX8L/JXY7X9nynzlX4EDx3GKxT0fk4/VmeXJcLSOu Lnv4iEHzFobRtaXZL8BjpOar+ieBQr0wRtroigyedYsKEIYM1prtPI2HrH+W42fUP0qHu Ox7bsM5PsiTilCTTqCkLwUph7LSo8UpXRRYbmPdUqEMC8admslA0sOVi0Rs1c6h1B2FnE rapIzKhSuXFKPJlvnny2Q+AF1AjduunSpPDqWnPdK3NsKmiCUDSyTWe1VhYy9fL4FEFPF 0QupZkV/oy+dGDYHqp5GyUgMiSRrVlEEp6w1kHCNjCJx6XrWMB6sg7ccOCf4Q/hFQLA== 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=RE51DOwp; arc=none smtp.remote-ip=74.125.224.42 Received: from mail-yx1-f42.google.com (mail-yx1-f42.google.com [74.125.224.42]) (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 D37E0606A6AC for ; Sat, 5 Dec 2026 01:31:42 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org D37E0606A6AC 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=RE51DOwp Received: by mail-yx1-f42.google.com with SMTP id 956f58d0204a3-677bc4704cbso1657950d50.0 for ; Fri, 04 Dec 2026 17:31:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dubeyko-com.20260707.gappssmtp.com; s=20260707; t=1796434302; x=1797039102; 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:content-type; bh=7rAuG1yncFvGvj7SkIG4E0tpkWPeWfXnqC3pza8P4EA=; b=RE51DOwpCEccbFJq3phVITS7lembxRTCCf0RzAAT5LSpbLvz4jbs6oxQPTTE5dEp0x n7JaQIvRO66PqOSacE8afjtFMWLL1s+D+yhcjP0qaUt+aOajoTHP8tG7C8n1h2+D7pSH X8si36KhGZsgiJJVVueZ+iwXgT8S5EEAW4fHz1DFcBueWbe4ALNq2GgLEpeLCbDu84EI 5rVMaT+C6mkzD4ANsuaBt7llshev2yf6NejTTnQ9VLTpsd18YwhBa+jLFmXviDXyQxAP zs8MCgtV2za648dSkVhk7CJGemm6Yz4getxTQDNL2XWrdCHYd5tu9XmwD3UZmbUuHKr8 8T9Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796434302; x=1797039102; 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:content-type; bh=7rAuG1yncFvGvj7SkIG4E0tpkWPeWfXnqC3pza8P4EA=; b=fKubfMdYFVYMNX1afhuKsL/Kypza/ZtEMdPzU9Bc5QrQeOASpfKiHvQv985SvqrboI inyD+RJzTisvUXA3UkjeYF4x9Siyfc843qaq///3WcT6n7Dg7n3y0m6tmxwezRM4BF5d VgqJ5A9j1RL48vq8397XeA10Rug17LNNIe4c9ygmInGcQrmdYqgJfkJUMWPRvbFmPSFU 2JBDKObC0EdHR81wWWX1SJrirvSdwfqjGbhHJVjf67wEDTgP/+h7POuo2SzpwuLzwTeG iEPd670BEIOmgTqvMYtfxF66AL5AmsrGHOyzgHCVqEGN9JnF+9meATnLtHcAEBCb7qvq bIBw== X-Gm-Message-State: AB4q+uFQuSuKUYfJnNoLgE1DRmLxG8VTFLXv8zb2LVxeOaZu/I2NH4zV KYQUxAJofMVPwEDWubyxjdctKP73jCHfnpidL1tC+LHqNKciT8hCeZJO7kD0YAPljA0= X-Gm-Gg: AZFdTZfaynlJetZJW2qeNIIk2XpebbGIitgcqsEeqTZOv9HWpg8bFSW8NX856XiBSI3 WrCq6uBNHeS1fZWUeAZPSpYNVTs0tU7Bc01P0Aba3x6IBIEQ7C0uQ8QydS7COtjj6u2Ha7QM4hM eMhAPbPODEeaeIWhwEdvmZH4jw3U+ttF9jIZes9ICtUIKcgDBjfshNTMRs9tGBZ/ndArhrIa+jB O1O/6rDxSdPz9SqbVwMHhX9RIDDDkCoLwLl+BMSS0LodPQZV/plCtBVDBHOG2m8ZuWj7UY7OQa6 1qA4uvwlSAoDtp29l2s2syzJZu/5vFP9HoPGAECpFgccDRdK4ik760+VtLGsrLJ1WAPQfiBNFXm nBWJBuK6EPH63xLQcBazBPHdCUQiJe9Em/UuGgFrIybhYPavNalpNPtFmSaAdEGr8AaY3H0nT1K ZBu0a3Jrg949+1nnTjl6DBmRAIwYtb3S+14nB4MYAc2RGeeQ2T5MUk5jzgZioPkbW8X0z/nuyzF o4vEgMawZ91hKQSHvYUdqi/S1nq91liGIVxXGHL5J/K6Fh/2Kh2STO+CmdimnhQJn8aNNSarjXq KrDjn03sSLiYHS/rs+mUr7fO+1n5arns/mNoyS+emKhZNd1S3VMCoSb7lBs5tEuRqe/zBHWpf4m J+RtQTtyjAJyKcB2lSovry5EQT8J4+Zf9bPQIZgAZtU+X0VVF6jtLyEXFo3/pg4y1MDpPlR8r X-Received: by 2002:a05:690e:47a2:20b0:674:1fdd:6116 with SMTP id 956f58d0204a3-67f7242507cmr891094d50.100.1796434301928; Fri, 04 Dec 2026 17:31:41 -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.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Dec 2026 17:31:41 -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 , Aymen T , stable@vger.kernel.org Subject: [PATCH 5/6] hfs: validate the partition map entry before following it Date: Fri, 4 Dec 2026 17:31:26 -0800 Message-ID: <20261205013127.1533652-6-slava@dubeyko.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20261205013127.1533652-1-slava@dubeyko.com> References: <20261205013127.1533652-1-slava@dubeyko.com> 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 If hfs_mdb_get() finds no MDB at the start of the device, it calls hfs_part_find() to look for an Apple partition map and reads the MDB at the start of the found partition. The start and the size of the partition are used as they are on disk, even if the partition overlaps the partition map itself or goes beyond the device. A partition cannot overlap the driver descriptor and the partition map, which take the first sectors of the device, and must end within the device. Check this for the found entry of both the old and the new partition map, and fail the mount if it doesn't hold. Reported-by: Aymen T Link: https://lore.kernel.org/linux-fsdevel/45bfa4d7-e9e2-45f2-9e12-a794defae64a@gmail.com/ Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2") Signed-off-by: Viacheslav Dubeyko Cc: stable@vger.kernel.org cc: John Paul Adrian Glaubitz cc: Yangtao Li cc: linux-fsdevel@vger.kernel.org --- fs/hfs/part_tbl.c | 53 ++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 48 insertions(+), 5 deletions(-) diff --git a/fs/hfs/part_tbl.c b/fs/hfs/part_tbl.c index 36add537d153..05c4c360bd68 100644 --- a/fs/hfs/part_tbl.c +++ b/fs/hfs/part_tbl.c @@ -9,6 +9,8 @@ * a patch contributed by Holger Schemel (aeglos@valinor.owl.de). */ +#include + #include "hfs_fs.h" /* @@ -49,6 +51,28 @@ struct old_pmap { } pdEntry[42]; } __packed; +/* + * Check that partition @part_index, which starts @entry_start sectors after + * @part_start and is @entry_count sectors long, does not overlap the driver + * descriptor and the partition map, which take @map_count sectors from + * HFS_PMAP_BLK, and ends within the device. + */ +static bool hfs_part_valid(struct super_block *sb, sector_t part_start, + int part_index, u32 entry_start, u32 entry_count, + u32 map_count) +{ + u64 map_end = (u64)HFS_PMAP_BLK + map_count; + sector_t part_end = part_start + entry_start + entry_count; + + if (entry_start >= map_end && entry_count > 0 && + part_end <= bdev_nr_sectors(sb->s_bdev)) + return true; + + pr_err("invalid partition %d: entry_start %u, entry_count %u\n", + part_index, entry_start, entry_count); + return false; +} + /* * hfs_part_find() * @@ -80,8 +104,18 @@ int hfs_part_find(struct super_block *sb, if (p->pdStart && p->pdSize && p->pdFSID == cpu_to_be32(0x54465331)/*"TFS1"*/ && (HFS_SB(sb)->part < 0 || HFS_SB(sb)->part == i)) { - *part_start += be32_to_cpu(p->pdStart); - *part_size = be32_to_cpu(p->pdSize); + u32 entry_start = be32_to_cpu(p->pdStart); + u32 entry_count = be32_to_cpu(p->pdSize); + + /* The old partition map takes one sector. */ + if (!hfs_part_valid(sb, *part_start, i, + entry_start, entry_count, + 1)) { + res = -EINVAL; + break; + } + *part_start += entry_start; + *part_size = entry_count; res = 0; } } @@ -96,9 +130,18 @@ int hfs_part_find(struct super_block *sb, for (i = 0; i < size;) { if (!memcmp(pm->pmPartType,"Apple_HFS", 9) && (HFS_SB(sb)->part < 0 || HFS_SB(sb)->part == i)) { - *part_start += be32_to_cpu(pm->pmPyPartStart); - *part_size = be32_to_cpu(pm->pmPartBlkCnt); - res = 0; + u32 entry_start = be32_to_cpu(pm->pmPyPartStart); + u32 entry_count = be32_to_cpu(pm->pmPartBlkCnt); + + if (hfs_part_valid(sb, *part_start, i, + entry_start, entry_count, + size)) { + *part_start += entry_start; + *part_size = entry_count; + res = 0; + } else { + res = -EINVAL; + } break; } brelse(bh); -- 2.53.0