Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp2921160pxb; Tue, 24 Aug 2021 10:38:32 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx4ftuo/xOGkgMRx8dx0yMA7zRv0lOW2R8PBlBGCQCMUdbi+3o+zUjxWxDKuvjdN3xF309A X-Received: by 2002:a5d:9bcf:: with SMTP id d15mr31873690ion.88.1629826711902; Tue, 24 Aug 2021 10:38:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1629826711; cv=none; d=google.com; s=arc-20160816; b=oY3qls7gwJPBS/7kX347S96JwjR4CdgxMNQeFfpwXiz7gVAbZhEQxY+8sZhchFkkTm gGumk8TgL7yBY5CdUaHO2w32RrYYy/vpUv69aQv4Lv9Yojgj8rlD1/X29VHmLX0dTQ+c 4Bp1l58AMbZ07C+Opa3Q57nuzEy56f9nXp2GHH3q5+u5dXfzFOYj0j/tWA5P22hnwCmJ S1nkiawNzzhqSMKo5V9URGicCftPRIbAmptpnGZhgmN54Xh/jRitbgvrzSP/XsfYZgZZ LUj6e7y3vuhFxLauY35o5Pd3lIXd3/pKTgswi8k93iBtnRo0QD0TMuFRl68y7LmvTPG8 kjGw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=sabhkK312rHac5ZeKE5DMFriXWPMVxPfuO2DEULCcIw=; b=lApPNKwdGzYPdGfQCEeGp/5sBGC2fUAAy7X6bRCHxZm0beQvlGQ/2R7fbKLFzQztUs Eccx3wEtrSktCyJoXrSPcsL+yzihAhDRkbPynnjPnb7oVKigAXK4649lRKVijcljqfUx O57KKPJkBMnqIGMgh6MUs48rkfdc1nb6ukE05jdNUEATZ8nHHGShbLuat/ruGrRFBVZJ hWSO9lElKH1+XJI1VshI+BH2FLTL7sj6oIMT2N2JMZFPU+4ED0+hGToADntoIasQJsUn rHn1Wal4hohGwxmgcVRF8p/q8qg2qK+Pdg3nGjItSeJf6/G4LVypUOe84bMLrX+qRQGz xM6Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=pf2dq3W7; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id q10si20282066ilu.60.2021.08.24.10.38.19; Tue, 24 Aug 2021 10:38:31 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=pf2dq3W7; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240026AbhHXRhm (ORCPT + 99 others); Tue, 24 Aug 2021 13:37:42 -0400 Received: from mail.kernel.org ([198.145.29.99]:40662 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242090AbhHXRef (ORCPT ); Tue, 24 Aug 2021 13:34:35 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id D944D61BB5; Tue, 24 Aug 2021 17:06:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1629824797; bh=KI4qFLZhEnSyuQurn8fvsdvnpXMyebWWFTGkXlH3vL4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=pf2dq3W7ciPlaKJ2WspcUZwSQDgpad2jFo4CQHbnTsqXHH5TB9gWGbPYgNUnmgBny SShjRQlFUDLM3MZtZtt5ofuDKSQePnpDSQQWLyOg3uH4woYuupFPB84IocGruUc8Px w6nLBOVknTacXg2soRLS+MLpuaZRKLRgpy3bRwg3XQtFjbiJtDYCVaO3pSNuEkTOLg TFO2HnU9Kp3JEAG0qIP6kODCESLM0tQnyjlq2usOcWSDfDVNXubvReM0dc3uIHckKh NMyz0Xe0rWSpL7zPZht/Lf96Fg8fVBOqVLXFJ6oxBcl+t2O7Bgz+lu9sg99XJNjr2x 3mPHFMJnhP/aA== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Maxim Levitsky , Paolo Bonzini , Greg Kroah-Hartman Subject: [PATCH 4.9 21/43] KVM: nSVM: avoid picking up unsupported bits from L2 in int_ctl (CVE-2021-3653) Date: Tue, 24 Aug 2021 13:05:52 -0400 Message-Id: <20210824170614.710813-22-sashal@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210824170614.710813-1-sashal@kernel.org> References: <20210824170614.710813-1-sashal@kernel.org> MIME-Version: 1.0 X-KernelTest-Patch: http://kernel.org/pub/linux/kernel/v4.x/stable-review/patch-4.9.281-rc1.gz X-KernelTest-Tree: git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable-rc.git X-KernelTest-Branch: linux-4.9.y X-KernelTest-Patches: git://git.kernel.org/pub/scm/linux/kernel/git/stable/stable-queue.git X-KernelTest-Version: 4.9.281-rc1 X-KernelTest-Deadline: 2021-08-26T17:06+00:00 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Maxim Levitsky [ upstream commit 0f923e07124df069ba68d8bb12324398f4b6b709 ] * Invert the mask of bits that we pick from L2 in nested_vmcb02_prepare_control * Invert and explicitly use VIRQ related bits bitmask in svm_clear_vintr This fixes a security issue that allowed a malicious L1 to run L2 with AVIC enabled, which allowed the L2 to exploit the uninitialized and enabled AVIC to read/write the host physical memory at some offsets. Fixes: 3d6368ef580a ("KVM: SVM: Add VMRUN handler") Signed-off-by: Maxim Levitsky Signed-off-by: Paolo Bonzini Signed-off-by: Greg Kroah-Hartman --- arch/x86/include/asm/svm.h | 2 ++ arch/x86/kvm/svm.c | 6 +++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/arch/x86/include/asm/svm.h b/arch/x86/include/asm/svm.h index 14824fc78f7e..509b9f3307e4 100644 --- a/arch/x86/include/asm/svm.h +++ b/arch/x86/include/asm/svm.h @@ -113,6 +113,8 @@ struct __attribute__ ((__packed__)) vmcb_control_area { #define V_IGN_TPR_SHIFT 20 #define V_IGN_TPR_MASK (1 << V_IGN_TPR_SHIFT) +#define V_IRQ_INJECTION_BITS_MASK (V_IRQ_MASK | V_INTR_PRIO_MASK | V_IGN_TPR_MASK) + #define V_INTR_MASKING_SHIFT 24 #define V_INTR_MASKING_MASK (1 << V_INTR_MASKING_SHIFT) diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c index cbc7f177bbd8..03fdeab057d2 100644 --- a/arch/x86/kvm/svm.c +++ b/arch/x86/kvm/svm.c @@ -3048,7 +3048,11 @@ static bool nested_svm_vmrun(struct vcpu_svm *svm) svm->nested.intercept = nested_vmcb->control.intercept; svm_flush_tlb(&svm->vcpu); - svm->vmcb->control.int_ctl = nested_vmcb->control.int_ctl | V_INTR_MASKING_MASK; + svm->vmcb->control.int_ctl = nested_vmcb->control.int_ctl & + (V_TPR_MASK | V_IRQ_INJECTION_BITS_MASK); + + svm->vmcb->control.int_ctl |= V_INTR_MASKING_MASK; + if (nested_vmcb->control.int_ctl & V_INTR_MASKING_MASK) svm->vcpu.arch.hflags |= HF_VINTR_MASK; else -- 2.30.2