Received: by 2002:a05:6a10:d5a5:0:0:0:0 with SMTP id gn37csp357005pxb; Wed, 6 Oct 2021 06:31:53 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyIEBdk/pPwxGlV+Bwz8RzkErg0nlIchFMyjBQsBnLB4I8yOndVbjSMxMmYqyvK87gqqPib X-Received: by 2002:a17:90a:1942:: with SMTP id 2mr11030479pjh.36.1633527113183; Wed, 06 Oct 2021 06:31:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1633527113; cv=none; d=google.com; s=arc-20160816; b=D8ho7AvCyV6LWEXCQNGBx+FMNuUkBsPd7QZDxkRMvpjR5TtJi7muHSuXcVPSykjB+U nUuC1NbqnFRdsEepW/m+V+ZoW0HlaDw1y6edqoJnCoORL9mCNxiUeU0BAtquDWTmhd40 OOinQJIU9+vgM4s81ZVyLIuJGs9q+xJ6zi9zTa6JBBpVfUs5oSFcr/58lePQETsr1nvJ 3odqvoM43lDgRe1Is4w1h437zN3reDHwm94OxX0kcz1hMQe+OIiK9ZdANrYrauIdmrBU TAYELSu1HI2hZQ8l1OMQkYER/bm94t72xbCE22jmjjOYv+BevSDlqOqnR5R02N1fR4sB X3eQ== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=6EWf0Yx8j2zCB+diCL/wrV4Cj2FyoAmYIxlZz0GEruY=; b=fthIrMrP7sUHCzKT+gnO9gJ0f9B+XTE5TI1hWJFxNdVJez6fqtNyXpgdnoPuYSeV7v ebZB9f2S71O+GpHSGojkS9YvLpVdpluQQaRIjNV6Ky9vUsLI5iYCSj1m5UAtmQTfWiic knldBoBv4Kq9XDKsRROcomZhu/LcZDmhKNrvq7VmzGdYVJTebJvRWCei2jq0yfXJlvd+ F6oVRgs6mth5rlpgA2vn0WnHUrPRbsMskDDJm9FAyt8OZCvmZpFSvv31xRk4val6YY1l nlP8z6a+nTeCjoeeuBigLi5crQtu7jKIr1/N5OQWUAxb34bHIB9LgByUudu+1HJsHb1x kmOw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=sh023Rab; 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=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id b24si7863067pff.33.2021.10.06.06.31.38; Wed, 06 Oct 2021 06:31:53 -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=@kernel.org header.s=k20201202 header.b=sh023Rab; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238815AbhJFNcT (ORCPT + 99 others); Wed, 6 Oct 2021 09:32:19 -0400 Received: from mail.kernel.org ([198.145.29.99]:48740 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238791AbhJFNcR (ORCPT ); Wed, 6 Oct 2021 09:32:17 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 6E23861151; Wed, 6 Oct 2021 13:30:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1633527025; bh=u3P87IAieIR9/ZaUN58rSAeqVqDTBLGa53zpCdiTFnQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=sh023RabxsRVULBr+PK5ZB3chkLXm28dfLR8QlxCFXDnWfz4u3Om88otYOychxOGl Cxr63STgYiQc62iMKna4D0YUpYACiboA0OlvBVjpnSce5F8+lPQOZnJNAeF6jJyAn0 85/KKHO/SC253pdayhZIB6TC4wXqGrwbi+7V/NLTGNRaRtLULsTfR7Wv9UmiOUrLZ8 yzVwqUJ/kTHViyJbEVp1aWFBa0iWviaLvdAsbxPsTs7RTKGY6CzjZStgWuy9ERoL7g k0TtVnGTjz4tBiyc3NxrU4/M6AZEMHo5Gx70u6AwWmhfbjCri2OBG0T4QlRWi1Tu31 zHgL/qh4CsnGg== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Haimin Zhang , TCS Robot , Paolo Bonzini , Sasha Levin , tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, x86@kernel.org, kvm@vger.kernel.org Subject: [PATCH MANUALSEL 5.14 2/9] KVM: x86: Handle SRCU initialization failure during page track init Date: Wed, 6 Oct 2021 09:30:14 -0400 Message-Id: <20211006133021.271905-2-sashal@kernel.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20211006133021.271905-1-sashal@kernel.org> References: <20211006133021.271905-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Haimin Zhang [ Upstream commit eb7511bf9182292ef1df1082d23039e856d1ddfb ] Check the return of init_srcu_struct(), which can fail due to OOM, when initializing the page track mechanism. Lack of checking leads to a NULL pointer deref found by a modified syzkaller. Reported-by: TCS Robot Signed-off-by: Haimin Zhang Message-Id: <1630636626-12262-1-git-send-email-tcs_kernel@tencent.com> [Move the call towards the beginning of kvm_arch_init_vm. - Paolo] Signed-off-by: Paolo Bonzini Signed-off-by: Sasha Levin --- arch/x86/include/asm/kvm_page_track.h | 2 +- arch/x86/kvm/mmu/page_track.c | 4 ++-- arch/x86/kvm/x86.c | 7 ++++++- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/arch/x86/include/asm/kvm_page_track.h b/arch/x86/include/asm/kvm_page_track.h index 87bd6025d91d..6a5f3acf2b33 100644 --- a/arch/x86/include/asm/kvm_page_track.h +++ b/arch/x86/include/asm/kvm_page_track.h @@ -46,7 +46,7 @@ struct kvm_page_track_notifier_node { struct kvm_page_track_notifier_node *node); }; -void kvm_page_track_init(struct kvm *kvm); +int kvm_page_track_init(struct kvm *kvm); void kvm_page_track_cleanup(struct kvm *kvm); void kvm_page_track_free_memslot(struct kvm_memory_slot *slot); diff --git a/arch/x86/kvm/mmu/page_track.c b/arch/x86/kvm/mmu/page_track.c index 91a9f7e0fd91..68e67228101d 100644 --- a/arch/x86/kvm/mmu/page_track.c +++ b/arch/x86/kvm/mmu/page_track.c @@ -163,13 +163,13 @@ void kvm_page_track_cleanup(struct kvm *kvm) cleanup_srcu_struct(&head->track_srcu); } -void kvm_page_track_init(struct kvm *kvm) +int kvm_page_track_init(struct kvm *kvm) { struct kvm_page_track_notifier_head *head; head = &kvm->arch.track_notifier_head; - init_srcu_struct(&head->track_srcu); INIT_HLIST_HEAD(&head->track_notifier_list); + return init_srcu_struct(&head->track_srcu); } /* diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index 7ec7c2dce506..b3f855d48f72 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -11090,9 +11090,15 @@ void kvm_arch_free_vm(struct kvm *kvm) int kvm_arch_init_vm(struct kvm *kvm, unsigned long type) { + int ret; + if (type) return -EINVAL; + ret = kvm_page_track_init(kvm); + if (ret) + return ret; + INIT_HLIST_HEAD(&kvm->arch.mask_notifier_list); INIT_LIST_HEAD(&kvm->arch.active_mmu_pages); INIT_LIST_HEAD(&kvm->arch.zapped_obsolete_pages); @@ -11125,7 +11131,6 @@ int kvm_arch_init_vm(struct kvm *kvm, unsigned long type) kvm_apicv_init(kvm); kvm_hv_init_vm(kvm); - kvm_page_track_init(kvm); kvm_mmu_init_vm(kvm); return static_call(kvm_x86_vm_init)(kvm); -- 2.33.0