Skip to content

Commit e0b0cb9

Browse files
Navidemgregkh
authored andcommitted
virt: vbox: fix memory leak in hgcm_call_preprocess_linaddr
In hgcm_call_preprocess_linaddr memory is allocated for bounce_buf but is not released if copy_form_user fails. In order to prevent memory leak in case of failure, the assignment to bounce_buf_ret is moved before the error check. This way the allocated bounce_buf will be released by the caller. Fixes: 579db9d ("virt: Add vboxguest VMMDEV communication code") Signed-off-by: Navid Emamdoost <[email protected]> Reviewed-by: Hans de Goede <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 5dc54a0 commit e0b0cb9

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

drivers/virt/vboxguest/vboxguest_utils.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,8 @@ static int hgcm_call_preprocess_linaddr(
220220
if (!bounce_buf)
221221
return -ENOMEM;
222222

223+
*bounce_buf_ret = bounce_buf;
224+
223225
if (copy_in) {
224226
ret = copy_from_user(bounce_buf, (void __user *)buf, len);
225227
if (ret)
@@ -228,7 +230,6 @@ static int hgcm_call_preprocess_linaddr(
228230
memset(bounce_buf, 0, len);
229231
}
230232

231-
*bounce_buf_ret = bounce_buf;
232233
hgcm_call_add_pagelist_size(bounce_buf, len, extra);
233234
return 0;
234235
}

0 commit comments

Comments
 (0)