Skip to content

Commit c2fdf82

Browse files
namjaejeongregkh
authored andcommitted
exfat: check if filename entries exceeds max filename length
[ Upstream commit d423345 ] exfat_extract_uni_name copies characters from a given file name entry into the 'uniname' variable. This variable is actually defined on the stack of the exfat_readdir() function. According to the definition of the 'exfat_uni_name' type, the file name should be limited 255 characters (+ null teminator space), but the exfat_get_uniname_from_ext_entry() function can write more characters because there is no check if filename entries exceeds max filename length. This patch add the check not to copy filename characters when exceeding max filename length. Cc: stable@vger.kernel.org Cc: Yuezhang Mo <Yuezhang.Mo@sony.com> Reported-by: Maxim Suhanov <dfirblog@gmail.com> Reviewed-by: Sungjong Seo <sj1557.seo@samsung.com> Signed-off-by: Namjae Jeon <linkinjeon@kernel.org> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent e2fb24c commit c2fdf82

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

fs/exfat/dir.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ static void exfat_get_uniname_from_ext_entry(struct super_block *sb,
3434
{
3535
int i;
3636
struct exfat_entry_set_cache *es;
37+
unsigned int uni_len = 0, len;
3738

3839
es = exfat_get_dentry_set(sb, p_dir, entry, ES_ALL_ENTRIES);
3940
if (!es)
@@ -52,7 +53,10 @@ static void exfat_get_uniname_from_ext_entry(struct super_block *sb,
5253
if (exfat_get_entry_type(ep) != TYPE_EXTEND)
5354
break;
5455

55-
exfat_extract_uni_name(ep, uniname);
56+
len = exfat_extract_uni_name(ep, uniname);
57+
uni_len += len;
58+
if (len != EXFAT_FILE_NAME_LEN || uni_len >= MAX_NAME_LENGTH)
59+
break;
5660
uniname += EXFAT_FILE_NAME_LEN;
5761
}
5862

@@ -1024,7 +1028,8 @@ int exfat_find_dir_entry(struct super_block *sb, struct exfat_inode_info *ei,
10241028
if (entry_type == TYPE_EXTEND) {
10251029
unsigned short entry_uniname[16], unichar;
10261030

1027-
if (step != DIRENT_STEP_NAME) {
1031+
if (step != DIRENT_STEP_NAME ||
1032+
name_len >= MAX_NAME_LENGTH) {
10281033
step = DIRENT_STEP_FILE;
10291034
continue;
10301035
}

0 commit comments

Comments
 (0)