Skip to content

Commit 8cf9bed

Browse files
pchelkin91Steve French
authored andcommitted
ksmbd: free ppace array on error in parse_dacl
The ppace array is not freed if one of the init_acl_state() calls inside parse_dacl() fails. At the moment the function may fail only due to the memory allocation errors so it's highly unlikely in this case but nevertheless a fix is needed. Move ppace allocation after the init_acl_state() calls with proper error handling. Found by Linux Verification Center (linuxtesting.org). Fixes: e2f3448 ("cifsd: add server-side procedures for SMB3") Cc: stable@vger.kernel.org Signed-off-by: Fedor Pchelkin <pchelkin@ispras.ru> Acked-by: Namjae Jeon <linkinjeon@kernel.org> Signed-off-by: Steve French <stfrench@microsoft.com>
1 parent 3fc74c6 commit 8cf9bed

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

fs/smb/server/smbacl.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -401,10 +401,6 @@ static void parse_dacl(struct mnt_idmap *idmap,
401401
if (num_aces > ULONG_MAX / sizeof(struct smb_ace *))
402402
return;
403403

404-
ppace = kmalloc_array(num_aces, sizeof(struct smb_ace *), GFP_KERNEL);
405-
if (!ppace)
406-
return;
407-
408404
ret = init_acl_state(&acl_state, num_aces);
409405
if (ret)
410406
return;
@@ -414,6 +410,13 @@ static void parse_dacl(struct mnt_idmap *idmap,
414410
return;
415411
}
416412

413+
ppace = kmalloc_array(num_aces, sizeof(struct smb_ace *), GFP_KERNEL);
414+
if (!ppace) {
415+
free_acl_state(&default_acl_state);
416+
free_acl_state(&acl_state);
417+
return;
418+
}
419+
417420
/*
418421
* reset rwx permissions for user/group/other.
419422
* Also, if num_aces is 0 i.e. DACL has no ACEs,

0 commit comments

Comments
 (0)