]> git.ipfire.org Git - thirdparty/kernel/linux.git/commit
KVM: X86: Fix array_index_nospec protection in __pv_send_ipi
authorAnel Orazgaliyeva <anelkz@amazon.de>
Fri, 6 Mar 2026 07:59:52 +0000 (08:59 +0100)
committerSean Christopherson <seanjc@google.com>
Thu, 12 Mar 2026 16:11:40 +0000 (09:11 -0700)
commit00d572d4cd7d23f9a7a498d2d824b68ba3ea5b88
treec458d00d731f4b3a4034b65e0ba2dec20e9ecaa3
parent26c9bfc0fac240540581cfbe58031b412f98aaf8
KVM: X86: Fix array_index_nospec protection in __pv_send_ipi

The __pv_send_ipi() function iterates over up to BITS_PER_LONG vCPUs
starting from the APIC ID specified in its 'min' argument, which is
provided by the guest.

Commit c87bd4dd43a6 used array_index_nospec() to clamp the value of 'min'
but then the for_each_set_bit() loop dereferences higher indices without
further protection. Theoretically, a guest can trigger speculative access
to up to BITS_PER_LONG elements off the end of the phys_map[] array.

(In practice it would probably need aggressive loop unrolling by the
compiler to go more than one element off the end, and even that seems
unlikely, but the theoretical possibility exists.)

Move the array_index_nospec() inside the loop to protect the [map + i]
index which is actually being used each time.

Fixes: c87bd4dd43a6 ("KVM: x86: use array_index_nospec with indices that come from guest")
Fixes: bdf7ffc89922 ("KVM: LAPIC: Fix pv ipis out-of-bounds access")
Fixes: 4180bf1b655a ("KVM: X86: Implement "send IPI" hypercall")
Signed-off-by: Anel Orazgaliyeva <anelkz@amazon.de>
Signed-off-by: David Woodhouse <dwmw@amazon.co.uk>
Reviewed-by: Jim Mattson <jmattson@google.com>
Link: https://patch.msgid.link/9d50fc3ca9e8e58f551d015f95d51a3c29ce6ccc.camel@infradead.org
Signed-off-by: Sean Christopherson <seanjc@google.com>
arch/x86/kvm/lapic.c