summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFedor Pchelkin <pchelkin@ispras.ru>2024-01-09 17:14:44 +0300
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2024-01-20 11:53:01 +0100
commit68f9b0945b19e8140239c6043f7a9b01f1d1a529 (patch)
tree9a110ef6ce6bb1b508cfe980de2893a64b77fbf9
parent4f6638562db5f9568dbfbe3a2a6ac80c4832f19e (diff)
downloadlinux-stable-68f9b0945b19e8140239c6043f7a9b01f1d1a529.tar.gz
linux-stable-68f9b0945b19e8140239c6043f7a9b01f1d1a529.tar.bz2
linux-stable-68f9b0945b19e8140239c6043f7a9b01f1d1a529.zip
ksmbd: free ppace array on error in parse_dacl
commit 8cf9bedfc3c47d24bb0de386f808f925dc52863e upstream. 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: 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> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
-rw-r--r--fs/smb/server/smbacl.c11
1 files changed, 7 insertions, 4 deletions
diff --git a/fs/smb/server/smbacl.c b/fs/smb/server/smbacl.c
index 1164365533f0..1c9775f1efa5 100644
--- a/fs/smb/server/smbacl.c
+++ b/fs/smb/server/smbacl.c
@@ -401,10 +401,6 @@ static void parse_dacl(struct mnt_idmap *idmap,
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;
@@ -414,6 +410,13 @@ static void parse_dacl(struct mnt_idmap *idmap,
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,