From: Pierre Mariani <pierre.mariani@gmail.com>
To: Zongmin Zhou <min_halo@163.com>, linkinjeon@kernel.org
Cc: linux-cifs@vger.kernel.org, linux-kernel@vger.kernel.org,
senozhatsky@chromium.org, sfrench@samba.org, tom@talpey.com,
kernel test robot <lkp@intel.com>,
Dan Carpenter <error27@gmail.com>,
Zongmin Zhou <zhouzongmin@kylinos.cn>
Subject: Re: [PATCH v2] ksmbd: prevent memory leak on error return
Date: Sun, 19 Nov 2023 01:14:06 -0800 [thread overview]
Message-ID: <b503d929-ff3a-4dc3-9de8-aa0eb00d181a@gmail.com> (raw)
In-Reply-To: <20231109011725.1798784-1-min_halo@163.com>
On 11/8/2023 5:17 PM, Zongmin Zhou wrote:
> When allocated memory for 'new' failed,just return
> will cause memory leak of 'ar'.
>
> v2: rollback iov_alloc_cnt when allocate memory failed.
>
> 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 | 5 ++++-
> 1 file changed, 4 insertions(+), 1 deletion(-)
>
> diff --git a/fs/smb/server/ksmbd_work.c b/fs/smb/server/ksmbd_work.c
> index a2ed441e837a..44bce4c56daf 100644
> --- a/fs/smb/server/ksmbd_work.c
> +++ b/fs/smb/server/ksmbd_work.c
> @@ -123,8 +123,11 @@ 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);
> + work->iov_alloc_cnt -= 4;
> return -ENOMEM;
> + }
> work->iov = new;
> }
>
A few lines above, ar is allocated inside the 'if (aux_size)' block.
If aux_size is falsy, isn't it possible that ar will be NULL hence
we should have 'if (ar) kfree(ar);'?
next prev parent reply other threads:[~2023-11-19 9:14 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-11-08 8:15 [PATCH] " Zongmin Zhou
2023-11-08 10:36 ` Namjae Jeon
2023-11-09 1:17 ` [PATCH v2] " Zongmin Zhou
2023-11-09 13:21 ` Namjae Jeon
2023-11-19 9:14 ` Pierre Mariani [this message]
2023-11-19 14:17 ` Namjae Jeon
2023-11-20 1:33 ` Zongmin Zhou
2023-11-20 1:38 ` Namjae Jeon
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=b503d929-ff3a-4dc3-9de8-aa0eb00d181a@gmail.com \
--to=pierre.mariani@gmail.com \
--cc=error27@gmail.com \
--cc=linkinjeon@kernel.org \
--cc=linux-cifs@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=lkp@intel.com \
--cc=min_halo@163.com \
--cc=senozhatsky@chromium.org \
--cc=sfrench@samba.org \
--cc=tom@talpey.com \
--cc=zhouzongmin@kylinos.cn \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®