Skip to content

Commit

Permalink
ksmbd: free ppace array on error in parse_dacl
Browse files Browse the repository at this point in the history
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: e2f34481b24d ("cifsd: add server-side procedures for SMB3")
Cc: [email protected]
Signed-off-by: Fedor Pchelkin <[email protected]>
Signed-off-by: Namjae Jeon <[email protected]>
  • Loading branch information
pchelkin91 authored and namjaejeon committed Jan 9, 2024
1 parent 178a041 commit 4c6bb4f
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions smbacl.c
Original file line number Diff line number Diff line change
Expand Up @@ -459,10 +459,6 @@ static void parse_dacl(struct user_namespace *user_ns,
if (num_aces > ULONG_MAX / sizeof(struct smb_ace *))
return;

ppace = kmalloc_array(num_aces, sizeof(struct smb_ace *), GFP_KERNEL);
if (!ppace)
return;

ret = init_acl_state(&acl_state, num_aces);
if (ret)
return;
Expand All @@ -472,6 +468,13 @@ static void parse_dacl(struct user_namespace *user_ns,
return;
}

ppace = kmalloc_array(num_aces, sizeof(struct smb_ace *), GFP_KERNEL);
if (!ppace) {
free_acl_state(&default_acl_state);
free_acl_state(&acl_state);
return;
}

/*
* reset rwx permissions for user/group/other.
* Also, if num_aces is 0 i.e. DACL has no ACEs,
Expand Down

0 comments on commit 4c6bb4f

Please sign in to comment.