Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.128.170 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796434299; b=ezX2MPBwsJewsLDeqVFRequ++aGHAiRnq2hzhL6+IaBFxHsIko/bSWS5rvcZgVIW1vfb QHT+ZmaofXLbxspdSX8O5eoIuDXuoCm68VIsEEDsutOMXCRpeNBAa7e0seQm/SsXre23H XEBdfNwY1fg4YYAEcLlTVVCndAYw67irLAHZ2J0/znXcVm7u3BA0UlTa6vTWir0Rhyr4U fk78Ntv2MGpjuYPzpmmy21yBsFfVUZivOYPXBgOFz1tMnxG1r0xcvDbg0MOluHGLV8PDk ICbei0zN17Ww3tz3YN+zUWJqKNsfgv+wE47AfLnkU+zRmlI+c2TIfKXoD6U0fbBpVeg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796434299; 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=6OpbCpJ+xSurtDNkIhiIXfD5AT8ZUSmSgA0zP8+bQ9U=; b=4G71ee7HJ1FNALsRRXpW1WlbR5J/2SsweLFRMTeDhEn2jdcVIVSAFHOFPcYnpK7e4OPW l6bpSTXQ7okYXXn78RIiYefPR9DvNeULJJ8KVTHd6VdQEHY82rodPSz5vmQZAA6sk8n/7 nQF5t5KL8jPMRIPdU+m/fwBqW/TCbOzll14X8OA4yQb5Ufr66sHDPXHltAnWW5CxjiGMT Uusard5cRuIsGqo4Hd8/HRZufRrkUtJAVS5olIER/qmMXTt4/U/gCM10HWwEpnp97g2xC eqFu31qnR6BfGYawITKXRj/PxLeNH82tkQTITNk5ZxFw2TDmje51FNsTj1Lk9Euqjlw== 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=209.85.128.170 Received: from mail-yw1-f170.google.com (mail-yw1-f170.google.com [209.85.128.170]) (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 1B077606A330 for ; Sat, 5 Dec 2026 01:31:38 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 1B077606A330 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-yw1-f170.google.com with SMTP id 00721157ae682-8b4e2ec4b42so9043617b3.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=BFWS/cqq8IcvEBleIWLkGioPjvxk4pRoSR9nikWyBZz5JkmF8Drx80BJU60mTIf72P qHo2QBaNrSdVRitrqWmqPoFW4nN4+ktMblGRtbn33HHDs7HdxU0FId34vcEycbbnKidj E4DcTf50QyU/jBwqHonaO2aTUhzlJYCeHv6bjAlzhxXQNP/48izNhR5rLloQFsAkdPSC M4IvnYUYOZLkERq+Qke4GF7uF6O6ZMzDp0uiwsBZun7EWxgwigmtlMD9r/PiTaZHE7Ad R5rs5u9oc/bmbeRnOSm4AGkxVKrf9v0Jd30LG9UGs9COvUxO63CtQ36gC7pylbLgCg4T ZV7A== X-Gm-Message-State: AB4q+uEQHwetG1LV0GywgNmEba3FGyQENNmMqJMVMyIc6lRXTlAd7Ktk 2UxGHQIvDFiRaReVqaGyG7Yg9+I8F+3PHc+g77c4JhKbUYOuaJR8RU6DpAHgH/De7AI= X-Gm-Gg: AZFdTZdVgzf0issuxIy8KoJJUtamhclGWdN5Zw4STNoihoRfOaje5kUquscyudCQu7Z 9dx88jtZ1VHfwo7txWn1akNB9UDQ1eYSKZe4FmLqoHX4V9pbSB+J590IQUckbDTk4EPGXIU8oxK IF/4HMGJ9l9wt5EoXRpPEhSz6JmzzVEIbWbSAMxLpoowZQ/guzksXzE1iQfuaWOmEnk/ZxOgnfy 3ooO5xhry2Nn03pKDYfht1DWi+29ccCR9yWiP7bacUBW0CEAQtVpi35FKvRnAHA5e28fdaw3Hg/ k9e7Wz/WlKQoEdTAz4cWmlVxag/t5O8QSv+Ixnd42vJ8sqSgbnvMjlTDe1bN8DjdyX9CY2dvPpF RukurUPvD7FiR9PvxGmt+elDbfIGQWSijUR7cxC/g8mOMUuhBC9PJM12M26KgBzr5IM61ShKUui icisUrd+NdOxOsKjtThxnUBlUwwFlPr18270jcJ1YU7/wHrlY1DQN1BagM4GmCJJJWqiwh0z80f ydmdMXOs4AkniFu8oCZzthiM+T7vP7CEPbiz+EHtaxpKBqP2x4PGQO5IpqyfD1NfaGQYt/5K/SB hk3WL+D99JUUK6m0zVPBL8GbC1RAs7gfxpvA4Y/+zi/p/Sa3Je6UiggERwRKhzvqSCNohk4v70E qFDg+KfLBYu+naHdNfF466HfxmgMB4DkzgocFtn4NiwXLPheZOWHrdyD2fe+VeqjwxjEJHevcVc jfShdR+NI5DQWh5UEu 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-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 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