mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Kyle Zeng <kylebot@openai.com>
To: linux-kernel@vger.kernel.org
Cc: Jan Kara <jack@suse.com>,
	outbounddisclosures@openai.com, Kyle Zeng <kylebot@openai.com>
Subject: [PATCH] udf: validate partition reference before freeing blocks
Date: Thu, 11 Jun 2026 14:36:35 -0700	[thread overview]
Message-ID: <20260611213635.17198-1-kylebot@openai.com> (raw)

UDF long allocation descriptors can carry an on-disk
partitionReferenceNum. The truncate/free path passes that value to
udf_free_blocks(), which indexes s_partmaps[partition] before checking
that partition is smaller than s_partitions.

A crafted writable image with one partition and a long allocation
descriptor that references partition 1 can therefore make
udf_free_blocks() read past the allocated partition map array when
truncating the file.

Validate the partition reference before forming the map pointer. Also
compare the checked end block, including the caller-supplied offset,
against the partition length; the previous test computed blk but then
compared logicalBlockNum + count.

Assisted-by: Codex:gpt-5.5
Signed-off-by: Kyle Zeng <kylebot@openai.com>
---
 fs/udf/balloc.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/fs/udf/balloc.c b/fs/udf/balloc.c
index 807c493..9d5fe22 100644
--- a/fs/udf/balloc.c
+++ b/fs/udf/balloc.c
@@ -656,13 +656,21 @@ void udf_free_blocks(struct super_block *sb, struct inode *inode,
 		     struct kernel_lb_addr *bloc, uint32_t offset,
 		     uint32_t count)
 {
+	struct udf_sb_info *sbi = UDF_SB(sb);
 	uint16_t partition = bloc->partitionReferenceNum;
-	struct udf_part_map *map = &UDF_SB(sb)->s_partmaps[partition];
+	struct udf_part_map *map;
 	uint32_t blk;
 
+	if (partition >= sbi->s_partitions) {
+		udf_debug("Invalid partition reference %u (partitions %u)\n",
+			  partition, sbi->s_partitions);
+		return;
+	}
+
+	map = &sbi->s_partmaps[partition];
 	if (check_add_overflow(bloc->logicalBlockNum, offset, &blk) ||
 	    check_add_overflow(blk, count, &blk) ||
-	    bloc->logicalBlockNum + count > map->s_partition_len) {
+	    blk > map->s_partition_len) {
 		udf_debug("Invalid request to free blocks: (%d, %u), off %u, "
 			  "len %u, partition len %u\n",
 			  partition, bloc->logicalBlockNum, offset, count,
-- 
2.54.0


             reply	other threads:[~2026-06-11 21:36 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-11 21:36 Kyle Zeng [this message]
2026-06-12 12:29 ` Jan Kara

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=20260611213635.17198-1-kylebot@openai.com \
    --to=kylebot@openai.com \
    --cc=jack@suse.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=outbounddisclosures@openai.com \
    /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®