Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp3490863pxp; Tue, 8 Mar 2022 15:48:56 -0800 (PST) X-Google-Smtp-Source: ABdhPJwRrOl9Ifzldt5GxBSTPqr0crP2GOPo2JyujMp/90+QP62cyLVRATjL+v0KK3nV669uE8ye X-Received: by 2002:a65:4143:0:b0:375:89f4:b46a with SMTP id x3-20020a654143000000b0037589f4b46amr16021244pgp.335.1646783336710; Tue, 08 Mar 2022 15:48:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646783336; cv=none; d=google.com; s=arc-20160816; b=KN9WoEJoRrItzRJE+gNmUIeU6Y3ZyxL7A6JPcfsCThy3NR9ZUI1Hu4JFEbnN/DeCsV PwDG1AN6CHMrvHiat/AHbX4SjxWiLdwmOuTeWXAZ7VJyh/oMAI1mjkMzpUHcih84N2Jq nfDnLLSGxSCjLVKYfvPsRzXOz1JdVO2cRJT06Kd4GarqjsNaEqUPiECTx9H9j4SG1hPF 5mLR2YuDvAkPUDjnQkF2bGJhj6n2VfboFHGSAb3jS59VK9AhZ2PDBoAL0ZLuqWXge+pN cO52jR2UXXwFxO8tq7hCdzCs5RKJy8bv5VYqruYAicsnEMzEXvyWi1xGCkNWTGHLxqBK YJoQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=GqtUPtymwD8nodVgRYs1OukKwm9TtrOarLaAI55BY/g=; b=kZPqgB6TSGpNznrL1FZd+HOp/Zu1BT/3uuIL6/8jOdgG2BvY+jUMl9eT6ehltdhFsc v6rERzB5+PmnbDTetUjFCB7boYy6bCHbgehuxVbl/Y0nUR6tD8NeipXJg3iSGB/OlfAR jLpBG3a66verfuYnjYC5DOaiOA7G4xUhKN8by3w7D52pAiutmJoJXIiTyt3zyL2Zijrd ctVL3BFIHYtsCBihqazf46OD8c0dWdql53ajxIMYDwgtJ1VVPMeUGLIQDwmqBeweOgET rr5vcCKDi3jq2lv0nwGWwt2B1qYZS/y/BG3+W9aEqyMZAtWgW5evwt3hKF53+BvMFBf6 Yu0A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=HmAOr0Eg; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id l6-20020a654c46000000b0036c1e25f69dsi264761pgr.410.2022.03.08.15.48.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Mar 2022 15:48:56 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=HmAOr0Eg; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id DA37A99EE2; Tue, 8 Mar 2022 15:29:13 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345310AbiCHJVz (ORCPT + 99 others); Tue, 8 Mar 2022 04:21:55 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48382 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234844AbiCHJVz (ORCPT ); Tue, 8 Mar 2022 04:21:55 -0500 Received: from mail-ej1-x630.google.com (mail-ej1-x630.google.com [IPv6:2a00:1450:4864:20::630]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E50AE3D1E2 for ; Tue, 8 Mar 2022 01:20:58 -0800 (PST) Received: by mail-ej1-x630.google.com with SMTP id qt6so37717390ejb.11 for ; Tue, 08 Mar 2022 01:20:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=GqtUPtymwD8nodVgRYs1OukKwm9TtrOarLaAI55BY/g=; b=HmAOr0EgeUBHvPZHmCKG4kogtaNj9ER/XOL2oeYxikeFqrOP+56VRcOO2TyJxjPGsS DqtrePggGOxJ0XNuBL/a98xyBbGPCP/T0URdliudkm0YcBtU5XD7doKAr0Em17dlVaf5 +gCdPZQv7q9vlasDvLyIZiF8n8vaHt6TMEngErSG6+j7U7ii/UKf8jEXY/DWlyqCdz0k Bo5hklneevWe1eQd/I5cXfHrPD9R6opXOjvPtCy6uxor/m+ABNeysfeOTY6YlbZb8xU+ J+aJE59tSdewBb+IQc1BGIYSWkVFP0ablcyRpqpXnWJZ5qaYUsv65yeRiagVXQ2S7Rh+ 9kIg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=GqtUPtymwD8nodVgRYs1OukKwm9TtrOarLaAI55BY/g=; b=muHhOFixcVsOji44JsxvlhUiEX/89AvGJJ+Ea3amGJ/9CzrNFdIwk97PMhlIAJqYC5 fSonftkR4ZX4TeGWOC+zYKYdjap7KSF6UUn26+KgsBMcFH5qZ7qxgP10z+OQ6wLlNqTo 7DoZDNReZKnY7UxzmOalQyDgQ2rzkrjCc4SQph0HDBIwzyD2QYvfgFkPeR4STJtIyyiE TeSnIVFUxdiC1WWcTRLclGzn3QnLQqlJbRePAvFD2MzV5sCi1CddesCRLmB1V9ZAnkTp ooD0KJizMQdcPjwdU7rRNL/3k0EM5TLPS11E00KprB/McIU1e9p6LnC48xEezTibXcGF loNw== X-Gm-Message-State: AOAM533NnifKJR/dPmbxePyP5HdpDuKaR3TspP0+pTNGC9HhseKMwJlo bgSC0xnj5eYFAraf+LCjJ1k= X-Received: by 2002:a17:906:69d1:b0:6ce:7201:ec26 with SMTP id g17-20020a17090669d100b006ce7201ec26mr12581079ejs.105.1646731257375; Tue, 08 Mar 2022 01:20:57 -0800 (PST) Received: from localhost.localdomain ([185.239.71.98]) by smtp.gmail.com with ESMTPSA id g13-20020a50bf4d000000b00410d407da2esm7410951edk.13.2022.03.08.01.20.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Mar 2022 01:20:56 -0800 (PST) From: Xiaolong Huang To: gregkh@linuxfoundation.org, fei1.li@intel.com Cc: linux-kernel@vger.kernel.org, Xiaolong Huang Subject: [PATCH] virt: acrn: fix a memory leak in acrn_dev_ioctl() Date: Tue, 8 Mar 2022 17:20:47 +0800 Message-Id: <20220308092047.1008409-1-butterflyhuangxx@gmail.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RDNS_NONE, SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no 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 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