Received: by 2002:a05:6a10:17d3:0:0:0:0 with SMTP id hz19csp2673556pxb; Mon, 19 Apr 2021 10:57:05 -0700 (PDT) X-Google-Smtp-Source: ABdhPJybrcyHqZF1X6lV1Hop4c3a7ZqWUt+Y19FYLSoGPq0QK/BAVDHHCioG0IZVap5av6t+RHKI X-Received: by 2002:a17:902:6949:b029:e8:c22d:17ae with SMTP id k9-20020a1709026949b02900e8c22d17aemr23909806plt.57.1618855025484; Mon, 19 Apr 2021 10:57:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1618855025; cv=none; d=google.com; s=arc-20160816; b=g3Zcrw9/p+29l5ZLJ84VYJcHTKmdlt9SyY6KBsyE2IdcBQgj1SvYM7Fq0Oyb7dRbSj 37mEN/CdAK0PVkq7BAxE3xd2xY6FsiswIaeez12nXm8GJYn98i0aZVQhAW60/1NDgdev 2Or4JY9tF/TbREO0O8+BIjwHcS2/mdtLONfgwS72xGYaLZpQAYSTdfxYCiMrLxYhNPBd /BmsOawypwMzhR/m7JKZJ5eLz6f2TYprgEYY13ChQFcaG5f+yQiGHPuxvqjjAk9qWOU/ 1PH5a2ZbALNJbahug9Ab26GpkyXXjRxxNw2+nUWcALBeNq1CePCZtdVh2mgXIH9vbXhC CEKw== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=Q+UuM+cBWCXk3lnpLlHK8PxXHSob6fO9QsI+4yFrl2U=; b=SDSVVamcLZPtCRIdYgekq+0+2KXkRJZ269rMBe1xcrGLIRqBQtj5FneqJ8w7Tfz68o KHZI0yj9+YLn3JIqdWe3aJQsJjJVY2dT00tyDMRzLejkdHAznoPls2lC6OmR2ImERNeE 7N+X22WQQ/+4SQo4z3pmomMiJKuJSP1tc1qO3tQmw+bWTQO2nuv3cOysCcWu3OWGPAPD RUtRsKxF1ehzOcQ7Rz7H2aV9UcRINJVwwSCGunf8bFYbBTZ6jFu6vJpFAG5hc9qYsTdE I/2hn8wyw400F/BcX56S1EPH3UOPEksPUUyC4qA4FLFu5ERkMzVj2fme9sZIWKXyYmk+ SfCQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=z+F7UgAA; 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=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id b184si5283345pfg.138.2021.04.19.10.56.52; Mon, 19 Apr 2021 10:57:05 -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=@linuxfoundation.org header.s=korg header.b=z+F7UgAA; 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=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242696AbhDSN3h (ORCPT + 99 others); Mon, 19 Apr 2021 09:29:37 -0400 Received: from mail.kernel.org ([198.145.29.99]:54232 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241553AbhDSNUy (ORCPT ); Mon, 19 Apr 2021 09:20:54 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 35B2E613D8; Mon, 19 Apr 2021 13:17:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1618838239; bh=OxV01kUvNRgHcTAQ6TWVRP8AMkFSj9AW+I1Xcfvm8vA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=z+F7UgAA53dvLUlDv2LQITuY9joLPg8m82ea+138zZ3EP+E/8WiGB0/hgZKDurW/D 4j1vWdISjT8oap5yRwbl9E76BHpBYAtYACpYtFY4Cjsqn4aCWnNLN+NhLnx+2q1LLX XGl5RYPKGJKgRQQ1A6c5PgxTq0dlNQ2L9dkGrwSU= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Reiji Watanabe , Jim Mattson , Paolo Bonzini , Sasha Levin Subject: [PATCH 5.10 094/103] KVM: VMX: Dont use vcpu->run->internal.ndata as an array index Date: Mon, 19 Apr 2021 15:06:45 +0200 Message-Id: <20210419130531.017872691@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210419130527.791982064@linuxfoundation.org> References: <20210419130527.791982064@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Reiji Watanabe [ Upstream commit 04c4f2ee3f68c9a4bf1653d15f1a9a435ae33f7a ] __vmx_handle_exit() uses vcpu->run->internal.ndata as an index for an array access. Since vcpu->run is (can be) mapped to a user address space with a writer permission, the 'ndata' could be updated by the user process at anytime (the user process can set it to outside the bounds of the array). So, it is not safe that __vmx_handle_exit() uses the 'ndata' that way. Fixes: 1aa561b1a4c0 ("kvm: x86: Add "last CPU" to some KVM_EXIT information") Signed-off-by: Reiji Watanabe Reviewed-by: Jim Mattson Message-Id: <20210413154739.490299-1-reijiw@google.com> Cc: stable@vger.kernel.org Signed-off-by: Paolo Bonzini Signed-off-by: Sasha Levin --- arch/x86/kvm/vmx/vmx.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c index 0b229282dd50..f8835cabf29f 100644 --- a/arch/x86/kvm/vmx/vmx.c +++ b/arch/x86/kvm/vmx/vmx.c @@ -6006,19 +6006,19 @@ static int vmx_handle_exit(struct kvm_vcpu *vcpu, fastpath_t exit_fastpath) exit_reason.basic != EXIT_REASON_PML_FULL && exit_reason.basic != EXIT_REASON_APIC_ACCESS && exit_reason.basic != EXIT_REASON_TASK_SWITCH)) { + int ndata = 3; + vcpu->run->exit_reason = KVM_EXIT_INTERNAL_ERROR; vcpu->run->internal.suberror = KVM_INTERNAL_ERROR_DELIVERY_EV; - vcpu->run->internal.ndata = 3; vcpu->run->internal.data[0] = vectoring_info; vcpu->run->internal.data[1] = exit_reason.full; vcpu->run->internal.data[2] = vcpu->arch.exit_qualification; if (exit_reason.basic == EXIT_REASON_EPT_MISCONFIG) { - vcpu->run->internal.ndata++; - vcpu->run->internal.data[3] = + vcpu->run->internal.data[ndata++] = vmcs_read64(GUEST_PHYSICAL_ADDRESS); } - vcpu->run->internal.data[vcpu->run->internal.ndata++] = - vcpu->arch.last_vmentry_cpu; + vcpu->run->internal.data[ndata++] = vcpu->arch.last_vmentry_cpu; + vcpu->run->internal.ndata = ndata; return 0; } -- 2.30.2