Skip to content

Commit

Permalink
virt: vbox: fix memory leak in hgcm_call_preprocess_linaddr
Browse files Browse the repository at this point in the history
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 <navid.emamdoost@gmail.com>
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
Link: https://lore.kernel.org/r/20190930204223.3660-1-navid.emamdoost@gmail.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
  • Loading branch information
Navidem authored and gregkh committed Oct 10, 2019
1 parent 5dc54a0 commit e0b0cb9
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion drivers/virt/vboxguest/vboxguest_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,8 @@ static int hgcm_call_preprocess_linaddr(
if (!bounce_buf)
return -ENOMEM;

*bounce_buf_ret = bounce_buf;

if (copy_in) {
ret = copy_from_user(bounce_buf, (void __user *)buf, len);
if (ret)
Expand All @@ -228,7 +230,6 @@ static int hgcm_call_preprocess_linaddr(
memset(bounce_buf, 0, len);
}

*bounce_buf_ret = bounce_buf;
hgcm_call_add_pagelist_size(bounce_buf, len, extra);
return 0;
}
Expand Down

0 comments on commit e0b0cb9

Please sign in to comment.