Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp72580pxb; Mon, 13 Sep 2021 13:16:09 -0700 (PDT) X-Google-Smtp-Source: ABdhPJySshUbkhzzqpCANH5akwDPXvZxmUGFtpFZnxJEO6dhSeUsFf9Vir/9/2u1bTuaiAjvuAVG X-Received: by 2002:a17:906:d1d1:: with SMTP id bs17mr14309382ejb.198.1631564169362; Mon, 13 Sep 2021 13:16:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631564169; cv=none; d=google.com; s=arc-20160816; b=QWFGLuvfSioU1WtEC4p+EnBtKoRVM9xOMlRW3ZaZLCrF6PS9twbqZpTcsfyDx2uzk1 PARI1sc9pTKp2ffLxbWAg3eGb7tEnkpfIhOtRH5DH6xOV2L0fomyn3JUARLgFwigMZ+e lF87eWz9O8bNMgc4+23MnEYvbMFfZxIfE+IjVkI6BvBbHqYr5dGcrcz4gXi6PZgS964R gd54iTV6SvdhXYq+i5ATq5t1cEvXeSi+5UH9NN08iRcEVX3tnyV5Y4+FcF4uppbYQm4d D0TW+bqIrIap4MYupC9ro/45uDpdI6/m5kYQV963q/ZIhCCCuZLO3EjyDW0aeMtypy/G 3kMw== 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=VcuonUj3sH91oYzLs2pLaXyvRSuA/pYDrTzt0QDTJ5M=; b=NoNbRAMI4aOyoevkLVB0dTFQ28oqLezynYLdQ7nMScj0qLVBcqbQJOo0kgODuIgfSY A2QOKu3S6BU8Q4AmT77CSs24xzPd/4a01Qk+AdvuiuC1qtfURpncAq5gpEhIMFVTMP8H qY78i5f0pvzo/aK0ddROWJBt5b+08EowTEzqeOJawqUYocHdggV/KnTwND7EBn4adIfb DA4k+4AjRuicuCbu24DvtH+PwrVP/Xkze3XP6RWriup0qMBK2PlZmwZWWA0phlM1ioxI DYZmrBfZh+j3GEn7qpgQg+6biRW5D4y/t+5He6DxsVX2cFS3MU0Vvrm8v8qOma5tn2dX yAxA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=x49qJHtw; 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 1si8372886edv.359.2021.09.13.13.15.45; Mon, 13 Sep 2021 13:16:09 -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=x49qJHtw; 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 S243038AbhIMNvK (ORCPT + 99 others); Mon, 13 Sep 2021 09:51:10 -0400 Received: from mail.kernel.org ([198.145.29.99]:56780 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243266AbhIMNrd (ORCPT ); Mon, 13 Sep 2021 09:47:33 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 43013610F7; Mon, 13 Sep 2021 13:32:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1631539945; bh=F4i1mJonU6zm6wETwto0yf/xl4rP4xC6cyqdmxZFf2U=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=x49qJHtwSd4VHZ3yT9xU7Zt7Le64p6rxrIIUMqbQYqEd1vCPayCqlBLKVOMdrabEL 4HaLwv7QWrd6B5m1ulq3tKxW108LxdJturINusjh92lrs1f2LI9Q0kQsxU6+jN1r81 ZWPHOdBgUChsNCNuvFGNEPrmYNCh5LnHqOXLYCRk= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, syzbot+200c08e88ae818f849ce@syzkaller.appspotmail.com, Sean Christopherson , Vitaly Kuznetsov , Paolo Bonzini Subject: [PATCH 5.10 224/236] Revert "KVM: x86: mmu: Add guest physical address check in translate_gpa()" Date: Mon, 13 Sep 2021 15:15:29 +0200 Message-Id: <20210913131107.975809274@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210913131100.316353015@linuxfoundation.org> References: <20210913131100.316353015@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: Sean Christopherson commit e7177339d7b5f9594b316842122b5fda9513d5e2 upstream. Revert a misguided illegal GPA check when "translating" a non-nested GPA. The check is woefully incomplete as it does not fill in @exception as expected by all callers, which leads to KVM attempting to inject a bogus exception, potentially exposing kernel stack information in the process. WARNING: CPU: 0 PID: 8469 at arch/x86/kvm/x86.c:525 exception_type+0x98/0xb0 arch/x86/kvm/x86.c:525 CPU: 1 PID: 8469 Comm: syz-executor531 Not tainted 5.14.0-rc7-syzkaller #0 RIP: 0010:exception_type+0x98/0xb0 arch/x86/kvm/x86.c:525 Call Trace: x86_emulate_instruction+0xef6/0x1460 arch/x86/kvm/x86.c:7853 kvm_mmu_page_fault+0x2f0/0x1810 arch/x86/kvm/mmu/mmu.c:5199 handle_ept_misconfig+0xdf/0x3e0 arch/x86/kvm/vmx/vmx.c:5336 __vmx_handle_exit arch/x86/kvm/vmx/vmx.c:6021 [inline] vmx_handle_exit+0x336/0x1800 arch/x86/kvm/vmx/vmx.c:6038 vcpu_enter_guest+0x2a1c/0x4430 arch/x86/kvm/x86.c:9712 vcpu_run arch/x86/kvm/x86.c:9779 [inline] kvm_arch_vcpu_ioctl_run+0x47d/0x1b20 arch/x86/kvm/x86.c:10010 kvm_vcpu_ioctl+0x49e/0xe50 arch/x86/kvm/../../../virt/kvm/kvm_main.c:3652 The bug has escaped notice because practically speaking the GPA check is useless. The GPA check in question only comes into play when KVM is walking guest page tables (or "translating" CR3), and KVM already handles illegal GPA checks by setting reserved bits in rsvd_bits_mask for each PxE, or in the case of CR3 for loading PTDPTRs, manually checks for an illegal CR3. This particular failure doesn't hit the existing reserved bits checks because syzbot sets guest.MAXPHYADDR=1, and IA32 architecture simply doesn't allow for such an absurd MAXPHYADDR, e.g. 32-bit paging doesn't define any reserved PA bits checks, which KVM emulates by only incorporating the reserved PA bits into the "high" bits, i.e. bits 63:32. Simply remove the bogus check. There is zero meaningful value and no architectural justification for supporting guest.MAXPHYADDR < 32, and properly filling the exception would introduce non-trivial complexity. This reverts commit ec7771ab471ba6a945350353617e2e3385d0e013. Fixes: ec7771ab471b ("KVM: x86: mmu: Add guest physical address check in translate_gpa()") Cc: stable@vger.kernel.org Reported-by: syzbot+200c08e88ae818f849ce@syzkaller.appspotmail.com Signed-off-by: Sean Christopherson Message-Id: <20210831164224.1119728-2-seanjc@google.com> Reviewed-by: Vitaly Kuznetsov Signed-off-by: Paolo Bonzini Signed-off-by: Greg Kroah-Hartman --- arch/x86/kvm/mmu/mmu.c | 6 ------ 1 file changed, 6 deletions(-) --- a/arch/x86/kvm/mmu/mmu.c +++ b/arch/x86/kvm/mmu/mmu.c @@ -267,12 +267,6 @@ static bool check_mmio_spte(struct kvm_v static gpa_t translate_gpa(struct kvm_vcpu *vcpu, gpa_t gpa, u32 access, struct x86_exception *exception) { - /* Check if guest physical address doesn't exceed guest maximum */ - if (kvm_vcpu_is_illegal_gpa(vcpu, gpa)) { - exception->error_code |= PFERR_RSVD_MASK; - return UNMAPPED_GVA; - } - return gpa; }