Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp2182688pxb; Fri, 25 Mar 2022 12:34:00 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxblwyNUtIFo98/Q5QDOpx9A7EQTFPnPYz5QbQh0oRcZ6syhhl5MrCU2jLAG1T7m6HoXYAU X-Received: by 2002:a63:2cd1:0:b0:386:5a8a:9ff4 with SMTP id s200-20020a632cd1000000b003865a8a9ff4mr871564pgs.129.1648236840311; Fri, 25 Mar 2022 12:34:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1648236840; cv=none; d=google.com; s=arc-20160816; b=qH2M6DSnM1zaSuR06JDwGK2kZ/RAAslK9apB1BP/P2GhpQ1+6L7t4VXuoOzFiM4s0F VGN7fXQy2chvEwSJwKqGyi/sHUdhVdIVfNDkRy2Cz9yqacuFKIp6pQTqb906IeSgPfKh qnJqhZEIsLfMUGz7ge6aU4+zAL/WMWuKhdL2XTAwxoJ5vS8YT4TdeCaNDLrAaKB/jqRP hlm0LgvWKm3kJL11qVgt1zMQjRy/uct/+EeVXDy1EfuS6rQjwtkgicScMI/b/DBUwO+4 aNpz3r7GRCsgQIr/E2TL7yUdaUro/4bsb24pAJw7nlrKGFX3lsUBi/mQ4aYxLwUkMhCK tEbA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id; bh=P62aTeSVTf9O6TlV39PHjMxV5lWMkskfhdTUHqLqaig=; b=N2JKtZGSTShyPP+Fo0ys/EvbTEjxIZww8FlJzmpJBdqsBOxdz/N0+R/ImuzuU2euvw ltPkK4nCtp+vR2aFPjF3HE8b5zG2fvAvZKT1QFXCPJzhJBMKhUnKlBuC7wD/fnykk2wd ekXz1VhotEHDwn9YL071Z+muocUzirVWr2npZBC7t/h52qURHr5PHuFPnTxBU9eDdTU5 SJKyzvUhrEo9ccrT6rpOO9FY6AywVMn/zJMoX8eNIcEfk1W3WT9l8G/2hqaRvmZc3Bbl jGzeD2v7lSOH2pUFL/0GpfMbLxfFkSB4BCY+QQWhYd7x8ZL71FVQ5c5oRaKTz+/08ylq E72A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id mn18-20020a17090b189200b001bd14e030ccsi3511845pjb.164.2022.03.25.12.34.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 25 Mar 2022 12:34:00 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 37A6A25516A; Fri, 25 Mar 2022 11:24:49 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1376959AbiCYQsX (ORCPT + 99 others); Fri, 25 Mar 2022 12:48:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58560 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1376881AbiCYQsW (ORCPT ); Fri, 25 Mar 2022 12:48:22 -0400 Received: from smtp.smtpout.orange.fr (smtp09.smtpout.orange.fr [80.12.242.131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E5A8DE339F for ; Fri, 25 Mar 2022 09:46:47 -0700 (PDT) Received: from [192.168.1.18] ([90.126.236.122]) by smtp.orange.fr with ESMTPA id Xn5Bn3MiVZQwWXn5Bnlbxv; Fri, 25 Mar 2022 17:46:45 +0100 X-ME-Helo: [192.168.1.18] X-ME-Auth: YWZlNiIxYWMyZDliZWIzOTcwYTEyYzlhMmU3ZiQ1M2U2MzfzZDfyZTMxZTBkMTYyNDBjNDJlZmQ3ZQ== X-ME-Date: Fri, 25 Mar 2022 17:46:45 +0100 X-ME-IP: 90.126.236.122 Message-ID: <7f25e53a-6d18-6ffd-7e0e-2cce5e632ffc@wanadoo.fr> Date: Fri, 25 Mar 2022 17:46:37 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.7.0 Subject: Re: [RFC PATCH] KVM: x86/mmu: fix general protection fault in kvm_mmu_uninit_tdp_mmu Content-Language: fr To: Pavel Skripkin , pbonzini@redhat.com, seanjc@google.com, vkuznets@redhat.com, wanpengli@tencent.com, jmattson@google.com Cc: x86@kernel.org, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, syzbot+717ed82268812a643b28@syzkaller.appspotmail.com References: <20220325163815.3514-1-paskripkin@gmail.com> From: Christophe JAILLET In-Reply-To: <20220325163815.3514-1-paskripkin@gmail.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,NICE_REPLY_A, RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Le 25/03/2022 à 17:38, Pavel Skripkin a écrit : > Syzbot reported GPF in kvm_mmu_uninit_tdp_mmu(), which is caused by > passing NULL pointer to flush_workqueue(). > > tdp_mmu_zap_wq is allocated via alloc_workqueue() which may fail. There > is no error hanling and kvm_mmu_uninit_tdp_mmu() return value is simply > ignored. Even all kvm_*_init_vm() functions are void, so the easiest > solution is to check that tdp_mmu_zap_wq is valid pointer before passing > it somewhere. > > Fixes: 22b94c4b63eb ("KVM: x86/mmu: Zap invalidated roots via asynchronous worker") > Reported-and-tested-by: syzbot+717ed82268812a643b28@syzkaller.appspotmail.com > Signed-off-by: Pavel Skripkin > --- > arch/x86/kvm/mmu/tdp_mmu.c | 14 +++++++++----- > 1 file changed, 9 insertions(+), 5 deletions(-) > > diff --git a/arch/x86/kvm/mmu/tdp_mmu.c b/arch/x86/kvm/mmu/tdp_mmu.c > index e7e7876251b3..b3e8ff7ac5b0 100644 > --- a/arch/x86/kvm/mmu/tdp_mmu.c > +++ b/arch/x86/kvm/mmu/tdp_mmu.c > @@ -48,8 +48,10 @@ void kvm_mmu_uninit_tdp_mmu(struct kvm *kvm) > if (!kvm->arch.tdp_mmu_enabled) > return; > > - flush_workqueue(kvm->arch.tdp_mmu_zap_wq); > - destroy_workqueue(kvm->arch.tdp_mmu_zap_wq); > + if (kvm->arch.tdp_mmu_zap_wq) { > + flush_workqueue(kvm->arch.tdp_mmu_zap_wq); > + destroy_workqueue(kvm->arch.tdp_mmu_zap_wq); Hi, unrelated to the patch, but flush_workqueue() is redundant and could be removed. destroy_workqueue() already drains the queue. Just my 2c, CJ > + } > > WARN_ON(!list_empty(&kvm->arch.tdp_mmu_pages)); > WARN_ON(!list_empty(&kvm->arch.tdp_mmu_roots)); > @@ -119,9 +121,11 @@ static void tdp_mmu_zap_root_work(struct work_struct *work) > > static void tdp_mmu_schedule_zap_root(struct kvm *kvm, struct kvm_mmu_page *root) > { > - root->tdp_mmu_async_data = kvm; > - INIT_WORK(&root->tdp_mmu_async_work, tdp_mmu_zap_root_work); > - queue_work(kvm->arch.tdp_mmu_zap_wq, &root->tdp_mmu_async_work); > + if (kvm->arch.tdp_mmu_zap_wq) { > + root->tdp_mmu_async_data = kvm; > + INIT_WORK(&root->tdp_mmu_async_work, tdp_mmu_zap_root_work); > + queue_work(kvm->arch.tdp_mmu_zap_wq, &root->tdp_mmu_async_work); > + } > } > > static inline bool kvm_tdp_root_mark_invalid(struct kvm_mmu_page *page)