Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp2809690pxp; Tue, 8 Mar 2022 02:12:26 -0800 (PST) X-Google-Smtp-Source: ABdhPJy7sI4EymWADeUsN5bN/SXhu7tULzcbsByf9hgUS0BS47TOwh/L/BpZjhvEzx8Aia0ctLxj X-Received: by 2002:a17:903:32d1:b0:151:da5c:60ae with SMTP id i17-20020a17090332d100b00151da5c60aemr13555525plr.34.1646734346050; Tue, 08 Mar 2022 02:12:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646734346; cv=none; d=google.com; s=arc-20160816; b=hFn0xxxZhq0Qz9X3zDN7DlafuXh+5Vk0rkoHdn0MrEJb6HjMaHkFzIVuqi+VhuWFZE vkdQ3D6AUkgPH79WKgX7Po3SOcZbEU/q6byTxDjHidBvv6OCbW4cU6TQeybbvf8ZUxzs f+i0f7Vd4QgvxFEAVDW5FlYE5dDjcJ862nOrJ64o2BMM/rdwU5nFL8WPe0tzhLrKAzEJ VSILWhFIjxwNqukPYqG8pg6QYA+HYBn/iyYKppHWYBOdxqgD3fcVSZdUlqLieZqgsqUe Y5UZ0CWoeCuIqQYA3f6I5SIPxwO69kq8F1NWF6MaSj8FDVa6KXNjEqiL2azN+DMQHxg/ bMzQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=1WeE7WCKh29OLDGRhOQqCzNV9gDNRkNrbXdK/R8oa+Y=; b=GIVTQ+DS4KA1WsYn/x90n2nr6962amH/jO5mU0H6Jg+R2ZlCsVzxbzV8NqgSPuSfEl OwauLAxof3TgON814jE10/NMQSmBPAx52RMGBvkA0LEgye6sfgN/gsh/Ljp8fZR9N6xg hqIGS5eIk+GQvGqc4SxA5RxAGZs44SInqaHIW0PEVQQac6euXPT3GdUasJ/W5SQv5Rd6 bj0N6S9J1JfFzsHNIlvjtF1pj6CJQ0tRD6XbCYTwxzOg/iDSHHpu1usTVdNxX/sikwjD DccM9m6VFCLZaJxTmgjxm3QE9Sh4LIh8DMlpVI9zJBU0+DnaInvzuuWPEhBWfStSd/ra OwaA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=QIbDi8pz; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id rj10-20020a17090b3e8a00b001bd14e0302fsi1872996pjb.7.2022.03.08.02.12.11; Tue, 08 Mar 2022 02:12:26 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=QIbDi8pz; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345532AbiCHJ5K (ORCPT + 99 others); Tue, 8 Mar 2022 04:57:10 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41154 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345506AbiCHJ5J (ORCPT ); Tue, 8 Mar 2022 04:57:09 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 75DF3424B7 for ; Tue, 8 Mar 2022 01:56:13 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 1F029614AF for ; Tue, 8 Mar 2022 09:56:13 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 21591C340EB; Tue, 8 Mar 2022 09:56:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1646733372; bh=Gf8xjLLG6y2c+UbvP31+EcyVjgRh5mZ67b05LPS1FC4=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=QIbDi8pzn/L62J4mO2VAKJtr/Ln6xIG+pDuC7C5pDr0WDj7rW5hOisSwVUR9ikHKz LaQTRpuGdaSs3MMCW4xYafafCa06JRupvmR+GBOQ3G78s4olPXHjuwPeEWY6MvUjBx 4P9FvrJbWAVy6QmyfCXewZpKS4JjNE1eWabTtDmo= Date: Tue, 8 Mar 2022 10:56:08 +0100 From: Greg KH To: Xiaolong Huang Cc: fei1.li@intel.com, linux-kernel@vger.kernel.org Subject: Re: [PATCH] virt: acrn: fix a memory leak in acrn_dev_ioctl() Message-ID: References: <20220308092047.1008409-1-butterflyhuangxx@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220308092047.1008409-1-butterflyhuangxx@gmail.com> X-Spam-Status: No, score=-7.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Mar 08, 2022 at 05:20:47PM +0800, Xiaolong Huang wrote: > The vm_param and cpu_regs need to be freed via kfree() > before return -EINVAL error. > > Fixes: 9c5137aedd11 ("virt: acrn: Introduce VM management interfaces") > Fixes: 2ad2aaee1bc9 ("virt: acrn: Introduce an ioctl to set vCPU registers state") > Signed-off-by: Xiaolong Huang > Signed-off-by: Fei Li > --- > drivers/virt/acrn/hsm.c | 20 +++++++++++++++----- > 1 file changed, 15 insertions(+), 5 deletions(-) > > diff --git a/drivers/virt/acrn/hsm.c b/drivers/virt/acrn/hsm.c > index 5419794fccf1..423ea888d79a 100644 > --- a/drivers/virt/acrn/hsm.c > +++ b/drivers/virt/acrn/hsm.c > @@ -136,8 +136,10 @@ static long acrn_dev_ioctl(struct file *filp, unsigned int cmd, > if (IS_ERR(vm_param)) > return PTR_ERR(vm_param); > > - if ((vm_param->reserved0 | vm_param->reserved1) != 0) > + if ((vm_param->reserved0 | vm_param->reserved1) != 0) { > + kfree(vm_param); > return -EINVAL; > + } > > vm = acrn_vm_create(vm, vm_param); > if (!vm) { > @@ -182,21 +184,29 @@ static long acrn_dev_ioctl(struct file *filp, unsigned int cmd, > return PTR_ERR(cpu_regs); > > for (i = 0; i < ARRAY_SIZE(cpu_regs->reserved); i++) > - if (cpu_regs->reserved[i]) > + if (cpu_regs->reserved[i]) { > + kfree(cpu_regs); > return -EINVAL; > + } > > for (i = 0; i < ARRAY_SIZE(cpu_regs->vcpu_regs.reserved_32); i++) > - if (cpu_regs->vcpu_regs.reserved_32[i]) > + if (cpu_regs->vcpu_regs.reserved_32[i]) { > + kfree(cpu_regs); > return -EINVAL; > + } > > for (i = 0; i < ARRAY_SIZE(cpu_regs->vcpu_regs.reserved_64); i++) > - if (cpu_regs->vcpu_regs.reserved_64[i]) > + if (cpu_regs->vcpu_regs.reserved_64[i]) { > + kfree(cpu_regs); > return -EINVAL; > + } > > for (i = 0; i < ARRAY_SIZE(cpu_regs->vcpu_regs.gdt.reserved); i++) > if (cpu_regs->vcpu_regs.gdt.reserved[i] | > - cpu_regs->vcpu_regs.idt.reserved[i]) > + cpu_regs->vcpu_regs.idt.reserved[i]) { > + kfree(cpu_regs); > return -EINVAL; > + } > > ret = hcall_set_vcpu_regs(vm->vmid, virt_to_phys(cpu_regs)); > if (ret < 0) > > base-commit: 5859a2b1991101d6b978f3feb5325dad39421f29 > -- > 2.25.1 > How did you test this?