]> www.infradead.org Git - users/willy/pagecache.git/commitdiff
ksmbd: fix incorrect validation for num_aces field of smb_acl
authorNamjae Jeon <linkinjeon@kernel.org>
Wed, 12 Feb 2025 00:32:11 +0000 (09:32 +0900)
committerSteve French <stfrench@microsoft.com>
Mon, 3 Mar 2025 04:50:54 +0000 (22:50 -0600)
parse_dcal() validate num_aces to allocate posix_ace_state_array.

if (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 request buffer
size. Use this to check invalid num_aces.

Reported-by: Igor Leite Ladessa <igor-ladessa@hotmail.com>
Tested-by: Igor Leite Ladessa <igor-ladessa@hotmail.com>
Signed-off-by: Namjae Jeon <linkinjeon@kernel.org>
Signed-off-by: Steve French <stfrench@microsoft.com>
fs/smb/server/smbacl.c

index 561f80d3f953e51896adfdae5c963bd8fce9788c..49b128698670a826beb01d65ee6e53c38ca5a407 100644 (file)
@@ -398,7 +398,9 @@ static void parse_dacl(struct mnt_idmap *idmap,
        if (num_aces <= 0)
                return;
 
-       if (num_aces > ULONG_MAX / sizeof(struct smb_ace *))
+       if (num_aces > (le16_to_cpu(pdacl->size) - sizeof(struct smb_acl)) /
+                       (offsetof(struct smb_ace, sid) +
+                        offsetof(struct smb_sid, sub_auth) + sizeof(__le16)))
                return;
 
        ret = init_acl_state(&acl_state, num_aces);
@@ -432,6 +434,7 @@ static void parse_dacl(struct mnt_idmap *idmap,
                        offsetof(struct smb_sid, sub_auth);
 
                if (end_of_acl - acl_base < acl_size ||
+                   ppace[i]->sid.num_subauth == 0 ||
                    ppace[i]->sid.num_subauth > SID_MAX_SUB_AUTHORITIES ||
                    (end_of_acl - acl_base <
                     acl_size + sizeof(__le32) * ppace[i]->sid.num_subauth) ||