From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.224.41 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796434300; b=QHnZMUyjHlqZA+8YftqMghHopfcdNBrgLl6VCTR0jjcUUxM6XjI489YJidcOReceUNrG IcYa01ehzIjaftZBylkUktmCsrqO2UMd16wVptLfum85sdEbI2/VuSuJsAEGiGmSi9ZpY MuXZk1i9NGhyiXZolEhkF4PpImJxSzAeb9K6UFpRxlQO8mFyufWsxxfzD2Qmf5z5dwpY1 jv5fviaSAxtTWzfXQf8HQ3TzWP7owq8UchZg/RspOy5xoo8jChQAyzjQtQzpeQgqzI289 B7nserZ1V5YWJYn/qTe47v/Td6T+K71tbBfwd3Y4mNPIQqtX1lVCqv+AXEk4c6TjINg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796434300; 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=6OpbCpJ+xSurtDNkIhiIXfD5AT8ZUSmSgA0zP8+bQ9U=; b=fvsALZDN/mWZm8ei5ZvUjRq2qhnWKAEg4zDwlfXZN5wrILaWjyP4KMiKjyD4dZtYiaII Qf3G+AqjA+GQatMbeBsaLmbkK0ppDuequeWqVTuFaFr4eZlKso7KZWjqLmeaI4LJDHZ7n CtwKWI7KLt3khf/zVMfWAqV65D7ZvF8EBi/1jbxM4RGMxsW4Qz3KtuesYQqhCGxfLTCD/ putm1xSuqLci4wKfsq27zQedRf9HjiWPC2mCml19qv/6SjkUQKLLpGF8ftK16WDNowGPv 1M5l2coueuAR7c0VWP4u60j/Rot7uxjfLacRjr2+FokTRYflm7m/xW7buQk+eg+64cA== 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=boDSMesW; arc=none smtp.remote-ip=74.125.224.41 Received: from mail-yx1-f41.google.com (mail-yx1-f41.google.com [74.125.224.41]) (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 1C034606A33C for ; Sat, 5 Dec 2026 01:31:38 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 1C034606A33C 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=boDSMesW Received: by mail-yx1-f41.google.com with SMTP id 956f58d0204a3-67db1f6f50eso1689597d50.0 for ; Fri, 04 Dec 2026 17:31:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dubeyko-com.20260707.gappssmtp.com; s=20260707; t=1796434298; x=1797039098; 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=6OpbCpJ+xSurtDNkIhiIXfD5AT8ZUSmSgA0zP8+bQ9U=; b=boDSMesWcwRFNQ6Bh5SLtlCB5DOS2fjH5gvmqRn1uuE8QTjD0GgCYAiAyQAEOBQYcH 3jgPTbUIT4c5gtHFQkBlljSILXZXuHDVs7203vNdj4JNLuEBl5YHOd/oORue4UTHQsl/ QzeHeiL3fCiV7SVE0ULzGKLn9pfI/aPw0W4d3URDZ3SiOpgIhAeQ8iruSs3keFhXFH/z PfMa+iGJ2m17BSklEyLBaquR/WZgkEJk8SO808rFGiW+Zoy3BfBtlDFbs3pecTyYGtzS 7UXUWDZCluH5ntlHQ2PgNaAkeEuRumMdmLhwsUZ+oON7n4bzvm0v+0oNqNNItGcV+GGL 77ig== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796434298; x=1797039098; 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=6OpbCpJ+xSurtDNkIhiIXfD5AT8ZUSmSgA0zP8+bQ9U=; b=Gmo4xKkp56MQfZPwA5VSL/+wkgr7F1/DM6kiYvVBzeUDqg/9f0pGWncrpSH0iwJYz+ xPsrYPYjfHrm//eE6dtETvqoI+oiDc1YCZY397BM4szIccdqy85VFqEZpczHHVL89H6k 8tHyr8HTIL5Gl6+6isPo6TMRY9ytMhUm19GcZXbNK/ugLroKh0HQKlZ1e89KJ2wv1yFJ Bmw8tgCkuJmp4W87MMPItleJ2tdt4rqncSfnj/PY0p4N5R40JKQU2qj6QEgTuCr+ED5m iJYWc/Y1JHhaWsTbh+2CO+PLuuxXFRLmZr0lX4sjIuzUgfmFQ9jVLwp+29I9a8ImoZDz hqoQ== X-Forwarded-Encrypted: i=1; AL+hErELJuUJBitZYkX+w8wBD7pJlYnLxZiM92sctYfA7hfI3hK3R7RVhhZaFytsQEHg2Vz4TjWKmELx4Cgpq4g=@vger.kernel.org X-Gm-Message-State: AB4q+uEb18HyUETzcrb3pJmDu0xhPApFBl0wCvUimGMdNBXEVLnDpnma urzfVUwuPWSPYkyaGmx624sns4cK1aNxrAIZDipIpL9pedvQ98Vkr9SpwapgDQoeYvk= X-Gm-Gg: AZFdTZfDZDIAfKiTQ3e2UisF1md5y2jJkSqTITD2Gz9CQ9ygZ1PeZfLIDp/NlgfRkRe GecpyDeIOJrmLWoVQvvGa0i5RXoeKSx9JOXBIWVqHBakaN1DBEeHJfF24AB4UuCSIKeWGYz8GbU /YXB4oLC8dnBl7JxWBAwzTEcaB7h2tIzNJtvD9khCFABbQYIkL5/9ODMPdr8ihdIeiabe5MY9Ra 8hsovAbiPUMmueo4a/Ucd9YFIB+KJtGtCmAEohKiN85ZU8KhXC6AbgpnT8C7GvbnRkw0zj5x7J5 ZryKuxyS5aCP0jt2w6OQn36FdCd105FdJLiBtZjkzLZi/n0KOBivYakRzM87Wpp1vVWu9/Xnrwc bHwh1399Ie0OTl7/reOitovtmje/00DALSIQnbfoyGsu7owizTL2yB+aicUsebE5ORJoOEaF4rF rG8eSYiKzRvOVJAmeBd/9spF5JkEx5MmxofGlAoaRcGgadWd8Tzy7mqe8AqHrL0u4v0xIZ9/ceq NYTo3/bme5G8zzMzPAREFrHyDMOCIjv426yFZ7+PWdynAAnlL+a26d9rJIFAJDnX8l22dUpOiqi wOMvTEPpI7tPR7pQpkh70dR9y3oRgOFq4E0Ce+2PtJ/HOFX4RWwu6X//dqTQx/lAjG5Yu3J5R5t DKjo7m0YLopK598yetAS9znVmqR3gOFlulMbVmyUQijC2YVJO9krjOE9g8/3HUGCeq6zJEW/UTq VzK/FSw6BNwbNEm2By X-Received: by 2002:a05:690c:6f82:b0:8b5:6331:79be with SMTP id 00721157ae682-8b660d5e13fmr20333807b3.39.1796434298050; Fri, 04 Dec 2026 17:31:38 -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.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Dec 2026 17:31:37 -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 3/6] hfsplus: validate the partition map entry before following it Date: Fri, 4 Dec 2026 17:31:24 -0800 Message-ID: <20261205013127.1533652-4-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 hfsplus_read_wrapper() finds no volume at the start of the device, it calls hfs_part_find() to look for an Apple partition map and reads the volume header 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/hfsplus/part_tbl.c | 48 +++++++++++++++++++++++++++++++++++++------ 1 file changed, 42 insertions(+), 6 deletions(-) diff --git a/fs/hfsplus/part_tbl.c b/fs/hfsplus/part_tbl.c index 9ec21664eda6..4076609c51a7 100644 --- a/fs/hfsplus/part_tbl.c +++ b/fs/hfsplus/part_tbl.c @@ -15,6 +15,7 @@ */ #include +#include #include "hfsplus_fs.h" /* offsets to various blocks */ @@ -67,6 +68,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; +} + static int hfs_parse_old_pmap(struct super_block *sb, struct old_pmap *pm, sector_t *part_start, sector_t *part_size) { @@ -79,8 +102,15 @@ static int hfs_parse_old_pmap(struct super_block *sb, struct old_pmap *pm, if (p->pdStart && p->pdSize && p->pdFSID == cpu_to_be32(0x54465331)/*"TFS1"*/ && (sbi->part < 0 || sbi->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)) + return -EINVAL; + *part_start += entry_start; + *part_size = entry_count; return 0; } } @@ -92,7 +122,7 @@ static int hfs_parse_new_pmap(struct super_block *sb, void *buf, struct new_pmap *pm, sector_t *part_start, sector_t *part_size) { struct hfsplus_sb_info *sbi = HFSPLUS_SB(sb); - int size = be32_to_cpu(pm->pmMapBlkCnt); + int map_count = be32_to_cpu(pm->pmMapBlkCnt); int buf_size = hfsplus_min_io_size(sb); int res; int i = 0; @@ -100,12 +130,18 @@ static int hfs_parse_new_pmap(struct super_block *sb, void *buf, do { if (!memcmp(pm->pmPartType, "Apple_HFS", 9) && (sbi->part < 0 || sbi->part == i)) { - *part_start += be32_to_cpu(pm->pmPyPartStart); - *part_size = be32_to_cpu(pm->pmPartBlkCnt); + 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, map_count)) + return -EINVAL; + *part_start += entry_start; + *part_size = entry_count; return 0; } - if (++i >= size) + if (++i >= map_count) return -ENOENT; pm = (struct new_pmap *)((u8 *)pm + HFSPLUS_SECTOR_SIZE); -- 2.53.0