Skip to content

Commit d423345

Browse files
committed
exfat: check if filename entries exceeds max filename length
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: [email protected] Cc: Yuezhang Mo <[email protected]> Reported-by: Maxim Suhanov <[email protected]> Reviewed-by: Sungjong Seo <[email protected]> Signed-off-by: Namjae Jeon <[email protected]>
1 parent daf60d6 commit d423345

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 int exfat_get_uniname_from_ext_entry(struct super_block *sb,
3434
{
3535
int i, err;
3636
struct exfat_entry_set_cache es;
37+
unsigned int uni_len = 0, len;
3738

3839
err = exfat_get_dentry_set(&es, sb, p_dir, entry, ES_ALL_ENTRIES);
3940
if (err)
@@ -52,7 +53,10 @@ static int 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

@@ -1079,7 +1083,8 @@ int exfat_find_dir_entry(struct super_block *sb, struct exfat_inode_info *ei,
10791083
if (entry_type == TYPE_EXTEND) {
10801084
unsigned short entry_uniname[16], unichar;
10811085

1082-
if (step != DIRENT_STEP_NAME) {
1086+
if (step != DIRENT_STEP_NAME ||
1087+
name_len >= MAX_NAME_LENGTH) {
10831088
step = DIRENT_STEP_FILE;
10841089
continue;
10851090
}

0 commit comments

Comments
 (0)