Received: by 2002:a05:6a10:6d10:0:0:0:0 with SMTP id gq16csp3391962pxb; Tue, 19 Apr 2022 01:08:56 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxDyWcFteZvtP5X0u58eTAxBj81i4RajgF/wZaz9JQg/rF9BskgZ5ncBy8Ti1Ua2+hUDyFr X-Received: by 2002:a17:90a:1a0b:b0:1d2:a1e6:230 with SMTP id 11-20020a17090a1a0b00b001d2a1e60230mr8859413pjk.179.1650355735949; Tue, 19 Apr 2022 01:08:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1650355735; cv=none; d=google.com; s=arc-20160816; b=DW/rCTUD59nhxpKiYrcGd63Wcf2njxz54SlYY0nuWBEv/UFexizlZNgyNAeSdKCzpw T5eOvhr80Yf9XiZB+vrPdmTpaGK5v/x+iJ8mWFWKmMvcpH4YnUmETq6TYAeYtL4WEauE BNIrZAHKxZE9hRJ0eA2QMkG9kQ4geBd/1QnSbV00VdZzAwviYy+9pKDToe0OFmhuxIkn XmM8g99uBM7JaVzvE1a4nf04eiv/hXyzcSXf/wqRbkGbSIwR75EniBytB+uPfOM1aZIv KbT1YwbkP18getT+zsIyHyKXZFvGbWL77nYrryby4VHS8h57ZtQQHI2ZzSMyzaKQo72U ReGQ== 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=ZkREQgMEZ64DA2hnAsmBbDI35wHFpJSoVPAg141S6gY=; b=CfiHi2+qJBCN7zfYxSV5Ahsfw2tNFnbEVwcj5tIBLvF7tlnmMs7oNX8JHZvRi07SjD BRyUT9sc7PSo8AIJxDFgS1Ogr5MwL6zLCxDHkILZZM6r/QBVy23du0W1DQ+FUqc8eU6T hcCzym+0dG8nTqr8hmUvJ/DnxePdjz0cRyireG8rkwMHLOVGvW23ILUeHTqzR2bhyHdX Oi8l/39C3Z0S1SwDtUBS5U8fpYmF2ooyK7Z0TgaHOzqIiLtPJq68/xBEkIiFtcx+wp+A c8epv1VuwqoMXQtsi1Aa5mo5P8+5ZeDwo1oQaJvuH05lvkrJ4JQHtDK8GnwaSEJpq/d5 o2qQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=YMvPs0Yq; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id lr13-20020a17090b4b8d00b001ca67459147si1695685pjb.104.2022.04.19.01.08.41; Tue, 19 Apr 2022 01:08:55 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=YMvPs0Yq; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S239386AbiDRMha (ORCPT + 99 others); Mon, 18 Apr 2022 08:37:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52846 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239073AbiDRMbj (ORCPT ); Mon, 18 Apr 2022 08:31:39 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7D2C4E089; Mon, 18 Apr 2022 05:24:07 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id D6B8F60FA7; Mon, 18 Apr 2022 12:24:06 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id DCE51C385A7; Mon, 18 Apr 2022 12:24:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1650284646; bh=YkaemEMBK7qaTeQB8mFXuiMEQuO6DXR44MGW7zHTBoM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=YMvPs0YqMy/eINu+ploeE9Uyc/Jd1YiYUW/FVnd33Myed3a9LUz1rSpArE9GWZda1 319yiYypmZq4OT0SaiFPYNeh8VA70ayjwYA3PDsvQbQlNw55m7dOEGPHJVR1ppneDT Fy+QGRh+msbyI5YqXHROybQicPO197rKawQ4qmyM= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, stable@kernel.org, Oliver Upton , Marc Zyngier Subject: [PATCH 5.17 183/219] KVM: Dont create VM debugfs files outside of the VM directory Date: Mon, 18 Apr 2022 14:12:32 +0200 Message-Id: <20220418121212.002023130@linuxfoundation.org> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20220418121203.462784814@linuxfoundation.org> References: <20220418121203.462784814@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.7 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham 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 From: Oliver Upton commit a44a4cc1c969afec97dbb2aedaf6f38eaa6253bb upstream. Unfortunately, there is no guarantee that KVM was able to instantiate a debugfs directory for a particular VM. To that end, KVM shouldn't even attempt to create new debugfs files in this case. If the specified parent dentry is NULL, debugfs_create_file() will instantiate files at the root of debugfs. For arm64, it is possible to create the vgic-state file outside of a VM directory, the file is not cleaned up when a VM is destroyed. Nonetheless, the corresponding struct kvm is freed when the VM is destroyed. Nip the problem in the bud for all possible errant debugfs file creations by initializing kvm->debugfs_dentry to -ENOENT. In so doing, debugfs_create_file() will fail instead of creating the file in the root directory. Cc: stable@kernel.org Fixes: 929f45e32499 ("kvm: no need to check return value of debugfs_create functions") Signed-off-by: Oliver Upton Signed-off-by: Marc Zyngier Link: https://lore.kernel.org/r/20220406235615.1447180-2-oupton@google.com Signed-off-by: Greg Kroah-Hartman --- virt/kvm/kvm_main.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c @@ -937,7 +937,7 @@ static void kvm_destroy_vm_debugfs(struc int kvm_debugfs_num_entries = kvm_vm_stats_header.num_desc + kvm_vcpu_stats_header.num_desc; - if (!kvm->debugfs_dentry) + if (IS_ERR(kvm->debugfs_dentry)) return; debugfs_remove_recursive(kvm->debugfs_dentry); @@ -960,6 +960,12 @@ static int kvm_create_vm_debugfs(struct int kvm_debugfs_num_entries = kvm_vm_stats_header.num_desc + kvm_vcpu_stats_header.num_desc; + /* + * Force subsequent debugfs file creations to fail if the VM directory + * is not created. + */ + kvm->debugfs_dentry = ERR_PTR(-ENOENT); + if (!debugfs_initialized()) return 0; @@ -5484,7 +5490,7 @@ static void kvm_uevent_notify_change(uns } add_uevent_var(env, "PID=%d", kvm->userspace_pid); - if (kvm->debugfs_dentry) { + if (!IS_ERR(kvm->debugfs_dentry)) { char *tmp, *p = kmalloc(PATH_MAX, GFP_KERNEL_ACCOUNT); if (p) {