Re: [PATCH] udf: check device specification EA size before reading impUseLength

From: Jan Kara

Date: Fri Nov 27 2026 - 09:27:35 EST


On Fri 27-11-26 07:43:52, Junyoung Jang wrote:
> udf_get_extendedattr() only verifies that the 12-byte genericFormat
> header and the declared attrLength fit within the inode's i_data buffer.
> However, udf_device_spec_valid() reads the 4-byte impUseLength field at
> offset 12 before checking that attrLength covers struct deviceSpec.
>
> If a crafted UDF image places a truncated device specification EA (with
> attrLength shorter than 16 bytes) at the end of i_data, reading
> impUseLength triggers a KASAN slab-out-of-bounds read in __udf_iget():
>
> BUG: KASAN: slab-out-of-bounds in __udf_iget+0x3d41/0x3f20
> Read of size 4 at addr ffff8881025a0f27 by task busybox/51
>
> Call Trace:
> <TASK>
> __udf_iget+0x3d41/0x3f20
> udf_lookup+0x1b5/0x1d0
> __lookup_slow+0x18f/0x330
> walk_component+0x2b1/0x4e0
> path_lookupat+0x112/0x670
> filename_lookup+0x17b/0x4f0
> vfs_statx+0xd8/0x160
> vfs_fstatat+0x77/0xb0
> __do_sys_newfstatat+0x9f/0x100
> __x64_sys_newfstatat+0x91/0xf0
> x64_sys_call+0x331/0x9f0
> do_syscall_64+0x47/0x110
> entry_SYSCALL_64_after_hwframe+0x67/0x6f
> </TASK>
>
> Allocated by task 51:
> __kmalloc_noprof+0x13c/0x250
> udf_alloc_i_data+0x19/0x60
> __udf_iget+0x2b03/0x3f20
> udf_lookup+0x1b5/0x1d0
> ...
>
> The buggy address belongs to the object at ffff8881025a0000
> which belongs to the cache kmalloc-4k of size 4096
> The buggy address is located 3879 bytes inside of
> allocated 3880-byte region [ffff8881025a0000, ffff8881025a0f28)
>
> Check attrLength against sizeof(*dsea) before reading impUseLength.
>
> Fixes: 9a2390959685 ("udf: validate the device specification EA before using it")
> Cc: stable@xxxxxxxxxxxxxxx
> Co-developed-by: Gwanhyun Lee <gwanhyunlee@xxxxxxxxx>
> Signed-off-by: Gwanhyun Lee <gwanhyunlee@xxxxxxxxx>
> Signed-off-by: Junyoung Jang <graypanda.inzag@xxxxxxxxx>

Thanks! I've added the patch to my tree (just undoing the sizeof(struct
deviceSpec) -> sizeof(*dsea) change).

Honza

> ---
> Tested on 6.12.118 with KASAN; with this patch applied, the malformed
> inode is rejected with -EIO and no KASAN report is triggered.
>
> Disclosure: An in-house LLM-based analysis tool developed by the authors
> assisted in surfacing this bug candidate and drafting the initial notes.
> All root-cause analysis, patch code, and QEMU/KVM reproducer results
> were manually reviewed and independently verified by the authors.
>
> fs/udf/inode.c | 8 +++++---
> 1 file changed, 5 insertions(+), 3 deletions(-)
>
> diff --git a/fs/udf/inode.c b/fs/udf/inode.c
> index 29900065673c..b4e34b345ff8 100644
> --- a/fs/udf/inode.c
> +++ b/fs/udf/inode.c
> @@ -1345,10 +1345,12 @@ static bool udf_device_spec_valid(struct deviceSpec *dsea)
> u32 attr_length, imp_use_length;
>
> attr_length = le32_to_cpu(dsea->attrLength);
> + if (attr_length < sizeof(*dsea))
> + return false;
> +
> imp_use_length = le32_to_cpu(dsea->impUseLength);
> - if (attr_length < sizeof(struct deviceSpec) ||
> - imp_use_length < sizeof(struct regid) ||
> - imp_use_length > attr_length - sizeof(struct deviceSpec))
> + if (imp_use_length < sizeof(struct regid) ||
> + imp_use_length > attr_length - sizeof(*dsea))
> return false;
>
> return true;
>
> base-commit: 25faec9ce61c01fb45abf812a222c5b43c3cd5c5
> --
> 2.43.0
>
--
Jan Kara <jack@xxxxxxxx>
SUSE Labs, CR