From patchwork Mon Dec 26 12:03:15 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Woodhouse X-Patchwork-Id: 13081792 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E24BEC3DA79 for ; Mon, 26 Dec 2022 12:03:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232031AbiLZMDn (ORCPT ); Mon, 26 Dec 2022 07:03:43 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38534 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231995AbiLZMDj (ORCPT ); Mon, 26 Dec 2022 07:03:39 -0500 Received: from desiato.infradead.org (desiato.infradead.org [IPv6:2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E9821630B for ; Mon, 26 Dec 2022 04:03:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=Sender:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description; bh=hpSTj81T7VQFWhZJUH3ju9ct0rByvUkHLq1nRl5GL9c=; b=hSO/n+6yc4sjxw/6NREXOSPLJ0 iWJyVRD4Xw1u+oh3v6JbWHeY2MpilZ26zHlcz6P8ozCglMtdT4WJ06301xGB8itQC6D98anFkrBxH 5/eh4AVEQkGTbgqyAJmkBNCBaJFgUe+acBaMVNun/s3AV3BMclS4OoP8mY7IimIPFULP6nAsqC2vv QyC7WTh/uMflTGnyQ92i6jrqODQh+eG4thu1ecjmftb445+pMCKlK1YcdzevfvHmClW4nQtOuIoc0 sOFWeD/pmWfkSv/i7hst9q7n6TI15VH7KMUJbbJbCsArQTsg/AlxCePSviO3//k9R0m9I3M8U5emZ Odf5qDeA==; Received: from i7.infradead.org ([2001:8b0:10b:1:21e:67ff:fecb:7a92]) by desiato.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1p9mCM-00FJcN-1A; Mon, 26 Dec 2022 12:03:18 +0000 Received: from dwoodhou by i7.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1p9mCO-004ilj-O3; Mon, 26 Dec 2022 12:03:20 +0000 From: David Woodhouse To: Paolo Bonzini Cc: Michal Luczaj , Sean Christopherson , Yu Zhang , kvm@vger.kernel.org, Paul Durrant Subject: [PATCH 1/6] KVM: x86/xen: Fix memory leak in kvm_xen_write_hypercall_page() Date: Mon, 26 Dec 2022 12:03:15 +0000 Message-Id: <20221226120320.1125390-1-dwmw2@infradead.org> X-Mailer: git-send-email 2.35.3 In-Reply-To: References: MIME-Version: 1.0 Sender: David Woodhouse X-SRS-Rewrite: SMTP reverse-path rewritten from by desiato.infradead.org. See http://www.infradead.org/rpr.html Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org From: Michal Luczaj Release page irrespectively of kvm_vcpu_write_guest() return value. Suggested-by: Paul Durrant Fixes: 23200b7a30de ("KVM: x86/xen: intercept xen hypercalls if enabled") Signed-off-by: Michal Luczaj Message-Id: <20221220151454.712165-1-mhal@rbox.co> Reviewed-by: Paul Durrant Signed-off-by: David Woodhouse --- arch/x86/kvm/xen.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/arch/x86/kvm/xen.c b/arch/x86/kvm/xen.c index d7af40240248..d1a98d834d18 100644 --- a/arch/x86/kvm/xen.c +++ b/arch/x86/kvm/xen.c @@ -1069,6 +1069,7 @@ int kvm_xen_write_hypercall_page(struct kvm_vcpu *vcpu, u64 data) u8 blob_size = lm ? kvm->arch.xen_hvm_config.blob_size_64 : kvm->arch.xen_hvm_config.blob_size_32; u8 *page; + int ret; if (page_num >= blob_size) return 1; @@ -1079,10 +1080,10 @@ int kvm_xen_write_hypercall_page(struct kvm_vcpu *vcpu, u64 data) if (IS_ERR(page)) return PTR_ERR(page); - if (kvm_vcpu_write_guest(vcpu, page_addr, page, PAGE_SIZE)) { - kfree(page); + ret = kvm_vcpu_write_guest(vcpu, page_addr, page, PAGE_SIZE); + kfree(page); + if (ret) return 1; - } } return 0; }