Received: by 2002:a05:6a10:d5a5:0:0:0:0 with SMTP id gn37csp362004pxb; Wed, 6 Oct 2021 06:37:56 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwchs9iF8Syjd9B+K69Ie3k4az0nTUi1qE2StmCXe3b6NGKVPYYsBoGNh11xafcR/rrVqL4 X-Received: by 2002:a17:902:c3c1:b0:13e:d190:849b with SMTP id j1-20020a170902c3c100b0013ed190849bmr11160788plj.78.1633527476048; Wed, 06 Oct 2021 06:37:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1633527476; cv=none; d=google.com; s=arc-20160816; b=VUYqhhe3LLnREk7qmPYtqDG7CeZReVBzQn8kT0A3xrHsqv4LVUpkfRIpAuUcPX2DKl K5nOoqNDmUmIcxUIQmDKY0LOYwsnWc0ioqCHFfA2MiLA7Lt8y9f+yeCNT4S/E1byviHg 6UidM5Af28EDrFSv/Y28PmNbN7GHUBwXIOXDlC4qW5qTvl9AGymJon1CftzEapo+bE3c THehaLs+7CH2dJd7lRa5Fxf+AYmHq/NxYg/xsK4pHW0/fGqUjKu50Eo41rgKw13nPsd/ Y6knK4vbr2GAMldrLbaJBVE/p7/i6wnzwM5t7GkWEgb5FXwRpfnLISCTtiPVB+UnqLOb 7Jpg== 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:dkim-signature; bh=5Y7uP8QRGocqx1FZVyYu93M+isTRRJCiJChkQsmHD78=; b=jhE2M/H9ZdVlI7QpZf8DxohELw1erHyrWo45yWpDTQIo6T1uikdK2HCMJu7xIz+8bi 5IdjdjfjIAKL3HzGiWXFKtigQAZbbh4uXQS7SiXapuU8vLhdqRm0FP+1T04v59lxaMQ+ MT0LCQWx1ga5DOBbbPrR2oHPOqXq2C95OlFBCCfMLZbLgVFDmQF+Dhg5LNOv/Obvfgb2 h7hMV6ctlvoS4b+mJmbdIJrTqRpa9iqCmT0gfB4FvPdYK1aXtxHaXwrTjd3oP4A12+va cKz39j/vdSTPs+PUP1dz18TIPAT+gf32FU+dXTdJfy4i2H+pAV7zdrW2cchWsrSYScFg ubnQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=M7sEu0PO; 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=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id s11si31459436pgp.222.2021.10.06.06.37.41; Wed, 06 Oct 2021 06:37:56 -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=@redhat.com header.s=mimecast20190719 header.b=M7sEu0PO; 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=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238701AbhJFNiW (ORCPT + 99 others); Wed, 6 Oct 2021 09:38:22 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:43471 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238952AbhJFNiT (ORCPT ); Wed, 6 Oct 2021 09:38:19 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1633527386; 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=5Y7uP8QRGocqx1FZVyYu93M+isTRRJCiJChkQsmHD78=; b=M7sEu0POQRrvt7zrygMEXvp42H/0eLlAmxDfQx683nhnumTuzWdcuoPgD11wllrFWBUtXv rwJYUWGcIipBSUe0NLhkK+BXVil7AtufNy3cQglRemt+8H4UZ93GkmaWF9gt5vDiR/opa5 JnMN4tovdsGPPVWMAyp5qfFR7h885SU= Received: from mail-ed1-f72.google.com (mail-ed1-f72.google.com [209.85.208.72]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-5-GJ8z24eVOWO9-460hm3O6Q-1; Wed, 06 Oct 2021 09:36:25 -0400 X-MC-Unique: GJ8z24eVOWO9-460hm3O6Q-1 Received: by mail-ed1-f72.google.com with SMTP id w6-20020a50d786000000b003dabc563406so2631166edi.17 for ; Wed, 06 Oct 2021 06:36:25 -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=5Y7uP8QRGocqx1FZVyYu93M+isTRRJCiJChkQsmHD78=; b=tV+l/6nrUNP+AGm+tDRIBp+RKtHT7stcWvEbMJJrfiQVwwuw1qWpIZkFB19t9bgdiM Mgj58DS31EGpHLkAkO97nK5FBE6frKoIsLOdQBvIUWc9Ajrei0dRWo7caJBr4Spurv9U 3EUldt8w5D+LDl+rw5E3pJWeYPgcEKeOJi29YMfIsZMB/e2UNpTGkQjQEZqjsZeYxzHh OrbdT0D7Gmgvq4AQlzuEoezx3+fkdyZg7xPjFgK33Lipq6aO0fK5JPj7bg6emaZXibT6 0QeyZkXW/Mz1/TvvnubkzGrRsVfDwOTVxx2XjMjgQlX0E21qHsomPceSg4PYT34mcbZ1 Q4OA== X-Gm-Message-State: AOAM533KQs6FpewdZaQymwL5inpKZemxHn8tDwnCWglZiGNLtlCVnCIH 50mSWxcu1VXssRsJNz+CIhil5w4GoOuWoUEAfXM4ifnJAHM9ts++rzjrP1/kSosDP+7oQSTzYTj 0W9EJAXU3uUxnlgyGObB2n5e9 X-Received: by 2002:a50:be87:: with SMTP id b7mr35515636edk.382.1633527382864; Wed, 06 Oct 2021 06:36:22 -0700 (PDT) X-Received: by 2002:a50:be87:: with SMTP id b7mr35515607edk.382.1633527382653; Wed, 06 Oct 2021 06:36:22 -0700 (PDT) Received: from ?IPV6:2001:b07:6468:f312:5e2c:eb9a:a8b6:fd3e? ([2001:b07:6468:f312:5e2c:eb9a:a8b6:fd3e]) by smtp.gmail.com with ESMTPSA id x16sm4468819ejj.8.2021.10.06.06.36.20 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 06 Oct 2021 06:36:21 -0700 (PDT) Message-ID: Date: Wed, 6 Oct 2021 15:36:20 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.1.0 Subject: Re: [PATCH MANUALSEL 5.14 2/9] KVM: x86: Handle SRCU initialization failure during page track init Content-Language: en-US To: Sasha Levin , linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Haimin Zhang , TCS Robot , tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, x86@kernel.org, kvm@vger.kernel.org References: <20211006133021.271905-1-sashal@kernel.org> <20211006133021.271905-2-sashal@kernel.org> From: Paolo Bonzini In-Reply-To: <20211006133021.271905-2-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 06/10/21 15:30, Sasha Levin wrote: > 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); > Acked-by: Paolo Bonzini