From: sashiko-bot@kernel.org
To: "Tao Cui" <cui.tao@linux.dev>
Cc: kvm@vger.kernel.org
Subject: Re: [PATCH v5 1/3] LoongArch: KVM: Clear device pointer in irqchip destroy callbacks
Date: Fri, 16 Oct 2026 10:07:13 +0000 [thread overview]
Message-ID: <sashiko-outbox-174122@kernel.org> (raw)
In-Reply-To: <20261016095151.1155049-2-cui.tao@linux.dev>
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [Critical] kvm: NULL pointer dereference in lockless IRQ injection paths
- [High] kvm: loongarch: UAF window in kvm_dmsintc_destroy due to wrong kfree order
--
commit b63c6600199f59512e0a9603666fb0590806637a
Author: Tao Cui <cuitao@kylinos.cn>
LoongArch: KVM: Clear device pointer in irqchip destroy callbacks
This commit clears the irqchip device pointers when destroying devices to
prevent dangling pointers from being dereferenced if device creation fails
later.
> diff --git a/arch/loongarch/kvm/intc/dmsintc.c b/arch/loongarch/kvm/intc/dmsintc.c
> index ff327b4c05f7e..c182185a3d592 100644
> --- a/arch/loongarch/kvm/intc/dmsintc.c
> +++ b/arch/loongarch/kvm/intc/dmsintc.c
> @@ -146,6 +146,7 @@ static void kvm_dmsintc_destroy(struct kvm_device *dev)
> return;
>
> kfree(dev->kvm->arch.dmsintc);
> + dev->kvm->arch.dmsintc = NULL;
[Severity: High]
Does this create a Use-After-Free window? The memory is freed before the
globally visible pointer is cleared. If KVM_CREATE_DEVICE succeeds but a
subsequent error (e.g. in anon_inode_getfd) triggers ops->destroy(), this
invokes kvm_dmsintc_destroy() while concurrent threads can still access the
pointer.
Should the pointer be cleared before calling kfree(), as is correctly done
for the other irqchip devices in this patch?
> kfree(dev);
> }
>
[ ... ]
> diff --git a/arch/loongarch/kvm/intc/pch_pic.c b/arch/loongarch/kvm/intc/pch_pic.c
> index 220fc23ffe8cf..dab2d3f1b8f62 100644
> --- a/arch/loongarch/kvm/intc/pch_pic.c
> +++ b/arch/loongarch/kvm/intc/pch_pic.c
> @@ -483,6 +483,7 @@ static void kvm_pch_pic_destroy(struct kvm_device *dev)
>
> kvm = dev->kvm;
> s = kvm->arch.pch_pic;
> + kvm->arch.pch_pic = NULL;
[Severity: Critical]
Does setting this pointer to NULL introduce a NULL pointer dereference in the
concurrent lockless IRQ injection paths?
If a user-space process maps GSI routing to an irqchip and races KVM_IRQ_LINE
or KVM_IRQFD interrupt injection against a failing KVM_CREATE_DEVICE ioctl
(e.g. by hitting the process RLIMIT_NOFILE limit), this teardown path will
assign NULL to the irqchip pointer.
Concurrently, the IRQ injection path locklessly invokes routing callbacks
like kvm_set_pic_irq() which pass the potentially NULL kvm->arch.pch_pic into
pch_pic_set_irq():
arch/loongarch/kvm/irqfd.c:kvm_set_pic_irq() {
...
pch_pic_set_irq(kvm->arch.pch_pic, e->irqchip.pin, level);
...
}
The pointer is then unconditionally dereferenced:
arch/loongarch/kvm/intc/pch_pic.c:pch_pic_set_irq() {
...
spin_lock(&s->lock);
...
}
A similar pattern exists for eiointc_set_irq() in
arch/loongarch/kvm/intc/eiointc.c.
Are NULL guard checks needed in the concurrent readers to safely handle this
regression?
> /* unregister pch pic device and free it's memory */
> mutex_lock(&kvm->slots_lock);
> kvm_io_bus_unregister_dev(kvm, KVM_MMIO_BUS, &s->device);
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261016095151.1155049-1-cui.tao@linux.dev?part=1
next prev parent reply other threads:[~2026-10-16 10:07 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-16 9:51 [PATCH v5 0/3] LoongArch: KVM: irqchip fixes Tao Cui
2026-10-16 9:51 ` [PATCH v5 1/3] LoongArch: KVM: Clear device pointer in irqchip destroy callbacks Tao Cui
2026-10-16 10:07 ` sashiko-bot [this message]
2026-10-16 9:51 ` [PATCH v5 2/3] LoongArch: KVM: Propagate real error code in kvm_pch_pic_create Tao Cui
2026-10-16 9:51 ` [PATCH v5 3/3] LoongArch: KVM: Reject repeated PCH-PIC CTRL_INIT Tao Cui
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=sashiko-outbox-174122@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=cui.tao@linux.dev \
--cc=kvm@vger.kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
/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