Received: by 2002:a25:31c3:0:0:0:0:0 with SMTP id x186csp4482373ybx; Mon, 4 Nov 2019 14:09:59 -0800 (PST) X-Google-Smtp-Source: APXvYqw0felu6CwlpBIIq+zulqh+rp6ueo972ZpC3DXuRPM3VF/0Kz1eD0LfKucFgjbJSnb+Kzlr X-Received: by 2002:a50:c305:: with SMTP id a5mr15259380edb.136.1572905399605; Mon, 04 Nov 2019 14:09:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1572905399; cv=none; d=google.com; s=arc-20160816; b=xWmnvSTOZ9yiUVEehZv0h+xBaA4QIkx+Ki6vLkNQcbSQtzdR275MDMNY8RsstjkqSM FIuMG4SAbw+ypjNbDHwfMIidVRiHAx0Rg5VzaW/NRj1QXSzDzFy0/9o+XDHhJakJuTEh QbynJrkuv9oJIR8iGprPiyv7Ojx3COCX/9V3fWwEDVxN5azsspLBlam/dVqwXAuLaQXt +q+Kb5sOpyrT88xylT/Bl0sVdsc6yFdG7HitG1313AqMlMsrS/Zqb20B9u1TtZgQg2SU nTn174vjSO8p4HYoFcqPhO5Nh19WZSOFLTU+AkJexIRn3yAVfxkh7jKHbsb3gwKhl4kC hOLw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=YOVZ2xpqK0o36i9V8lAftKB+KY/0VPy2r0XPpEH6Wo8=; b=Df64XSQ2tqweAmp4L4EvG/RkqjYqnt30Qf5U/s1VzYaGJU9Ns4o/a7CtuSPnsqjbNY HyrpPu28eUywktI367UnNWrZ4lhO8ZFQoYqkhNUMrbwdnZm1TZwYUFJFUPmmRpZ3F8s/ sCXeATbtFzocYeDaZIPTLVDF+7S32vq2iYjboxp+MMkJChzcbeNfoVAL57nZGAi+IciN lss/5R1EyhUA/SdNv45y72wtzXVP2bRbakeRVdTSN1mfGXvfJekDj4f9gA2LYRvDhqKt DWGnOXH/bfl/rDHoXDA5DcW+Wi1qHbJSbTeNjcDBUPPB9UYssgRY5Yys2km2SHFDw7pA 8bGA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="I5r/RXYY"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g3si13279811ejw.13.2019.11.04.14.09.31; Mon, 04 Nov 2019 14:09:59 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="I5r/RXYY"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390116AbfKDWHZ (ORCPT + 99 others); Mon, 4 Nov 2019 17:07:25 -0500 Received: from mail.kernel.org ([198.145.29.99]:39884 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390095AbfKDWHY (ORCPT ); Mon, 4 Nov 2019 17:07:24 -0500 Received: from localhost (6.204-14-84.ripe.coltfrance.com [84.14.204.6]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 1DCE020650; Mon, 4 Nov 2019 22:07:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1572905243; bh=c1WbYc7+1DaUk7tz5oVMf3z3M5NgNPMbvxSbncKOJaI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=I5r/RXYYjbt5r0MPPGSvq7RbP6sgZahLXnENcrsl4bCUN2/GvVzuM7uzc3JeB2r+d MbBK+ssNkM9vCSn1pfHcywsXoKBxByzZdkYKsPFkfHQJ0z8UAsRD8HBTwCpZKEeBgu GFTXWMdZwtoiURfG4hdYg+kZjZHxfsFo+ZaJjwGY= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Navid Emamdoost , Hans de Goede , Sasha Levin Subject: [PATCH 5.3 077/163] virt: vbox: fix memory leak in hgcm_call_preprocess_linaddr Date: Mon, 4 Nov 2019 22:44:27 +0100 Message-Id: <20191104212145.823138060@linuxfoundation.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191104212140.046021995@linuxfoundation.org> References: <20191104212140.046021995@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Navid Emamdoost [ Upstream commit e0b0cb9388642c104838fac100a4af32745621e2 ] 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: 579db9d45cb4 ("virt: Add vboxguest VMMDEV communication code") Signed-off-by: Navid Emamdoost Reviewed-by: Hans de Goede Link: https://lore.kernel.org/r/20190930204223.3660-1-navid.emamdoost@gmail.com Signed-off-by: Greg Kroah-Hartman Signed-off-by: Sasha Levin --- drivers/virt/vboxguest/vboxguest_utils.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/virt/vboxguest/vboxguest_utils.c b/drivers/virt/vboxguest/vboxguest_utils.c index 75fd140b02ff8..43c391626a000 100644 --- a/drivers/virt/vboxguest/vboxguest_utils.c +++ b/drivers/virt/vboxguest/vboxguest_utils.c @@ -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) @@ -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; } -- 2.20.1