Received: by 2002:a05:6a10:6d25:0:0:0:0 with SMTP id gq37csp1906892pxb; Mon, 13 Sep 2021 07:56:59 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxUbGC2SHS1ZyEldD6sIgKS+uKuTBU8YrLdNXZy4GgRReRpdeNftA2H2qzzOJmgOGpbpB0K X-Received: by 2002:a6b:8e50:: with SMTP id q77mr9218878iod.96.1631545018971; Mon, 13 Sep 2021 07:56:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631545018; cv=none; d=google.com; s=arc-20160816; b=ZVV544QLa3C7Xr7R0zz4aO3u2mk7GFutJ6ezzQiT+8FLl6X167LqZ0+frbRU0XLvPA Kd9TwlDv0GnsDghnLmrlKmJzzDoR3p+rfzut4LLxHdAuzoWxVWQjwl/VAs6Es6NIo1iJ VbJHHyfA2628ffdqbpwbFvAAN3P3+Qy0Mpdi2hMDeCzUp58x5ySVxTJSo3yayD84dYdH sl0waluFAaB3CHQohquQYqOznqpg60BxQ7gWNRAuEyFTR/izkgdJ3KUsQ2kYgkGeOK76 4cAJFaC0HnWdUa/CmojYdd0s8PalgPJyzpLDxub6LWWOckKvFj1m8eRIwbZKhfiq/A2O 5A+A== 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=CgqdhRe8RmbzvclUoIb7yMBwpqmXKMW46ORhkgwMIVs=; b=KUXva/ikIEW/DAFYec8v+LnIcra8L6tzkXKoomuaW3lz5sC1iMBbA5FegFYtYhlvZG 1tVdW6qkkZGtmwJlbQp5zwzjaw5DBbYoizjDAqXk/20l0ylxMRDGUGUcusWMHuZCtEDY jhsw0oXkc5rO4JY5IwWjfe0YEfMA9zsOKjxRA6rAmzid1Z/F/TByQ9pQUjjLcIb7LGCF Zigo9mj0KiOsg+GUhhLO3rOS2JDHWoYTgFdozAj60nK6yie27ZWdTp0knCpCEhAF7mwy Db2IrXFEs2ZBm0q16tLtUV2LyuiD6OSonM2CJXRfj1ch/jb1tgqzUEX4qM3EWTezd8SL U7yg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=q9yukfDm; 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 z4si6734748jap.100.2021.09.13.07.56.43; Mon, 13 Sep 2021 07:56:58 -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=q9yukfDm; 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 S1347233AbhIMOxp (ORCPT + 99 others); Mon, 13 Sep 2021 10:53:45 -0400 Received: from mail.kernel.org ([198.145.29.99]:39018 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345921AbhIMOrR (ORCPT ); Mon, 13 Sep 2021 10:47:17 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 2143763231; Mon, 13 Sep 2021 13:58:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1631541539; bh=IvAwBdmLkkjY1O9Y8jbFHJ0A3p/g3xffFYofgC4W08A=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=q9yukfDmHao5MiCt/vdM+dhuAqk5Ub05sDfyoYo0Mae8uws5ieQlyoVmOJPGQ1Cug CpzKnRyQmULN2viD+0muXegbylgRk9rrcWd0EjOMMj40FNDOFmdiniFLOWthhYQsna 9w3Ql0pLBejS0oXgSU5cx8uuMuB5eQ85O8o4REIU= 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.14 310/334] Revert "KVM: x86: mmu: Add guest physical address check in translate_gpa()" Date: Mon, 13 Sep 2021 15:16:04 +0200 Message-Id: <20210913131123.905441516@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210913131113.390368911@linuxfoundation.org> References: <20210913131113.390368911@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 @@ -323,12 +323,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; }