Skip to content

Commit 2d86361

Browse files
name2965namjaejeon
authored andcommitted
exfat: fix out-of-bounds in exfat_nls_to_ucs2()
Since the len argument value passed to exfat_ioctl_set_volume_label() from exfat_nls_to_utf16() is passed 1 too large, an out-of-bounds read occurs when dereferencing p_cstring in exfat_nls_to_ucs2() later. And because of the NLS_NAME_OVERLEN macro, another error occurs when creating a file with a period at the end using utf8 and other iocharsets. So to avoid this, you should remove the code that uses NLS_NAME_OVERLEN macro and make the len argument value be the length of the label string, but with a maximum length of FSLABEL_MAX - 1. Reported-by: syzbot+98cc76a76de46b3714d4@syzkaller.appspotmail.com Closes: https://syzkaller.appspot.com/bug?extid=98cc76a76de46b3714d4 Fixes: d01579d ("exfat: Add support for FS_IOC_{GET,SET}FSLABEL") Suggested-by: Pali Rohár <pali@kernel.org> Signed-off-by: Jeongjun Park <aha310510@gmail.com> Signed-off-by: Namjae Jeon <linkinjeon@kernel.org>
1 parent 82ebecd commit 2d86361

File tree

4 files changed

+5
-8
lines changed

4 files changed

+5
-8
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: 1 addition & 1 deletion
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
}

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)