Received: by 2002:a05:6a10:d5a5:0:0:0:0 with SMTP id gn37csp3807987pxb; Mon, 4 Oct 2021 10:02:26 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwXPKJygzin1v44EWsW+X76/xpsvjwAs0/vzEzP7qWCA5mKXieGc6QSXEP0wpm8ry4Faj9i X-Received: by 2002:a17:90a:10:: with SMTP id 16mr31635630pja.50.1633366946672; Mon, 04 Oct 2021 10:02:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1633366946; cv=none; d=google.com; s=arc-20160816; b=gXqvkb8psNH9WE0HWdbGLwsGgATtTZ4DD5sLc4VCoK6rkb38IfSdpPQN7pW3cGrDI/ xZuXMbqsgUudUxM2flK5nWpegW73wFaS1Uk80ZpW/9uGE4WjFLYX8K26MprYy0d1UXUF MiqTTYlUHOf3DmZQsGRyuM5BP+ob64EvcKIYeVMkVarKlPMP9FVwdM/WD/+5aS9iXrQa cntYB3Pv4iLtixeyMl9XLscp2+zTlfQxW/lJsJY2waQIJX34eAvD607jClTwxOpss4H5 OJLeFU3dRjLv46kbaoAMy8y50W5yT3etlmu3hQn4p1zVhj4XgcQ0Mg7JAiIQ9zD4f1Ja H4qg== 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=z1C3JkUkKIT3DqgUKeQjg10HnScoaGh/MzgxcAtqFAY=; b=xzVqb3emK+hFIbI8P/+0r1Pf95BMZVrfQoijdtqa63U5pom74aLT/iZ1IkHClegmgu CnvlK34e0kRC9X8BQSuE4bdwfjXspIplEm8/fxyeq7UXBMz9L/UzYbTIpsXE4ABI/ohS 5JRKGzQ/nEn9bNKJ5GYZJJd5NNaVjxJBfMb1yTm2KQNzMRFc0eGyf+3Tu3lrv2eBhHCG v3zVRXWhKIDM+MUxOmhUhCfZLBbNY6UDVjx359RcUubf7QVivgQVJfii6tECyAdZuCMs PeXJhu7InAFGqxEN10jF44oHyRLa0sS4z7O0REYP9zH+Y63hGghHOxIGckA2pl67a3Eg FeqQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=gdY6wLqs; 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 j73si11979780pge.385.2021.10.04.10.02.10; Mon, 04 Oct 2021 10:02:26 -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=gdY6wLqs; 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 S238186AbhJDNpR (ORCPT + 99 others); Mon, 4 Oct 2021 09:45:17 -0400 Received: from mail.kernel.org ([198.145.29.99]:51966 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238302AbhJDNmB (ORCPT ); Mon, 4 Oct 2021 09:42:01 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 952A061B5F; Mon, 4 Oct 2021 13:19:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1633353559; bh=GTeihYqeg/dAY5dWT6mKp5H7xEbmQHk9pU9mM3bKo5Y=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=gdY6wLqsIxy+CpS9b6y0G8X5mfRwQOXS4aA82mJ52io65zb/O43dqsq49FRyLjzYl LeAKT/lHwRkmE9GZHu+EbaeKrmXToUiDzLkKxd6lA5FAVMTwyELXqYFpcBvrK3E4P1 gl7BXUThFpHYrFVCS4XzikrFSyRZaAtixkZfcTio= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, TCS Robot , Haimin Zhang , Paolo Bonzini Subject: [PATCH 5.14 169/172] KVM: x86: Handle SRCU initialization failure during page track init Date: Mon, 4 Oct 2021 14:53:39 +0200 Message-Id: <20211004125050.431128011@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20211004125044.945314266@linuxfoundation.org> References: <20211004125044.945314266@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: Haimin Zhang commit eb7511bf9182292ef1df1082d23039e856d1ddfb upstream. 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: Greg Kroah-Hartman --- 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(-) --- 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); --- 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 * 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); } /* --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -11093,9 +11093,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); @@ -11128,7 +11134,6 @@ int kvm_arch_init_vm(struct kvm *kvm, un 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);