From: Jackie Liu <liu.yun@linux.dev>
To: maz@kernel.org, linux-arm-kernel@lists.infradead.org
Cc: oupton@kernel.org, yuzenghui@huawei.com, will@kernel.org,
kvmarm@lists.linux.dev
Subject: [PATCH] KVM/arm64: vgic-its: Fix memory leak when vgic_its_set_abi() fails
Date: Thu, 4 Jun 2026 11:14:26 +0800 [thread overview]
Message-ID: <20260604031426.16109-1-liu.yun@linux.dev> (raw)
From: Jackie Liu <liuyun01@kylinos.cn>
In vgic_its_create(), if vgic_its_set_abi() fails after allocating the
its structure and setting kvm state, the allocated 'its' is leaked
because the function returns without freeing it.
Fix by rolling back the kvm state flags and freeing the its structure
when vgic_its_set_abi() returns an error.
Fixes: 71afe470e20d ("KVM: arm64: vgic-its: Introduce migration ABI infrastructure")
Signed-off-by: Jackie Liu <liuyun01@kylinos.cn>
---
arch/arm64/kvm/vgic/vgic-its.c | 18 +++++++++++-------
1 file changed, 11 insertions(+), 7 deletions(-)
diff --git a/arch/arm64/kvm/vgic/vgic-its.c b/arch/arm64/kvm/vgic/vgic-its.c
index 1d7e5d560af4..83718eab4e06 100644
--- a/arch/arm64/kvm/vgic/vgic-its.c
+++ b/arch/arm64/kvm/vgic/vgic-its.c
@@ -1878,8 +1878,6 @@ static int vgic_its_create(struct kvm_device *dev, u32 type)
INIT_LIST_HEAD(&its->collection_list);
xa_init(&its->translation_cache);
- dev->kvm->arch.vgic.msis_require_devid = true;
- dev->kvm->arch.vgic.has_its = true;
its->enabled = false;
its->dev = dev;
@@ -1887,15 +1885,21 @@ static int vgic_its_create(struct kvm_device *dev, u32 type)
((u64)GITS_BASER_TYPE_DEVICE << GITS_BASER_TYPE_SHIFT);
its->baser_coll_table = INITIAL_BASER_VALUE |
((u64)GITS_BASER_TYPE_COLLECTION << GITS_BASER_TYPE_SHIFT);
- dev->kvm->arch.vgic.propbaser = INITIAL_PROPBASER_VALUE;
-
- dev->private = its;
ret = vgic_its_set_abi(its, NR_ITS_ABIS - 1);
+ if (ret) {
+ mutex_unlock(&dev->kvm->arch.config_lock);
+ kfree(its);
+ return ret;
+ }
- mutex_unlock(&dev->kvm->arch.config_lock);
+ dev->kvm->arch.vgic.msis_require_devid = true;
+ dev->kvm->arch.vgic.has_its = true;
+ dev->kvm->arch.vgic.propbaser = INITIAL_PROPBASER_VALUE;
+ dev->private = its;
- return ret;
+ mutex_unlock(&dev->kvm->arch.config_lock);
+ return 0;
}
static void vgic_its_destroy(struct kvm_device *kvm_dev)
--
2.54.0
next reply other threads:[~2026-06-04 3:15 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-04 3:14 Jackie Liu [this message]
2026-06-04 6:41 ` [PATCH] KVM/arm64: vgic-its: Fix memory leak when vgic_its_set_abi() fails Oliver Upton
2026-06-04 6:59 ` Jackie Liu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260604031426.16109-1-liu.yun@linux.dev \
--to=liu.yun@linux.dev \
--cc=kvmarm@lists.linux.dev \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=maz@kernel.org \
--cc=oupton@kernel.org \
--cc=will@kernel.org \
--cc=yuzenghui@huawei.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox