Skip to content

Commit 299f962

Browse files
Tristan Madanismfrench
authored andcommitted
ksmbd: use check_add_overflow() to prevent u16 DACL size overflow
set_posix_acl_entries_dacl() and set_ntacl_dacl() accumulate ACE sizes in u16 variables. When a file has many POSIX ACL entries, the accumulated size can wrap past 65535, causing the pointer arithmetic (char *)pndace + *size to land within already-written ACEs. Subsequent writes then overwrite earlier entries, and pndacl->size gets a truncated value. Use check_add_overflow() at each accumulation point to detect the wrap before it corrupts the buffer, consistent with existing check_mul_overflow() usage elsewhere in smbacl.c. Cc: stable@vger.kernel.org Fixes: e2f3448 ("cifsd: add server-side procedures for SMB3") Signed-off-by: Tristan Madani <tristan@talencesecurity.com> Acked-by: Namjae Jeon <linkinjeon@kernel.org> Signed-off-by: Steve French <stfrench@microsoft.com>
1 parent 1baff47 commit 299f962

1 file changed

Lines changed: 12 additions & 4 deletions

File tree

fs/smb/server/smbacl.c

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -596,6 +596,7 @@ static void set_posix_acl_entries_dacl(struct mnt_idmap *idmap,
596596
struct smb_sid *sid;
597597
struct smb_ace *ntace;
598598
int i, j;
599+
u16 ace_sz;
599600

600601
if (!fattr->cf_acls)
601602
goto posix_default_acl;
@@ -640,8 +641,10 @@ static void set_posix_acl_entries_dacl(struct mnt_idmap *idmap,
640641
flags = 0x03;
641642

642643
ntace = (struct smb_ace *)((char *)pndace + *size);
643-
*size += fill_ace_for_sid(ntace, sid, ACCESS_ALLOWED, flags,
644+
ace_sz = fill_ace_for_sid(ntace, sid, ACCESS_ALLOWED, flags,
644645
pace->e_perm, 0777);
646+
if (check_add_overflow(*size, ace_sz, size))
647+
break;
645648
(*num_aces)++;
646649
if (pace->e_tag == ACL_USER)
647650
ntace->access_req |=
@@ -650,8 +653,10 @@ static void set_posix_acl_entries_dacl(struct mnt_idmap *idmap,
650653
if (S_ISDIR(fattr->cf_mode) &&
651654
(pace->e_tag == ACL_USER || pace->e_tag == ACL_GROUP)) {
652655
ntace = (struct smb_ace *)((char *)pndace + *size);
653-
*size += fill_ace_for_sid(ntace, sid, ACCESS_ALLOWED,
656+
ace_sz = fill_ace_for_sid(ntace, sid, ACCESS_ALLOWED,
654657
0x03, pace->e_perm, 0777);
658+
if (check_add_overflow(*size, ace_sz, size))
659+
break;
655660
(*num_aces)++;
656661
if (pace->e_tag == ACL_USER)
657662
ntace->access_req |=
@@ -691,8 +696,10 @@ static void set_posix_acl_entries_dacl(struct mnt_idmap *idmap,
691696
}
692697

693698
ntace = (struct smb_ace *)((char *)pndace + *size);
694-
*size += fill_ace_for_sid(ntace, sid, ACCESS_ALLOWED, 0x0b,
699+
ace_sz = fill_ace_for_sid(ntace, sid, ACCESS_ALLOWED, 0x0b,
695700
pace->e_perm, 0777);
701+
if (check_add_overflow(*size, ace_sz, size))
702+
break;
696703
(*num_aces)++;
697704
if (pace->e_tag == ACL_USER)
698705
ntace->access_req |=
@@ -728,7 +735,8 @@ static void set_ntacl_dacl(struct mnt_idmap *idmap,
728735
break;
729736

730737
memcpy((char *)pndace + size, ntace, nt_ace_size);
731-
size += nt_ace_size;
738+
if (check_add_overflow(size, nt_ace_size, &size))
739+
break;
732740
aces_size -= nt_ace_size;
733741
ntace = (struct smb_ace *)((char *)ntace + nt_ace_size);
734742
num_aces++;

0 commit comments

Comments
 (0)