* [PATCH] ksmbd: free ppace array on error in parse_dacl
@ 2024-01-09 13:34 Fedor Pchelkin
2024-01-09 13:46 ` Namjae Jeon
0 siblings, 1 reply; 4+ messages in thread
From: Fedor Pchelkin @ 2024-01-09 13:34 UTC (permalink / raw)
To: Namjae Jeon
Cc: Fedor Pchelkin, Steve French, Sergey Senozhatsky, Tom Talpey,
Ronnie Sahlberg, Hyunchul Lee, linux-cifs, linux-kernel,
Alexey Khoroshilov, lvc-project
Free the ppace array 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.
Found by Linux Verification Center (linuxtesting.org).
Fixes: e2f34481b24d ("cifsd: add server-side procedures for SMB3")
Signed-off-by: Fedor Pchelkin <pchelkin@ispras.ru>
---
fs/smb/server/smbacl.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/fs/smb/server/smbacl.c b/fs/smb/server/smbacl.c
index 1164365533f0..e6d0537cab49 100644
--- a/fs/smb/server/smbacl.c
+++ b/fs/smb/server/smbacl.c
@@ -406,11 +406,14 @@ static void parse_dacl(struct mnt_idmap *idmap,
return;
ret = init_acl_state(&acl_state, num_aces);
- if (ret)
+ if (ret) {
+ kfree(ppace);
return;
+ }
ret = init_acl_state(&default_acl_state, num_aces);
if (ret) {
free_acl_state(&acl_state);
+ kfree(ppace);
return;
}
--
2.43.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] ksmbd: free ppace array on error in parse_dacl
2024-01-09 13:34 [PATCH] ksmbd: free ppace array on error in parse_dacl Fedor Pchelkin
@ 2024-01-09 13:46 ` Namjae Jeon
2024-01-09 14:14 ` [PATCH v2] " Fedor Pchelkin
0 siblings, 1 reply; 4+ messages in thread
From: Namjae Jeon @ 2024-01-09 13:46 UTC (permalink / raw)
To: Fedor Pchelkin
Cc: Steve French, Sergey Senozhatsky, Tom Talpey, Ronnie Sahlberg,
Hyunchul Lee, linux-cifs, linux-kernel, Alexey Khoroshilov,
lvc-project
2024-01-09 22:34 GMT+09:00, Fedor Pchelkin <pchelkin@ispras.ru>:
> Free the ppace array 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.
>
> Found by Linux Verification Center (linuxtesting.org).
>
> Fixes: e2f34481b24d ("cifsd: add server-side procedures for SMB3")
> Signed-off-by: Fedor Pchelkin <pchelkin@ispras.ru>
> ---
> fs/smb/server/smbacl.c | 5 ++++-
> 1 file changed, 4 insertions(+), 1 deletion(-)
>
> diff --git a/fs/smb/server/smbacl.c b/fs/smb/server/smbacl.c
> index 1164365533f0..e6d0537cab49 100644
> --- a/fs/smb/server/smbacl.c
> +++ b/fs/smb/server/smbacl.c
> @@ -406,11 +406,14 @@ static void parse_dacl(struct mnt_idmap *idmap,
> return;
>
> ret = init_acl_state(&acl_state, num_aces);
> - if (ret)
> + if (ret) {
> + kfree(ppace);
> return;
> + }
> ret = init_acl_state(&default_acl_state, num_aces);
> if (ret) {
> free_acl_state(&acl_state);
> + kfree(ppace);
> return;
> }
Looks good to me.
But rather than this, How about moving ppace allocation here ?
Thanks for your patch.
>
> --
> 2.43.0
>
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH v2] ksmbd: free ppace array on error in parse_dacl
2024-01-09 13:46 ` Namjae Jeon
@ 2024-01-09 14:14 ` Fedor Pchelkin
2024-01-10 0:28 ` Namjae Jeon
0 siblings, 1 reply; 4+ messages in thread
From: Fedor Pchelkin @ 2024-01-09 14:14 UTC (permalink / raw)
To: Namjae Jeon
Cc: Fedor Pchelkin, Steve French, Sergey Senozhatsky, Tom Talpey,
Hyunchul Lee, linux-cifs, linux-kernel, Alexey Khoroshilov,
lvc-project
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")
Signed-off-by: Fedor Pchelkin <pchelkin@ispras.ru>
---
v2: refine the patch with moving ppace allocation into another place per
Namjae's suggestion; update the commit description accordingly.
fs/smb/server/smbacl.c | 11 +++++++----
1 file 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,
--
2.43.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH v2] ksmbd: free ppace array on error in parse_dacl
2024-01-09 14:14 ` [PATCH v2] " Fedor Pchelkin
@ 2024-01-10 0:28 ` Namjae Jeon
0 siblings, 0 replies; 4+ messages in thread
From: Namjae Jeon @ 2024-01-10 0:28 UTC (permalink / raw)
To: Fedor Pchelkin
Cc: Steve French, Sergey Senozhatsky, Tom Talpey, Hyunchul Lee,
linux-cifs, linux-kernel, Alexey Khoroshilov, lvc-project
2024-01-09 23:14 GMT+09:00, Fedor Pchelkin <pchelkin@ispras.ru>:
> 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")
> Signed-off-by: Fedor Pchelkin <pchelkin@ispras.ru>
Acked-by: Namjae Jeon <linkinjeon@kernel.org>
Applied it to #ksmbd-for-next-next.
Thanks for your patch!
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2024-01-10 0:28 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-01-09 13:34 [PATCH] ksmbd: free ppace array on error in parse_dacl Fedor Pchelkin
2024-01-09 13:46 ` Namjae Jeon
2024-01-09 14:14 ` [PATCH v2] " Fedor Pchelkin
2024-01-10 0:28 ` Namjae Jeon
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).