linux-cifs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] cifsd: fix memory leak when loop ends
@ 2021-04-01  7:55 ` Muhammad Usama Anjum
  2021-04-01  8:17   ` Namjae Jeon
  0 siblings, 1 reply; 2+ messages in thread
From: Muhammad Usama Anjum @ 2021-04-01  7:55 UTC (permalink / raw)
  To: Namjae Jeon, Sergey Senozhatsky, Steve French, Hyunchul Lee,
	open list:COMMON INTERNET FILE SYSTEM SERVER (CIFSD),
	open list:COMMON INTERNET FILE SYSTEM SERVER (CIFSD),
	open list, kernel-janitors, colin.king, dan.carpenter
  Cc: musamaanjum

Memory is being allocated and if veto_list is zero, the loop breaks
without cleaning up the allocated memory. In this patch, the length
check has been moved before allocation. If loop breaks, the memory isn't
allocated in the first place. Thus the memory is being protected from
leaking.

Signed-off-by: Muhammad Usama Anjum <musamaanjum@gmail.com>
---
 fs/cifsd/mgmt/share_config.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/fs/cifsd/mgmt/share_config.c b/fs/cifsd/mgmt/share_config.c
index db780febd692..b2bd789af945 100644
--- a/fs/cifsd/mgmt/share_config.c
+++ b/fs/cifsd/mgmt/share_config.c
@@ -92,14 +92,14 @@ static int parse_veto_list(struct ksmbd_share_config *share,
 	while (veto_list_sz > 0) {
 		struct ksmbd_veto_pattern *p;
 
-		p = kzalloc(sizeof(struct ksmbd_veto_pattern), GFP_KERNEL);
-		if (!p)
-			return -ENOMEM;
-
 		sz = strlen(veto_list);
 		if (!sz)
 			break;
 
+		p = kzalloc(sizeof(struct ksmbd_veto_pattern), GFP_KERNEL);
+		if (!p)
+			return -ENOMEM;
+
 		p->pattern = kstrdup(veto_list, GFP_KERNEL);
 		if (!p->pattern) {
 			ksmbd_free(p);
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* RE: [PATCH] cifsd: fix memory leak when loop ends
  2021-04-01  7:55 ` [PATCH] cifsd: fix memory leak when loop ends Muhammad Usama Anjum
@ 2021-04-01  8:17   ` Namjae Jeon
  0 siblings, 0 replies; 2+ messages in thread
From: Namjae Jeon @ 2021-04-01  8:17 UTC (permalink / raw)
  To: 'Muhammad Usama Anjum', 'Sergey Senozhatsky',
	'Steve French', 'Hyunchul Lee',
	'open list:COMMON INTERNET FILE SYSTEM SERVER (CIFSD)',
	'open list:COMMON INTERNET FILE SYSTEM SERVER (CIFSD)',
	'open list',
	kernel-janitors, colin.king, dan.carpenter

> 
> Memory is being allocated and if veto_list is zero, the loop breaks without cleaning up the allocated
> memory. In this patch, the length check has been moved before allocation. If loop breaks, the memory
> isn't allocated in the first place. Thus the memory is being protected from leaking.
> 
> Signed-off-by: Muhammad Usama Anjum <musamaanjum@gmail.com>
I will apply. Thanks for your patch!


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-04-01  8:18 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <CGME20210401075539epcas1p3b7cb52923217b212c80185aab135fe22@epcas1p3.samsung.com>
2021-04-01  7:55 ` [PATCH] cifsd: fix memory leak when loop ends Muhammad Usama Anjum
2021-04-01  8:17   ` 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).