From: Sasha Levin <sashal@kernel.org>
To: patches@lists.linux.dev, stable@vger.kernel.org
Cc: Jan Kara <jack@suse.cz>,
syzbot+478f2c1a6f0f447a46bb@syzkaller.appspotmail.com,
Sasha Levin <sashal@kernel.org>,
jack@suse.com
Subject: [PATCH AUTOSEL 5.15 07/15] udf: Verify partition map count
Date: Sun, 3 Aug 2025 17:21:57 -0400 [thread overview]
Message-ID: <20250803212206.3548990-7-sashal@kernel.org> (raw)
In-Reply-To: <20250803212206.3548990-1-sashal@kernel.org>
From: Jan Kara <jack@suse.cz>
[ Upstream commit 1a11201668e8635602577dcf06f2e96c591d8819 ]
Verify that number of partition maps isn't insanely high which can lead
to large allocation in udf_sb_alloc_partition_maps(). All partition maps
have to fit in the LVD which is in a single block.
Reported-by: syzbot+478f2c1a6f0f447a46bb@syzkaller.appspotmail.com
Signed-off-by: Jan Kara <jack@suse.cz>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
LLM Generated explanations, may be completely bogus:
**Backport Status: YES**
This commit should be backported to stable kernel trees based on the
following analysis:
1. **Security Fix**: The commit addresses a security vulnerability
reported by syzbot
(syzbot+478f2c1a6f0f447a46bb@syzkaller.appspotmail.com), indicating
this is fixing a real bug discovered through fuzzing. The issue could
lead to excessive memory allocation in
`udf_sb_alloc_partition_maps()`.
2. **Integer Overflow/Memory Exhaustion Prevention**: The code adds a
crucial bounds check that prevents potentially huge allocations.
Without this check, a malformed UDF filesystem could specify an
arbitrarily large `numPartitionMaps` value, causing `kcalloc()` in
`udf_sb_alloc_partition_maps()` to allocate excessive memory or fail.
3. **Small, Contained Fix**: The change is minimal - only 11 lines added
and 2 modified. It adds a simple validation check:
```c
if (part_map_count > table_len / sizeof(struct genericPartitionMap1))
```
This ensures the partition map count doesn't exceed what can
physically fit in the table.
4. **Clear Bug Fix Pattern**: The fix follows a standard pattern of
input validation before allocation, which is a well-understood
security best practice. The logic is straightforward: all partition
maps must fit within the Logical Volume Descriptor (LVD) block.
5. **No Feature Changes**: This is purely a defensive check that
prevents invalid input from causing problems. It doesn't change any
functionality for valid UDF filesystems.
6. **Affects User-Facing Code**: UDF filesystem mounting is user-facing
functionality that could be triggered by inserting malicious media or
mounting crafted filesystem images, making this an important security
boundary.
7. **Low Risk of Regression**: The added check only rejects invalid
filesystems that would likely cause problems anyway. Valid UDF
filesystems will pass this check without issue.
The commit follows stable kernel rules by fixing an important bug
(potential DoS through memory exhaustion) with minimal, low-risk changes
to a filesystem that handles untrusted input.
fs/udf/super.c | 13 +++++++++++--
1 file changed, 11 insertions(+), 2 deletions(-)
diff --git a/fs/udf/super.c b/fs/udf/super.c
index 4275d2bc0c36..69e4f00ce791 100644
--- a/fs/udf/super.c
+++ b/fs/udf/super.c
@@ -1411,7 +1411,7 @@ static int udf_load_logicalvol(struct super_block *sb, sector_t block,
struct genericPartitionMap *gpm;
uint16_t ident;
struct buffer_head *bh;
- unsigned int table_len;
+ unsigned int table_len, part_map_count;
int ret;
bh = udf_read_tagged(sb, block, block, &ident);
@@ -1432,7 +1432,16 @@ static int udf_load_logicalvol(struct super_block *sb, sector_t block,
"logical volume");
if (ret)
goto out_bh;
- ret = udf_sb_alloc_partition_maps(sb, le32_to_cpu(lvd->numPartitionMaps));
+
+ part_map_count = le32_to_cpu(lvd->numPartitionMaps);
+ if (part_map_count > table_len / sizeof(struct genericPartitionMap1)) {
+ udf_err(sb, "error loading logical volume descriptor: "
+ "Too many partition maps (%u > %u)\n", part_map_count,
+ table_len / (unsigned)sizeof(struct genericPartitionMap1));
+ ret = -EIO;
+ goto out_bh;
+ }
+ ret = udf_sb_alloc_partition_maps(sb, part_map_count);
if (ret)
goto out_bh;
--
2.39.5
next prev parent reply other threads:[~2025-08-03 21:22 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-08-03 21:21 [PATCH AUTOSEL 5.15 01/15] hfs: fix slab-out-of-bounds in hfs_bnode_read() Sasha Levin
2025-08-03 21:21 ` [PATCH AUTOSEL 5.15 02/15] hfsplus: fix slab-out-of-bounds in hfsplus_bnode_read() Sasha Levin
2025-08-03 21:21 ` [PATCH AUTOSEL 5.15 03/15] hfsplus: fix slab-out-of-bounds read in hfsplus_uni2asc() Sasha Levin
2025-08-03 21:21 ` [PATCH AUTOSEL 5.15 04/15] hfsplus: don't use BUG_ON() in hfsplus_create_attributes_file() Sasha Levin
2025-08-03 21:21 ` [PATCH AUTOSEL 5.15 05/15] arm64: Handle KCOV __init vs inline mismatches Sasha Levin
2025-08-03 21:21 ` [PATCH AUTOSEL 5.15 06/15] smb/server: avoid deadlock when linking with ReplaceIfExists Sasha Levin
2025-08-03 21:21 ` Sasha Levin [this message]
2025-08-03 21:21 ` [PATCH AUTOSEL 5.15 08/15] drbd: add missing kref_get in handle_write_conflicts Sasha Levin
2025-08-03 21:21 ` [PATCH AUTOSEL 5.15 09/15] hfs: fix not erasing deleted b-tree node issue Sasha Levin
2025-08-03 21:22 ` [PATCH AUTOSEL 5.15 10/15] better lockdep annotations for simple_recursive_removal() Sasha Levin
2025-08-03 21:22 ` [PATCH AUTOSEL 5.15 11/15] ata: libata-sata: Disallow changing LPM state if not supported Sasha Levin
2025-08-03 21:22 ` [PATCH AUTOSEL 5.15 12/15] fs/ntfs3: Add sanity check for file name Sasha Levin
2025-08-03 21:22 ` [PATCH AUTOSEL 5.15 13/15] fs/ntfs3: correctly create symlink for relative path Sasha Levin
2025-08-03 21:22 ` [PATCH AUTOSEL 5.15 14/15] ext2: Handle fiemap on empty files to prevent EINVAL Sasha Levin
2025-08-03 21:22 ` [PATCH AUTOSEL 5.15 15/15] securityfs: don't pin dentries twice, once is enough Sasha Levin
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=20250803212206.3548990-7-sashal@kernel.org \
--to=sashal@kernel.org \
--cc=jack@suse.com \
--cc=jack@suse.cz \
--cc=patches@lists.linux.dev \
--cc=stable@vger.kernel.org \
--cc=syzbot+478f2c1a6f0f447a46bb@syzkaller.appspotmail.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