From a186657ea1f298d3a44df501030a80c8c369bfd5 Mon Sep 17 00:00:00 2001 From: Bernard Xiong Date: Tue, 17 Nov 2026 02:02:46 +0800 Subject: [PATCH] [dfs][iso9660] fix: validate directory record name length The name length field of an ISO9660 directory record comes from the medium and was used without validation. For regular files the code unconditionally stripped the two-byte version suffix, so a length of 0 or 1 underflowed the size_t and a later rt_strncpy() zeroed kernel memory until it reached an unmapped page. Clamp the length to the local name buffer and only strip the suffix when the name is long enough. Verified by building bsp/qemu-virt64-riscv with DFS v1 and ISO9660 enabled; the runtime reproduction on a block device was not executed. --- .../dfs/dfs_v1/filesystems/iso9660/dfs_iso9660.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/components/dfs/dfs_v1/filesystems/iso9660/dfs_iso9660.c b/components/dfs/dfs_v1/filesystems/iso9660/dfs_iso9660.c index 2358280a799a..2db2ebe65243 100644 --- a/components/dfs/dfs_v1/filesystems/iso9660/dfs_iso9660.c +++ b/components/dfs/dfs_v1/filesystems/iso9660/dfs_iso9660.c @@ -290,6 +290,12 @@ static struct iso9660_fd *iso9660_lookup(struct iso9660 *iso, const char *path, namelen = rt_le32_to_cpu(dirent->namelen); + /* The name length comes from the medium, never trust it */ + if (namelen >= MAX_NAMELEN) + { + namelen = MAX_NAMELEN - 1; + } + if (iso->joliet) { iso9660_convert_string(sname, (rt_uint16_t *)dirent->name, namelen); @@ -298,8 +304,11 @@ static struct iso9660_fd *iso9660_lookup(struct iso9660 *iso, const char *path, { if (!(rt_le32_to_cpu(dirent->flags) & FLAG_TYPE_DIR)) { - /* Remove ";1" */ - namelen -= 2; + /* Remove ";1", but only when the name is long enough */ + if (namelen >= 2) + { + namelen -= 2; + } } iso9660_convert_lower(sname, (rt_uint8_t *)dirent->name, namelen);