diff mbox series

ksmbd: prevent memory leak on error return

Message ID 20231108081502.3113828-1-min_halo@163.com (mailing list archive)
State New, archived
Headers show
Series ksmbd: prevent memory leak on error return | expand

Commit Message

Zongmin Zhou Nov. 8, 2023, 8:15 a.m. UTC
When allocated memory for 'new' failed,just return
will cause memory leak of 'ar'.

Fixes: 1819a9042999 ("ksmbd: reorganize ksmbd_iov_pin_rsp()")

Reported-by: kernel test robot <lkp@intel.com>
Reported-by: Dan Carpenter <error27@gmail.com>
Closes: https://lore.kernel.org/r/202311031837.H3yo7JVl-lkp@intel.com/
Signed-off-by: Zongmin Zhou<zhouzongmin@kylinos.cn>
---
 fs/smb/server/ksmbd_work.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

Comments

Namjae Jeon Nov. 8, 2023, 10:36 a.m. UTC | #1
2023-11-08 17:15 GMT+09:00, Zongmin Zhou <min_halo@163.com>:
> When allocated memory for 'new' failed,just return
> will cause memory leak of 'ar'.
>
> Fixes: 1819a9042999 ("ksmbd: reorganize ksmbd_iov_pin_rsp()")
>
> Reported-by: kernel test robot <lkp@intel.com>
> Reported-by: Dan Carpenter <error27@gmail.com>
> Closes: https://lore.kernel.org/r/202311031837.H3yo7JVl-lkp@intel.com/
> Signed-off-by: Zongmin Zhou<zhouzongmin@kylinos.cn>
> ---
>  fs/smb/server/ksmbd_work.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/fs/smb/server/ksmbd_work.c b/fs/smb/server/ksmbd_work.c
> index a2ed441e837a..dbbef686e160 100644
> --- a/fs/smb/server/ksmbd_work.c
> +++ b/fs/smb/server/ksmbd_work.c
> @@ -123,8 +123,10 @@ static int __ksmbd_iov_pin_rsp(struct ksmbd_work *work,
> void *ib, int len,
>  		new = krealloc(work->iov,
>  			       sizeof(struct kvec) * work->iov_alloc_cnt,
>  			       GFP_KERNEL | __GFP_ZERO);
> -		if (!new)
> +		if (!new) {
> +			kfree(ar);
Looks good to me:)
Can you add the below code to rollback ->iov_alloc_cnt ?
                       work->iov_alloc_cnt -= 4;
Thanks!
>  			return -ENOMEM;
> +		}
>  		work->iov = new;
>  	}
>
> --
> 2.34.1
>
>
>
diff mbox series

Patch

diff --git a/fs/smb/server/ksmbd_work.c b/fs/smb/server/ksmbd_work.c
index a2ed441e837a..dbbef686e160 100644
--- a/fs/smb/server/ksmbd_work.c
+++ b/fs/smb/server/ksmbd_work.c
@@ -123,8 +123,10 @@  static int __ksmbd_iov_pin_rsp(struct ksmbd_work *work, void *ib, int len,
 		new = krealloc(work->iov,
 			       sizeof(struct kvec) * work->iov_alloc_cnt,
 			       GFP_KERNEL | __GFP_ZERO);
-		if (!new)
+		if (!new) {
+			kfree(ar);
 			return -ENOMEM;
+		}
 		work->iov = new;
 	}