Skip to content

Commit b0bea6f

Browse files
Zongmin Zhouroxanan1996
authored andcommitted
ksmbd: prevent memory leak on error return
BugLink: https://bugs.launchpad.net/bugs/2052406 [ Upstream commit 9004448 ] When allocated memory for 'new' failed,just return will cause memory leak of 'ar'. Fixes: 1819a90 ("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> Acked-by: Namjae Jeon <linkinjeon@kernel.org> Signed-off-by: Steve French <stfrench@microsoft.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Signed-off-by: Portia Stephens <portia.stephens@canonical.com> Signed-off-by: Roxana Nicolescu <roxana.nicolescu@canonical.com>
1 parent 17b35a7 commit b0bea6f

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

fs/ksmbd/ksmbd_work.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ static inline void __ksmbd_iov_pin(struct ksmbd_work *work, void *ib,
106106
static int __ksmbd_iov_pin_rsp(struct ksmbd_work *work, void *ib, int len,
107107
void *aux_buf, unsigned int aux_size)
108108
{
109-
struct aux_read *ar;
109+
struct aux_read *ar = NULL;
110110
int need_iov_cnt = 1;
111111

112112
if (aux_size) {
@@ -123,8 +123,11 @@ static int __ksmbd_iov_pin_rsp(struct ksmbd_work *work, void *ib, int len,
123123
new = krealloc(work->iov,
124124
sizeof(struct kvec) * work->iov_alloc_cnt,
125125
GFP_KERNEL | __GFP_ZERO);
126-
if (!new)
126+
if (!new) {
127+
kfree(ar);
128+
work->iov_alloc_cnt -= 4;
127129
return -ENOMEM;
130+
}
128131
work->iov = new;
129132
}
130133

0 commit comments

Comments
 (0)