From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 85DFEC433EF for ; Wed, 27 Apr 2022 16:24:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243111AbiD0Q1U (ORCPT ); Wed, 27 Apr 2022 12:27:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43144 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243011AbiD0Q0s (ORCPT ); Wed, 27 Apr 2022 12:26:48 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 8C3F8261BF2 for ; Wed, 27 Apr 2022 09:21:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1651076450; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=rsca3nN9F0L3L7CF4f4/JIiLe+nDncGsHBTvE+SQpns=; b=hOvnWxgfr4IvKvLO2sECzlbYzFgdRFmditKOdssZPBIZLUvdPt2xoSJTRxVFDKPYPs1NCd bXjuA6d5tDlixh4GpMXAul3u9Zs1srHTRt15d5oFl7+66mH47YHuFm1z+F5VPi57K0EY6T WnFNpx0gE304tdLwe9rXUJOp8mgyHJ4= Received: from mail-ej1-f70.google.com (mail-ej1-f70.google.com [209.85.218.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-435-hO0atB7gMKKNoLZ6oWVTdw-1; Wed, 27 Apr 2022 12:20:44 -0400 X-MC-Unique: hO0atB7gMKKNoLZ6oWVTdw-1 Received: by mail-ej1-f70.google.com with SMTP id sc26-20020a1709078a1a00b006effb6a81b9so1455851ejc.6 for ; Wed, 27 Apr 2022 09:20:44 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent:subject :content-language:to:cc:references:from:in-reply-to :content-transfer-encoding; bh=rsca3nN9F0L3L7CF4f4/JIiLe+nDncGsHBTvE+SQpns=; b=ZXgb1xgaRhqO6B/AN+7DEZz6MMYif9NGDY6+EcBHKI9hMt+a4RpubAzzbL6lK3okQ+ NZEgb+qF8db5TcDLDeo/zhGzdfsQ10tmaobQT6OY2GTGhX7IHBd6UoStlVningcNXSb7 IDfVaxY3zAy8zLv4GRRPGy4xtxwz7J9707Z8l79pHcenohd03uuk5fQFBS4LF6Y8QJ+v zYlhuN8fbzgHMCVCTyG2J9bZ+CUlplE9pI/4O01+GE9DTHhhQ+Fbzr6XrDMdvavo9TQC QULEl+Fm5eB78mnkOXI/44Cx++D9W3w6gM1veHC4/2DjF5kdzTMhfb3wTzf9euaYexlt 8lJQ== X-Gm-Message-State: AOAM533PCTpxj+8+1VuyTznEp0sAprVjEgYW9Xe+mOO2a6U+3NQDEnIO uAXUdxu2pzw/8Xa/oKz+66iMiv9Tugw6okkQiYQv8E4fHHhYgc+2IGKokUhSCDv/nTBrMF8E5e6 Xo51GHeIIgo5E+KvdeKtL4SQI X-Received: by 2002:a05:6402:1a42:b0:424:20bb:3e37 with SMTP id bf2-20020a0564021a4200b0042420bb3e37mr31381793edb.29.1651076441833; Wed, 27 Apr 2022 09:20:41 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzy79Ti+40bhX02i6AE/YohVsvCl0+6reMKemh3Hg1j7DTh1D/TMmfHWFR50FWzqoAwUbxSgA== X-Received: by 2002:a05:6402:1a42:b0:424:20bb:3e37 with SMTP id bf2-20020a0564021a4200b0042420bb3e37mr31381758edb.29.1651076441571; Wed, 27 Apr 2022 09:20:41 -0700 (PDT) Received: from ?IPV6:2001:b07:6468:f312:1c09:f536:3de6:228c? ([2001:b07:6468:f312:1c09:f536:3de6:228c]) by smtp.googlemail.com with ESMTPSA id s12-20020a1709062ecc00b006e8558c9a5csm7003572eji.94.2022.04.27.09.20.39 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 27 Apr 2022 09:20:40 -0700 (PDT) Message-ID: <143ede94-5231-de84-9e8a-97a5f9ca8563@redhat.com> Date: Wed, 27 Apr 2022 18:20:39 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.8.0 Subject: Re: [PATCH MANUALSEL 5.15 6/7] KVM: x86/mmu: avoid NULL-pointer dereference on page freeing bugs Content-Language: en-US To: Sasha Levin , linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Sean Christopherson , tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, x86@kernel.org, kvm@vger.kernel.org References: <20220427155431.19458-1-sashal@kernel.org> <20220427155431.19458-6-sashal@kernel.org> From: Paolo Bonzini In-Reply-To: <20220427155431.19458-6-sashal@kernel.org> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 4/27/22 17:54, Sasha Levin wrote: > From: Paolo Bonzini > > [ Upstream commit 9191b8f0745e63edf519e4a54a4aaae1d3d46fbd ] > > WARN and bail if KVM attempts to free a root that isn't backed by a shadow > page. KVM allocates a bare page for "special" roots, e.g. when using PAE > paging or shadowing 2/3/4-level page tables with 4/5-level, and so root_hpa > will be valid but won't be backed by a shadow page. It's all too easy to > blindly call mmu_free_root_page() on root_hpa, be nice and WARN instead of > crashing KVM and possibly the kernel. > > Reviewed-by: Sean Christopherson > Signed-off-by: Paolo Bonzini > Signed-off-by: Sasha Levin > --- > arch/x86/kvm/mmu/mmu.c | 2 ++ > 1 file changed, 2 insertions(+) > > diff --git a/arch/x86/kvm/mmu/mmu.c b/arch/x86/kvm/mmu/mmu.c > index 34e828badc51..806f9d42bcce 100644 > --- a/arch/x86/kvm/mmu/mmu.c > +++ b/arch/x86/kvm/mmu/mmu.c > @@ -3314,6 +3314,8 @@ static void mmu_free_root_page(struct kvm *kvm, hpa_t *root_hpa, > return; > > sp = to_shadow_page(*root_hpa & PT64_BASE_ADDR_MASK); > + if (WARN_ON(!sp)) > + return; > > if (is_tdp_mmu_page(sp)) > kvm_tdp_mmu_put_root(kvm, sp, false); Acked-by: Paolo Bonzini