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 894A0C4332F for ; Wed, 27 Apr 2022 16:19:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243180AbiD0QWx (ORCPT ); Wed, 27 Apr 2022 12:22:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37546 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242617AbiD0QUY (ORCPT ); Wed, 27 Apr 2022 12:20:24 -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 304EC51E4C for ; Wed, 27 Apr 2022 09:17:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1651076219; 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=RzItaAexJm8D+vfjQz5rKxOdybX8BYSOmObiCpIyc/0=; b=a3ZN4KfAl5pVShhkOCKJghtGoFYEHc5Bq9oG1hKZ/viZafbvjNzC1BLJF+I+QyroNZqhbz GSQ/fof4jhe7dWEWJX7FKzyRduvmVe7E5d7kj28o4tMqcV4LLv0T1olr/3hVbK+BMEd5+4 ppaxw2ejqWHzTxqE8+xGVKiehE95+z8= Received: from mail-ej1-f71.google.com (mail-ej1-f71.google.com [209.85.218.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-151-nT-KcSYlMiG6kJbLRkex7w-1; Wed, 27 Apr 2022 12:16:58 -0400 X-MC-Unique: nT-KcSYlMiG6kJbLRkex7w-1 Received: by mail-ej1-f71.google.com with SMTP id x2-20020a1709065ac200b006d9b316257fso1444136ejs.12 for ; Wed, 27 Apr 2022 09:16:57 -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=RzItaAexJm8D+vfjQz5rKxOdybX8BYSOmObiCpIyc/0=; b=eqEsacXnaoVF2Wj9c8dxmxQpsVAk7wHAqtDPLJyRExS6evJJacqZCuUJ9tz+xkH8Zx Mq+HrcblD2EGYQokSD77maTiKWgJWI5dkuFCHDu4FVa+15jc4wk5kmdwGytpRDt8rQJM Gj43CtOGInIWlGD4lCkMznSDa1XceGHAWgL9mao6Jf+oRynLYbVtTDGSRuWCx/gHS6c1 I+YR3vPShwgzFdhHbdVqZ/G3/u+pu5rPXYH7+m1vnn62WyLRVypxbPsfASi1M+rfKEKV 1tjd656BN0FJR1qfkflSJKjAwRrMhnCKr8ji8yXsjTJNvezHyMvUNL7S5lcV9iimysn4 3lQg== X-Gm-Message-State: AOAM530/USe1fzAHBngTxyJngBkBpEofbRY7ScNRJrtjwDADduq4gmnn v3hsMoq4Qpd+wIyMnYP6kZXfrlB3is/A+UnxC54ewzuT6uj1Y1P0XT3UvNmTEz5gmzwbtP43zw8 9x0380fAAOdRK1kAytHIKg+T9 X-Received: by 2002:a05:6402:5207:b0:426:1f0:b22 with SMTP id s7-20020a056402520700b0042601f00b22mr6744647edd.186.1651076216839; Wed, 27 Apr 2022 09:16:56 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwb75nHu6t51f1NDMxfZSRIItEiFS+6dOplwZZEazQUSBmfChxMq0wTDyn1DlO9plv/BGY99w== X-Received: by 2002:a05:6402:5207:b0:426:1f0:b22 with SMTP id s7-20020a056402520700b0042601f00b22mr6744632edd.186.1651076216627; Wed, 27 Apr 2022 09:16:56 -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 z19-20020a1709067e5300b006f39880d8e5sm4297615ejr.78.2022.04.27.09.16.55 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 27 Apr 2022 09:16:55 -0700 (PDT) Message-ID: <76dfc0b8-f892-c445-084c-62672293ca92@redhat.com> Date: Wed, 27 Apr 2022 18:16:54 +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.17 5/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: <20220427155408.19352-1-sashal@kernel.org> <20220427155408.19352-5-sashal@kernel.org> From: Paolo Bonzini In-Reply-To: <20220427155408.19352-5-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 7f009ebb319a..e7cd16e1e0a0 100644 > --- a/arch/x86/kvm/mmu/mmu.c > +++ b/arch/x86/kvm/mmu/mmu.c > @@ -3239,6 +3239,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