Skip to content

Commit 847f242

Browse files
committed
Merge tag 'exfat-for-6.18-rc2' of git://git.kernel.org/pub/scm/linux/kernel/git/linkinjeon/exfat
Pull exfat fixes from Namjae Jeon: - Fix out-of-bounds in FS_IOC_SETFSLABEL - Add validation for stream entry size to prevent infinite loop * tag 'exfat-for-6.18-rc2' of git://git.kernel.org/pub/scm/linux/kernel/git/linkinjeon/exfat: exfat: fix out-of-bounds in exfat_nls_to_ucs2() exfat: fix improper check of dentry.stream.valid_size
2 parents 2d07c6c + 2d86361 commit 847f242

File tree

4 files changed

+10
-9
lines changed

4 files changed

+10
-9
lines changed

fs/exfat/exfat_fs.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ enum exfat_error_mode {
2929
enum {
3030
NLS_NAME_NO_LOSSY = 0, /* no lossy */
3131
NLS_NAME_LOSSY = 1 << 0, /* just detected incorrect filename(s) */
32-
NLS_NAME_OVERLEN = 1 << 1, /* the length is over than its limit */
3332
};
3433

3534
#define EXFAT_HASH_BITS 8

fs/exfat/file.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -509,8 +509,8 @@ static int exfat_ioctl_get_volume_label(struct super_block *sb, unsigned long ar
509509
static int exfat_ioctl_set_volume_label(struct super_block *sb,
510510
unsigned long arg)
511511
{
512-
int ret = 0, lossy;
513-
char label[FSLABEL_MAX];
512+
int ret = 0, lossy, label_len;
513+
char label[FSLABEL_MAX] = {0};
514514
struct exfat_uni_name uniname;
515515

516516
if (!capable(CAP_SYS_ADMIN))
@@ -520,8 +520,9 @@ static int exfat_ioctl_set_volume_label(struct super_block *sb,
520520
return -EFAULT;
521521

522522
memset(&uniname, 0, sizeof(uniname));
523+
label_len = strnlen(label, FSLABEL_MAX - 1);
523524
if (label[0]) {
524-
ret = exfat_nls_to_utf16(sb, label, FSLABEL_MAX,
525+
ret = exfat_nls_to_utf16(sb, label, label_len,
525526
&uniname, &lossy);
526527
if (ret < 0)
527528
return ret;

fs/exfat/namei.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,7 @@ static int __exfat_resolve_path(struct inode *inode, const unsigned char *path,
442442
return namelen; /* return error value */
443443

444444
if ((lossy && !lookup) || !namelen)
445-
return (lossy & NLS_NAME_OVERLEN) ? -ENAMETOOLONG : -EINVAL;
445+
return -EINVAL;
446446

447447
return 0;
448448
}
@@ -642,10 +642,14 @@ static int exfat_find(struct inode *dir, const struct qstr *qname,
642642

643643
info->type = exfat_get_entry_type(ep);
644644
info->attr = le16_to_cpu(ep->dentry.file.attr);
645-
info->size = le64_to_cpu(ep2->dentry.stream.valid_size);
646645
info->valid_size = le64_to_cpu(ep2->dentry.stream.valid_size);
647646
info->size = le64_to_cpu(ep2->dentry.stream.size);
648647

648+
if (info->valid_size < 0) {
649+
exfat_fs_error(sb, "data valid size is invalid(%lld)", info->valid_size);
650+
return -EIO;
651+
}
652+
649653
if (unlikely(EXFAT_B_TO_CLU_ROUND_UP(info->size, sbi) > sbi->used_clusters)) {
650654
exfat_fs_error(sb, "data size is invalid(%lld)", info->size);
651655
return -EIO;

fs/exfat/nls.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -616,9 +616,6 @@ static int exfat_nls_to_ucs2(struct super_block *sb,
616616
unilen++;
617617
}
618618

619-
if (p_cstring[i] != '\0')
620-
lossy |= NLS_NAME_OVERLEN;
621-
622619
*uniname = '\0';
623620
p_uniname->name_len = unilen;
624621
p_uniname->name_hash = exfat_calc_chksum16(upname, unilen << 1, 0,

0 commit comments

Comments
 (0)