From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D1B83311C2C; Tue, 2 Sep 2025 13:27:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756819667; cv=none; b=m5ALp658u8B2/BKloDTrB4pjBv6L2/e3EBeIsLBz9GB/pAUuj1HB8VCHdvuw35iJuAUUVz2CZ3rVvMv7BI9EeaHXBQjfCCHX54BUiuO69+52X+qCYZgmyAwtKdNQTM5ppYsjJYXxPYEmjMPktXwmFQN5PKOillG6j4CzyvgWTwg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756819667; c=relaxed/simple; bh=0tYzcJ2v/fnrh5RGmvEn9bOAirlQspH76IDCYZ2bGlc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=op2T6wyVVBy3z3PTiQ/uCYdkiLnPUtrUmTdzo4T7cMFhOzu0iiSsi3DyDEZp8ykBOuEo6jPFsjUvpVYdrZPFh5cetkYOsvqeHLmF7FE6rTHtiJ5Zuaj30lf0/Ex5RN3Fg1RM1+iE0v5HAbxypxzQeROvWS8v2qvvbPakLGFZLxA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=lIT8KaV4; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="lIT8KaV4" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 57C5FC4CEED; Tue, 2 Sep 2025 13:27:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1756819667; bh=0tYzcJ2v/fnrh5RGmvEn9bOAirlQspH76IDCYZ2bGlc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lIT8KaV4GFa1ACJSvnV8eSzjP236M2uUn3WgcKGckYfuObLhKiQxPcNUyrU/DW123 1FM6u8XAvFSQLo4pKVmmzq8IgZwfcGDosvyd8tgj5a41xLYxlBr3PhwtTJArg0HWUX WVDT3qwZVsI44Yma1UQYotJ6wiC7Y70cUED3SU0o= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Thijs Raymakers , Sean Christopherson , Paolo Bonzini Subject: [PATCH 6.16 104/142] KVM: x86: use array_index_nospec with indices that come from guest Date: Tue, 2 Sep 2025 15:20:06 +0200 Message-ID: <20250902131952.266580276@linuxfoundation.org> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20250902131948.154194162@linuxfoundation.org> References: <20250902131948.154194162@linuxfoundation.org> User-Agent: quilt/0.68 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.16-stable review patch. If anyone has any objections, please let me know. ------------------ From: Thijs Raymakers commit c87bd4dd43a624109c3cc42d843138378a7f4548 upstream. min and dest_id are guest-controlled indices. Using array_index_nospec() after the bounds checks clamps these values to mitigate speculative execution side-channels. Signed-off-by: Thijs Raymakers Cc: stable@vger.kernel.org Cc: Sean Christopherson Cc: Paolo Bonzini Cc: Greg Kroah-Hartman Fixes: 715062970f37 ("KVM: X86: Implement PV sched yield hypercall") Fixes: bdf7ffc89922 ("KVM: LAPIC: Fix pv ipis out-of-bounds access") Fixes: 4180bf1b655a ("KVM: X86: Implement "send IPI" hypercall") Link: https://lore.kernel.org/r/20250804064405.4802-1-thijs@raymakers.nl Signed-off-by: Sean Christopherson Signed-off-by: Greg Kroah-Hartman --- arch/x86/kvm/lapic.c | 2 ++ arch/x86/kvm/x86.c | 7 +++++-- 2 files changed, 7 insertions(+), 2 deletions(-) --- a/arch/x86/kvm/lapic.c +++ b/arch/x86/kvm/lapic.c @@ -852,6 +852,8 @@ static int __pv_send_ipi(unsigned long * if (min > map->max_apic_id) return 0; + min = array_index_nospec(min, map->max_apic_id + 1); + for_each_set_bit(i, ipi_bitmap, min((u32)BITS_PER_LONG, (map->max_apic_id - min + 1))) { if (map->phys_map[min + i]) { --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -10051,8 +10051,11 @@ static void kvm_sched_yield(struct kvm_v rcu_read_lock(); map = rcu_dereference(vcpu->kvm->arch.apic_map); - if (likely(map) && dest_id <= map->max_apic_id && map->phys_map[dest_id]) - target = map->phys_map[dest_id]->vcpu; + if (likely(map) && dest_id <= map->max_apic_id) { + dest_id = array_index_nospec(dest_id, map->max_apic_id + 1); + if (map->phys_map[dest_id]) + target = map->phys_map[dest_id]->vcpu; + } rcu_read_unlock();