From: sashiko-bot@kernel.org
To: "David Woodhouse" <dwmw2@infradead.org>
Cc: kvm@vger.kernel.org
Subject: Re: [PATCH v3 13/13] KVM: x86/xen: Convert evtchn_ports from IDR to XArray
Date: Mon, 31 Aug 2026 23:36:20 +0000 [thread overview]
Message-ID: <20260831233621.136B31F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260831213632.81023-14-dwmw2@infradead.org>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Pre-existing issues:
- [Critical] Type confusion in evtchnfd delivery union allows a userspace guest to crash the host kernel by assigning an EVTCHNSTAT_ipi event channel to port 0.
--
commit 365d4c87b9f4941190fe8a9a101dce7853ba1e18
Author: Furkan Caliskan <frn1furkan10@gmail.com>
KVM: x86/xen: Convert evtchn_ports from IDR to XArray
This patch converts the deprecated IDR used for evtchn_ports into an XArray.
It replaces idr_alloc() with xa_insert() and idr_remove() with xa_erase(),
dropping the explicit rcu_read_lock() in kvm_xen_hcall_evtchn_send() since
xa_load() is internally RCU-safe.
> diff --git a/arch/x86/kvm/xen.c b/arch/x86/kvm/xen.c
> index b024a09de55a3..b59c6b747c2f6 100644
> --- a/arch/x86/kvm/xen.c
> +++ b/arch/x86/kvm/xen.c
> @@ -2214,13 +2214,13 @@ static int kvm_xen_eventfd_assign(struct kvm *kvm,
> }
>
> mutex_lock(&kvm->arch.xen.xen_lock);
> - ret = idr_alloc(&kvm->arch.xen.evtchn_ports, evtchnfd, port, port + 1,
> + ret = xa_insert(&kvm->arch.xen.evtchn_ports, port, evtchnfd,
> GFP_KERNEL);
[Severity: Critical]
This isn't a bug introduced by this patch, but could this union type
confusion allow a userspace guest to crash the host kernel?
When a userspace process calls the KVM ioctl to assign an event channel with
type EVTCHNSTAT_ipi and send_port = 0, the setup code just prior to this
insertion does the following in kvm_xen_eventfd_assign():
evtchnfd->deliver.port.port = data->u.evtchn.deliver.port.port;
evtchnfd->deliver.port.vcpu_id = data->u.evtchn.deliver.port.vcpu;
evtchnfd->deliver.port.vcpu_idx = -1;
Because of the union layout in the evtchnfd structure, deliver.port overlaps
with deliver.eventfd. Writing -1 to vcpu_idx corrupts the eventfd_ctx pointer.
> [ ... ]
> @@ -2235,7 +2235,7 @@ static int kvm_xen_eventfd_deassign(struct kvm *kvm, u32 port)
> struct evtchnfd *evtchnfd;
>
> mutex_lock(&kvm->arch.xen.xen_lock);
> - evtchnfd = idr_remove(&kvm->arch.xen.evtchn_ports, port);
> + evtchnfd = xa_erase(&kvm->arch.xen.evtchn_ports, port);
> mutex_unlock(&kvm->arch.xen.xen_lock);
>
> if (!evtchnfd)
> @@ -2251,7 +2251,7 @@ static int kvm_xen_eventfd_deassign(struct kvm *kvm, u32 port)
> [ ... ]
> @@ -2376,23 +2374,23 @@ void kvm_xen_destroy_vcpu(struct kvm_vcpu *vcpu)
> void kvm_xen_destroy_vm(struct kvm *kvm)
> {
> struct evtchnfd *evtchnfd;
> - int i;
> + unsigned long i;
>
> kvm_gpc_deactivate(&kvm->arch.xen.shinfo_cache);
>
> - idr_for_each_entry(&kvm->arch.xen.evtchn_ports, evtchnfd, i) {
> + xa_for_each(&kvm->arch.xen.evtchn_ports, i, evtchnfd) {
> if (!evtchnfd->deliver.port.port)
> eventfd_ctx_put(evtchnfd->deliver.eventfd.ctx);
[Severity: Critical]
This is a pre-existing issue, but does this check trigger an invalid pointer
dereference due to the type confusion mentioned above?
If an IPI was assigned to port 0, evtchnfd->deliver.port.port evaluates to 0,
making the condition true. The kernel will then mistakenly dereference the
corrupted pointer (overlapping with vcpu_idx = -1) by calling
eventfd_ctx_put().
This exact sequence is present during deassignment in
kvm_xen_eventfd_deassign(), as well as here during VM destruction, which
seems like it could lead to a kernel panic and a host denial of service.
> kfree(evtchnfd);
> }
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260831213632.81023-1-dwmw2@infradead.org?part=13
next prev parent reply other threads:[~2026-08-31 23:36 UTC|newest]
Thread overview: 38+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-31 21:26 [PATCH v3 0/13] KVM: x86/xen: Bug fixes and long_mode cleanup David Woodhouse
2026-08-31 21:26 ` [PATCH v3 01/13] KVM: x86/xen: Rename 'longmode' to 'is_64bit' in hypercall handling David Woodhouse
2026-09-02 12:18 ` Paul Durrant
2026-09-02 18:24 ` David Woodhouse
2026-09-02 18:57 ` Sean Christopherson
2026-09-02 22:00 ` David Woodhouse
2026-08-31 21:26 ` [PATCH v3 02/13] KVM: x86/xen: Introduce kvm_xen_has_64bit_shinfo() macro David Woodhouse
2026-09-02 12:21 ` Paul Durrant
2026-09-02 18:28 ` David Woodhouse
2026-08-31 21:26 ` [PATCH v3 03/13] KVM: x86/xen: Rename max_evtchn_port() to kvm_max_evtchn_port() David Woodhouse
2026-09-02 12:22 ` Paul Durrant
2026-08-31 21:26 ` [PATCH v3 04/13] KVM: x86/xen: Latch shinfo mode in kvm_xen_set_evtchn_fast() David Woodhouse
2026-09-02 12:25 ` Paul Durrant
2026-08-31 21:26 ` [PATCH v3 05/13] KVM: x86/xen: Latch shinfo mode in kvm_xen_schedop_poll() David Woodhouse
2026-09-02 12:27 ` Paul Durrant
2026-08-31 21:26 ` [PATCH v3 06/13] KVM: x86/xen: Enforce 4-byte alignment of vcpu_info registration David Woodhouse
2026-09-02 12:29 ` Paul Durrant
2026-08-31 21:26 ` [PATCH v3 07/13] KVM: x86/xen: Use 32-bit locked bts for vcpu_info evtchn_pending_sel David Woodhouse
2026-08-31 22:50 ` sashiko-bot
2026-08-31 23:18 ` David Woodhouse
2026-09-02 12:33 ` Paul Durrant
2026-08-31 21:26 ` [PATCH v3 08/13] KVM: x86/xen: Use 32-bit atomics if vCPU's evtchn_pending_sel isn't aligned David Woodhouse
2026-09-02 12:38 ` Paul Durrant
2026-08-31 21:26 ` [PATCH v3 09/13] KVM: x86/xen: Use atomic*() APIs instead of open coded equivalents David Woodhouse
2026-09-02 12:41 ` Paul Durrant
2026-09-02 18:32 ` David Woodhouse
2026-09-02 18:59 ` Sean Christopherson
2026-08-31 21:26 ` [PATCH v3 10/13] KVM: x86/xen: Take kvm->srcu in __kvm_xen_has_interrupt() David Woodhouse
2026-09-02 12:43 ` Paul Durrant
2026-08-31 21:26 ` [PATCH v3 11/13] KVM: x86/xen: Mark poll_evtchn accesses with READ_ONCE()/WRITE_ONCE() David Woodhouse
2026-09-02 12:45 ` Paul Durrant
2026-08-31 21:26 ` [PATCH v3 12/13] KVM: pfncache: use a dedicated invalidation sequence for cache refresh David Woodhouse
2026-09-02 12:14 ` Paul Durrant
2026-08-31 21:26 ` [PATCH v3 13/13] KVM: x86/xen: Convert evtchn_ports from IDR to XArray David Woodhouse
2026-08-31 23:36 ` sashiko-bot [this message]
2026-09-01 0:07 ` David Woodhouse
2026-09-02 12:48 ` Paul Durrant
2026-09-04 15:37 ` [PATCH v3 0/13] KVM: x86/xen: Bug fixes and long_mode cleanup Paolo Bonzini
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=20260831233621.136B31F000E9@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=dwmw2@infradead.org \
--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