From mboxrd@z Thu Jan 1 00:00:00 1970 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=EcKYPgbMPyLdSCox+Bti/kG+lNowmOaQ7xyJFjq2RD+LCKfJQP1soEiEPF2lG0eoJmRf k6f7+NYnJyVdkALSPkl2GJqs5BbuoYqIGMCVPAGvDzKbZylM8NKQQdZFFqpVZb/m8ucnR aH5mnnIF8/ppdu3Opwfa12ObIimk3cEnAfwWuAkgGizRaSm5RmosWO9zg11ugwXxX7EwV chxE1SfdN+ZXBv8N0qOwZMG6mM2c429nn6cOCQDJgLY+a0Y6Uh7Kmld9drldzc2c6vgLZ QhIHlh6oZWF321rBxN+WuIuhL78RGdHIw6A309JrpdAW0iNmwJWohWtmD8Jsr7V7cRw== 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-Forwarded-Encrypted: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=oSR8b9z0h0jJ2y/rY5NBvjy2edKhWN1zdB8aXgPMVmrRmlF2yZoCN7Ho/I3jPFT0zAuj 0dl2GUjnZm54YChal4h6TTky26hXDcZHrsP6H9r2X68qp2wLgj3WR/FACG8bLf29gNbYx CCmfi9rri78KQ2AagteObqZvH4ugv+JaonsVLCs9q6jki1wCCWw57kM9VjtFnHCfnyYyw E+i/x6Y7yjUJ9EgiWwOSF3as+gQKT+RTraC877J+s6cgIPTvHbs/AC8t+ivMWF2ydKquH WZR6MfTj/7jvAH7LEnMIqmbxyZ04smMqFF0EgjBa4HmewFisz3m9S+ZpA2+2Rp6f67Q== 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 CA8C4606A6AB for ; Sat, 5 Dec 2026 01:31:42 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org CA8C4606A6AB 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-67dae7d3f7dso1696889d50.2 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=0+FJ6Vr6t63HM8ofIkzYTZt24k30HNnb0jHJdNar7L79VEgI5hr9ju6k3OZt8e4RnO Dnic4cr9xQNGdjeQ/TCZ8GjOj5PIoDOyzdyBzGvhPgl0sHwv3gtXyb6VjIqjT9ewELdK EzjBfF34mtG0P2LfIMfH3HScHHtV+cj6a35pLmgm756plNUdDrlmp/iWnYuFhhVzHSCU yvQbcGZnSLu6lc9PfNNUWdqEAhUfP7HvjprOEICJ/BnirdJ4YdYFcVFeFpuhFVioQLwc E+XJNzFw+zlmCGP52HgQV8VlCMiDJ547CfdvwvTNohX63N5tFzy4mmCdsTUe5dy+Z4yV M3dQ== X-Forwarded-Encrypted: i=1; AL+hErFW9fZBCTAM1OS7u7Om3MFWH9Zjh0QxJzM1a1ehuH10AywAlQI4YcH5Gd4LnwDaha41omPbz9RiEa/k8F0=@vger.kernel.org X-Gm-Message-State: AB4q+uENkjCyFcO4yWwP5fqa+4ehGbG+O4T2YqeTHCg9AhAl8Hm3M4sU 3Ze2ySST1U7yPSOQ98yxLT35VfooIVnyOaFxJY+oIr/Sgpby41yKU9Nh6/a3GJ+ug9E= X-Gm-Gg: AZFdTZd5KmGSjO8S19CNFb38P0VemuUtvznmEffxbyiKGRAopxYoVmILIpLAuU3+cJE RjR1gRZ9KTQHZL/uQRBRXMvf1ki6LabT4VFKZd7M+wgiz/MdsVjbHUFbcGql5e3T609DNKlHi3d gDX3ZuhczKygWWyEmyuLFs1aAAFgXcdDLfiTSTqePKVay0myH08QFsGlM8iKZtmTDXXkTRlg2Xo 2nYJ2WdWOnWdg3Z3q1v9zFfITkKmiaGqRjp6ImXYXr4gGQYCC5ZuBmSCmGvlIajDiEegkE/dl42 2U5eFKZC/EIPkqXj3JmACOVZbW/OuS3OBrV0Bmcb3ycGRpYFVWUav/E26m9e6A7rdxeCUt89U0W TmZcw1qB1uq2Rp4vsmBVwEiyh/qr/jQM7EMJVOExp+PB6cSqv0C9Wh7Pty/2D3qXZevmm1udDW6 H0yh073qqAkKfFJzyxrw5ar3gwKsq8N5kA7bMDXpE05Z95usmO16BEpJXiYFOqbuAjdcjf0oUVe /9GxvnJWP+I5o/rilQwk2Yt/qrrMvBPsmT1uiCUvIZpnLd6to7Fqlh3sPgbRdfC+H1mfmN9O9ce VlSXMSkww1ubFK6iTFUQVpvEUIUfMAEsBooS/8C5ZSQ12Y4BWw5sH1vnIhm2UPkfpZT1XZ1UyX9 uDml53sJbUO/8qf0GZBuEYkqvDvvYt7ikudF0yj8Ik4BNvWFskWbaOWZVDFSfbzAa9f/1PGCK 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-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 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