Re: [PATCH] fs/ntfs3: Fix OOB write if ret == buf_len in ntfs_utf16_to_nls()
kernel test robot <[email protected]> Wed, 8 Jul 2026 16:15:43 +0800
| Newsgroups | dev.linux.lists.ntfs3,dev.linux.lists.oe-kbuild-all |
|---|---|
| Message-ID | <[email protected]> |
Hi Alexandro, kernel test robot noticed the following build warnings: [auto build test WARNING on 0e35b9b6ec0ffcc5e23cbdec09f5c622ad532b53] url: https://github.com/intel-lab-lkp/linux/commits/Alexandro-Cal/fs-ntfs3-Fix-OOB-write-if-ret-buf_len-in-ntfs_utf16_to_nls/20260708-001557 base: 0e35b9b6ec0ffcc5e23cbdec09f5c622ad532b53 patch link: https://lore.kernel.org/r/3EFE7695-DA5B-4A28-8E39-4853BBA784FC%40nozominetworks.com patch subject: [PATCH] fs/ntfs3: Fix OOB write if ret == buf_len in ntfs_utf16_to_nls() config: x86_64-randconfig-161 (https://download.01.org/0day-ci/archive/20260708/[email protected]/config) compiler: gcc-14 (Debian 14.2.0-19) 14.2.0 smatch: v0.5.0-9185-gbcc58b9c If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags | Reported-by: kernel test robot <[email protected]> | Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/ smatch warnings: fs/ntfs3/dir.c:32 ntfs_utf16_to_nls() warn: inconsistent indenting vim +32 fs/ntfs3/dir.c 17 18 /* Convert little endian UTF-16 to NLS string. */ 19 int ntfs_utf16_to_nls(struct ntfs_sb_info *sbi, const __le16 *name, u32 len, 20 u8 *buf, int buf_len) 21 { 22 int ret, warn; 23 u8 *op; 24 struct nls_table *nls = sbi->options->nls; 25 26 static_assert(sizeof(wchar_t) == sizeof(__le16)); 27 28 if (!nls) { 29 /* UTF-16 -> UTF-8 */ 30 ret = utf16s_to_utf8s((wchar_t *)name, len, UTF16_LITTLE_ENDIAN, 31 buf, buf_len); > 32 if (ret >= buf_len) { 33 ret = buf_len-1; 34 } 35 buf[ret] = '\0'; 36 return ret; 37 } 38 39 op = buf; 40 warn = 0; 41 42 while (len--) { 43 u16 ec; 44 int charlen; 45 char dump[5]; 46 47 if (buf_len < NLS_MAX_CHARSET_SIZE) { 48 ntfs_warn(sbi->sb, 49 "filename was truncated while converting."); 50 break; 51 } 52 53 ec = le16_to_cpu(*name++); 54 charlen = nls->uni2char(ec, op, buf_len); 55 56 if (charlen > 0) { 57 op += charlen; 58 buf_len -= charlen; 59 continue; 60 } 61 62 *op++ = '_'; 63 buf_len -= 1; 64 if (warn) 65 continue; 66 67 warn = 1; 68 hex_byte_pack(&dump[0], ec >> 8); 69 hex_byte_pack(&dump[2], ec); 70 dump[4] = 0; 71 72 ntfs_err(sbi->sb, "failed to convert \"%s\" to %s", dump, 73 nls->charset); 74 } 75 76 *op = '\0'; 77 return op - buf; 78 } 79 -- 0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki