public inbox for stable@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] KVM: arm64: vgic-its: Avoid potential UAF in LPI translation cache
@ 2024-01-04 18:32 Oliver Upton
  2024-01-04 19:33 ` Marc Zyngier
  0 siblings, 1 reply; 2+ messages in thread
From: Oliver Upton @ 2024-01-04 18:32 UTC (permalink / raw)
  To: kvmarm
  Cc: kvm, Marc Zyngier, James Morse, Suzuki K Poulose, Zenghui Yu,
	Raghavendra Rao Ananta, Jing Zhang, Oliver Upton, stable

There is a potential UAF scenario in the case of an LPI translation
cache hit racing with an operation that invalidates the cache, such
as a DISCARD ITS command. The root of the problem is that
vgic_its_check_cache() does not elevate the refcount on the vgic_irq
before dropping the lock that serializes refcount changes.

Have vgic_its_check_cache() raise the refcount on the returned vgic_irq
and add the corresponding decrement after queueing the interrupt.

Cc: stable@vger.kernel.org
Signed-off-by: Oliver Upton <oliver.upton@linux.dev>
---
 arch/arm64/kvm/vgic/vgic-its.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/arch/arm64/kvm/vgic/vgic-its.c b/arch/arm64/kvm/vgic/vgic-its.c
index 2dad2d095160..e2764d0ffa9f 100644
--- a/arch/arm64/kvm/vgic/vgic-its.c
+++ b/arch/arm64/kvm/vgic/vgic-its.c
@@ -590,7 +590,11 @@ static struct vgic_irq *vgic_its_check_cache(struct kvm *kvm, phys_addr_t db,
 	unsigned long flags;
 
 	raw_spin_lock_irqsave(&dist->lpi_list_lock, flags);
+
 	irq = __vgic_its_check_cache(dist, db, devid, eventid);
+	if (irq)
+		vgic_get_irq_kref(irq);
+
 	raw_spin_unlock_irqrestore(&dist->lpi_list_lock, flags);
 
 	return irq;
@@ -769,6 +773,7 @@ int vgic_its_inject_cached_translation(struct kvm *kvm, struct kvm_msi *msi)
 	raw_spin_lock_irqsave(&irq->irq_lock, flags);
 	irq->pending_latch = true;
 	vgic_queue_irq_unlock(kvm, irq, flags);
+	vgic_put_irq(kvm, irq);
 
 	return 0;
 }

base-commit: 33cc938e65a98f1d29d0a18403dbbee050dcad9a
-- 
2.43.0.472.g3155946c3a-goog


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] KVM: arm64: vgic-its: Avoid potential UAF in LPI translation cache
  2024-01-04 18:32 [PATCH] KVM: arm64: vgic-its: Avoid potential UAF in LPI translation cache Oliver Upton
@ 2024-01-04 19:33 ` Marc Zyngier
  0 siblings, 0 replies; 2+ messages in thread
From: Marc Zyngier @ 2024-01-04 19:33 UTC (permalink / raw)
  To: Oliver Upton, kvmarm
  Cc: Raghavendra Rao Ananta, kvm, James Morse, Zenghui Yu, stable,
	Suzuki K Poulose, Jing Zhang

On Thu, 4 Jan 2024 18:32:32 +0000, Oliver Upton wrote:
> There is a potential UAF scenario in the case of an LPI translation
> cache hit racing with an operation that invalidates the cache, such
> as a DISCARD ITS command. The root of the problem is that
> vgic_its_check_cache() does not elevate the refcount on the vgic_irq
> before dropping the lock that serializes refcount changes.
> 
> Have vgic_its_check_cache() raise the refcount on the returned vgic_irq
> and add the corresponding decrement after queueing the interrupt.

Applied to next, thanks!

[1/1] KVM: arm64: vgic-its: Avoid potential UAF in LPI translation cache
      commit: ad362fe07fecf0aba839ff2cc59a3617bd42c33f

Cheers,

	M.
-- 
Without deviation from the norm, progress is not possible.



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2024-01-04 19:34 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-01-04 18:32 [PATCH] KVM: arm64: vgic-its: Avoid potential UAF in LPI translation cache Oliver Upton
2024-01-04 19:33 ` Marc Zyngier

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox