From nobody Sat May 30 17:45:06 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1779375351; cv=none; d=zohomail.com; s=zohoarc; b=Gmny3LoYnrzqziGOiH7X79tiFXi90nIR8Y5H9P+AepfSWorzTczOEwU6E/YLcBHErU/7BUSpYiAmjKEgRdmCMf6Cw+vtrrtMN4cO8CKCCWWArPEayxsyn76LOrjdL3tW9SvSqBWkL1DqWb4upd3VuS6wCv6S8rREyY+raxCFAZw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1779375351; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=KbVkSi2FA3zfV3b05kKADQgLFBaKkxPEvGcknU8X7sg=; b=BDUfWMxomKjKNO0TuvUFYh3XUqC6ahQojzUOGLyEF2tJebQfTQslIUp9OF2Pn+WVHmTuiSRbUmh3jBUcziSPHiSFUio1A6MGmbx+Mk8PX0jZ4azaf1mDAAsHYGMMCH68ZNext03w84jNxue8ZJFuyLvq3XC+v5UJytRmNXyeN7Y= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1779375351784483.6236604297271; Thu, 21 May 2026 07:55:51 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wQ4oC-0008Ol-AM; Thu, 21 May 2026 10:55:36 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wQ4nu-0008Kv-GL for qemu-devel@nongnu.org; Thu, 21 May 2026 10:55:20 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wQ4nr-0001t8-Ky for qemu-devel@nongnu.org; Thu, 21 May 2026 10:55:17 -0400 Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-436-6EIFua6ZMxicfKq195Lx0A-1; Thu, 21 May 2026 10:54:59 -0400 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id CA05319560B8; Thu, 21 May 2026 14:54:56 +0000 (UTC) Received: from localhost (unknown [10.44.24.26]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 0CFAA3002D2D; Thu, 21 May 2026 14:54:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1779375314; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=KbVkSi2FA3zfV3b05kKADQgLFBaKkxPEvGcknU8X7sg=; b=OErsoATqivbdJuqURN1ytRjGu2Ko1Fqsaut8inOU0fRW5VUNQjzcn3ZjUVr1mWNYfIpg5M kSw8gku6pXwr5vsXDhPJkgg5+EJ/iTnUseYFpQ+QyFH+mEUeZC29ftZ9OhvFnJmB40MZzs aDzcwzgsA/rRwOmHJ6/v1keRVE0y0yo= X-MC-Unique: 6EIFua6ZMxicfKq195Lx0A-1 X-Mimecast-MFC-AGG-ID: 6EIFua6ZMxicfKq195Lx0A_1779375297 From: marcandre.lureau@redhat.com To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Paolo Bonzini , Peter Xu , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Zhao Liu , Marcelo Tosatti , kvm@vger.kernel.org (open list:X86 KVM CPUs) Subject: [PATCH] target/i386/sev: fix MemoryRegion reference leaks in gpa2hva callers Date: Thu, 21 May 2026 18:54:51 +0400 Message-ID: <20260521145451.1831984-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=marcandre.lureau@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: 8 X-Spam_score: 0.8 X-Spam_bar: / X-Spam_report: (0.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.445, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_SBL_CSS=3.335, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1779375355886154100 From: Marc-Andr=C3=A9 Lureau gpa2hva() returns a referenced MemoryRegion via its p_mr out-parameter (inherited from memory_region_find()), but both SEV callers were failing to release it. Fixes: c7f7e6970d3b ("sev: add sev-inject-launch-secret") Signed-off-by: Marc-Andr=C3=A9 Lureau Reviewed-by: Peter Xu --- include/system/memory.h | 2 ++ target/i386/sev.c | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/include/system/memory.h b/include/system/memory.h index 1417132f6d9..53f65a224bb 100644 --- a/include/system/memory.h +++ b/include/system/memory.h @@ -1343,6 +1343,8 @@ void memory_region_ref(MemoryRegion *mr); */ void memory_region_unref(MemoryRegion *mr); =20 +G_DEFINE_AUTOPTR_CLEANUP_FUNC(MemoryRegion, memory_region_unref) + /** * memory_region_init_io: Initialize an I/O memory region. * diff --git a/target/i386/sev.c b/target/i386/sev.c index b44b5a1c2b9..3ae922779d7 100644 --- a/target/i386/sev.c +++ b/target/i386/sev.c @@ -1573,7 +1573,7 @@ snp_populate_metadata_pages(SevSnpGuestState *sev_snp, OvmfSevMetadataDesc *desc; int type, ret, i; void *hva; - MemoryRegion *mr =3D NULL; + g_autoptr(MemoryRegion) mr =3D NULL; =20 for (i =3D 0; i < metadata->num_desc; i++) { desc =3D &metadata->descs[i]; @@ -2067,7 +2067,7 @@ int sev_inject_launch_secret(const char *packet_hdr, = const char *secret, int error, ret =3D 1; void *hva; gsize hdr_sz =3D 0, data_sz =3D 0; - MemoryRegion *mr =3D NULL; + g_autoptr(MemoryRegion) mr =3D NULL; SevCommonState *sev_common =3D SEV_COMMON(MACHINE(qdev_get_machine())-= >cgs); =20 if (!sev_common) { --=20 2.54.0