From: Junyoung Jang <graypanda.inzag@gmail.com>
To: Jan Kara <jack@suse.cz>
Cc: Junyoung Jang <graypanda.inzag@gmail.com>,
Gwanhyun Lee <gwanhyunlee@gmail.com>,
linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH] udf: validate logical volume partition map lengths before parsing
Date: Thu, 26 Nov 2026 00:56:07 +0900 [thread overview]
Message-ID: <20261125155608.282719-1-graypanda.inzag@gmail.com> (raw)
udf_load_logicalvol() checks the aggregate partition map table length,
but uses each entry's unvalidated partitionMapLength to walk the table.
A truncated type-2 map near the end of a Logical Volume Descriptor can
contain the sparable partition identifier while its packetLength field
lies past the descriptor buffer. This causes a two-byte out-of-bounds
read in udf_load_sparable_map(), reported by KASAN in
udf_process_sequence().
Check that each map header fits in the remaining table and that its
declared length fits in the table and covers the fields for its type.
The 64-byte generic type-2 size covers the virtual, sparable, and
metadata partition map layouts. Report and reject truncated headers
and invalid map lengths before accessing type-specific fields. The
unchecked walk is present in the initial imported tree.
A custom LLM agent assisted with discovery and reproducer setup.
Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
Cc: stable@vger.kernel.org
Co-developed-by: Gwanhyun Lee <gwanhyunlee@gmail.com>
Signed-off-by: Gwanhyun Lee <gwanhyunlee@gmail.com>
Signed-off-by: Junyoung Jang <graypanda.inzag@gmail.com>
---
The malformed image uses a 4096-byte Logical Volume Descriptor with a
3656-byte partition map table and 16 maps. The last map begins at table
offset 3626 and declares a 30-byte type-2 sparable map. Its
packetLength field lies at descriptor byte 4106, past the end of the
4096-byte buffer. A second image declares a 3627-byte table, leaving
only one byte of the last map header inside the table.
On unmodified mainline 4dce97c6c265 with UDF and KASAN enabled, the
first image produced:
BUG: KASAN: use-after-free in udf_process_sequence+0x3cfe/0x3f60
Read of size 2 at addr ffff88807ffc000a by task busybox/57
Call Trace:
udf_process_sequence+0x3cfe/0x3f60
udf_check_anchor_block+0x270/0x460
udf_load_vrs+0x67b/0xde0
udf_fill_super+0x778/0x19d0
The read crossed the descriptor boundary into an adjacent freed page;
that is why KASAN classified it as use-after-free. The mount failed
with EIO after the invalid packetLength was read. On patched mainline,
three boots rejected map length 30 at offset 3626 before that read;
three boots of the second image rejected the truncated header at the
same offset. Neither patched case produced a KASAN report. Valid UDF
and sparable UDF images mounted before and after the patch.
fs/udf/super.c | 20 ++++++++++++++++++++
1 file changed, 20 insertions(+)
diff --git a/fs/udf/super.c b/fs/udf/super.c
index a81a8509524a..41988a07b86b 100644
--- a/fs/udf/super.c
+++ b/fs/udf/super.c
@@ -1580,9 +1580,29 @@ static int udf_load_logicalvol(struct super_block *sb, sector_t block,
i < sbi->s_partitions && offset < table_len;
i++, offset += gpm->partitionMapLength) {
struct udf_part_map *map = &sbi->s_partmaps[i];
+ unsigned int min_len;
+
+ if (table_len - offset < sizeof(*gpm)) {
+ udf_err(sb, "Truncated partition map header at offset %d\n",
+ offset);
+ ret = -EIO;
+ goto out_bh;
+ }
gpm = (struct genericPartitionMap *)
&(lvd->partitionMaps[offset]);
type = gpm->partitionMapType;
+ min_len = sizeof(*gpm);
+ if (type == 1)
+ min_len = sizeof(struct genericPartitionMap1);
+ else if (type == 2)
+ min_len = sizeof(struct genericPartitionMap2);
+ if (gpm->partitionMapLength < min_len ||
+ gpm->partitionMapLength > table_len - offset) {
+ udf_err(sb, "Invalid partition map length %u at offset %d\n",
+ gpm->partitionMapLength, offset);
+ ret = -EIO;
+ goto out_bh;
+ }
if (type == 1) {
struct genericPartitionMap1 *gpm1 =
(struct genericPartitionMap1 *)gpm;
base-commit: 4dce97c6c265544342e716e62fd24bbb232590c5
--
2.43.0
reply other threads:[~2026-11-25 15:56 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261125155608.282719-1-graypanda.inzag@gmail.com \
--to=graypanda.inzag@gmail.com \
--cc=gwanhyunlee@gmail.com \
--cc=jack@suse.cz \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®