Skip to content

Commit aa2a739

Browse files
namjaejeonSteve French
authored andcommitted
cifs: fix incorrect validation for num_aces field of smb_acl
parse_dcal() validate num_aces to allocate ace array. f (num_aces > ULONG_MAX / sizeof(struct smb_ace *)) It is an incorrect validation that we can create an array of size ULONG_MAX. smb_acl has ->size field to calculate actual number of aces in response buffer size. Use this to check invalid num_aces. Signed-off-by: Namjae Jeon <linkinjeon@kernel.org> Signed-off-by: Steve French <stfrench@microsoft.com>
1 parent 1b8b67f commit aa2a739

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

fs/smb/client/cifsacl.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -778,7 +778,8 @@ static void parse_dacl(struct smb_acl *pdacl, char *end_of_acl,
778778
}
779779

780780
/* validate that we do not go past end of acl */
781-
if (end_of_acl < (char *)pdacl + le16_to_cpu(pdacl->size)) {
781+
if (end_of_acl < (char *)pdacl + sizeof(struct smb_acl) ||
782+
end_of_acl < (char *)pdacl + le16_to_cpu(pdacl->size)) {
782783
cifs_dbg(VFS, "ACL too small to parse DACL\n");
783784
return;
784785
}
@@ -799,8 +800,11 @@ static void parse_dacl(struct smb_acl *pdacl, char *end_of_acl,
799800
if (num_aces > 0) {
800801
umode_t denied_mode = 0;
801802

802-
if (num_aces > ULONG_MAX / sizeof(struct smb_ace *))
803+
if (num_aces > (le16_to_cpu(pdacl->size) - sizeof(struct smb_acl)) /
804+
(offsetof(struct smb_ace, sid) +
805+
offsetof(struct smb_sid, sub_auth) + sizeof(__le16)))
803806
return;
807+
804808
ppace = kmalloc_array(num_aces, sizeof(struct smb_ace *),
805809
GFP_KERNEL);
806810
if (!ppace)

0 commit comments

Comments
 (0)