From patchwork Wed Apr 6 23:56:13 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oliver Upton X-Patchwork-Id: 12804255 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 67525C433EF for ; Wed, 6 Apr 2022 23:57:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:From:Subject:References: Mime-Version:Message-Id:In-Reply-To:Date:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=ND9X1LUz4xOikhC2QQlmlfERH8PPrd17FwD9iAx2FDw=; b=pJboXeGmMVT4d/hQOW8K83nm7u KRHwMy8RRiUz89sNGFjB3eRx9QbaqfIN04FXSUtOAHfjRqioubghDbBfpSo1q5+sqlXWljV8k3EDi z87BBqXrUIbvCL5eZ2zfigQXEsOXVDwaIxpNDKLs30vtzbMWGu9Vgu27aCSpTtCvPprSXkAlMvNS4 PFHqM/YdA6Gwz/5BT6R2GXLX2gmiMHsroeHUjiLbgajDxS78X6bb0QJYL/va3orCiPumygUkL5gBE 7qAMJFfgeAPrbx5pSiInNCfy0YU9dr80JOkxAsFva5/ABchXa6wOs6MgCUe45WohR6dk2gD9GXsok 7TIShNKA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1ncFVq-008L4I-Ty; Wed, 06 Apr 2022 23:56:35 +0000 Received: from mail-yb1-xb4a.google.com ([2607:f8b0:4864:20::b4a]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1ncFVh-008L1J-P7 for linux-arm-kernel@lists.infradead.org; Wed, 06 Apr 2022 23:56:27 +0000 Received: by mail-yb1-xb4a.google.com with SMTP id r134-20020a25768c000000b0063d13119f84so2937144ybc.16 for ; Wed, 06 Apr 2022 16:56:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=UE8U10PWA5ODRXn2/uykVggaoFMEeuBNkjbyKzrUnCc=; b=StweytVoVyZbt90ESUuB2VGZmpz69UiQywLFR+/3fhQYHNUTdQZloEgP4cirg0Kkhd ureLULbzCXKzEuVeyccV7zNNedLEQpO4ayhcybXsVmgxDbgKCBrnsMt4KcoGFXliCiDL p0yS3x603eqH2cuF0Jfgeumy6ZZXE4/Odao00WPCwWYzuYVheUOvU/y7PhYbkklz5J8P spP+ZBEnX4drhVit+1wCy6T9N9UoRJEFMu/pj0F3D0FqfNpLHeAMKkavfelwlloXm8Ki mtOpj9fHSSXtZbEZUujQ5kBOBV5TtTSNk278FllAny6hV6Rytjamf7Z1WSwRNnqUdxFb gBaA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=UE8U10PWA5ODRXn2/uykVggaoFMEeuBNkjbyKzrUnCc=; b=drg7ey/6xgqU1KxE3acTknjdqZRh1pWgJ3IF7nN99Wr/GoI8w4NrRviAvk0ur8tYIz +r/0EPzgAfi8hFtg8qK5uXk4AXqzw5AME0W91D15vaF9mFjlMTqWjgQpi7uitpCFF1WX g2ryBAQbok4eGivcn1ualzCFuBdsYlUwzjAQSHfWpJtjpuJixOgQ0BDQ2rSQGpHtM6r4 s+bY75D7x5Jo/ET8tBLY+naoS0iOQkBpiyjqWnwE4QZ8esP0rQBPr3mXl4FnAmoBF6XI rAuMM9dB16aFGosZCnNwZz+GFaVPFmcOLKvKC19CpFQnS6AAZSX03jvv0/hbmF2w21kJ y8/w== X-Gm-Message-State: AOAM532LulNlk4m2e9v/7lmClHICyRAriixsGzKqYepx+uWGlaBNqAjc Qzokn1obFyQzwo6Tx9jc08n6XtNKBJM= X-Google-Smtp-Source: ABdhPJydvJQ9YWsazIPz0K7K9LDxhja6MJh+d1QgvhsxpSx1I3YpvuashAMC5XHLhA33/FRzcSzrmPBE1A8= X-Received: from oupton.c.googlers.com ([fda3:e722:ac3:cc00:2b:ff92:c0a8:404]) (user=oupton job=sendgmr) by 2002:a05:6902:100e:b0:637:7536:6582 with SMTP id w14-20020a056902100e00b0063775366582mr8357978ybt.355.1649289383593; Wed, 06 Apr 2022 16:56:23 -0700 (PDT) Date: Wed, 6 Apr 2022 23:56:13 +0000 In-Reply-To: <20220406235615.1447180-1-oupton@google.com> Message-Id: <20220406235615.1447180-2-oupton@google.com> Mime-Version: 1.0 References: <20220406235615.1447180-1-oupton@google.com> X-Mailer: git-send-email 2.35.1.1094.g7c7d902a7c-goog Subject: [PATCH v3 1/3] KVM: Don't create VM debugfs files outside of the VM directory From: Oliver Upton To: kvmarm@lists.cs.columbia.edu Cc: kvm@vger.kernel.org, Marc Zyngier , James Morse , Alexandru Elisei , Suzuki K Poulose , linux-arm-kernel@lists.infradead.org, Peter Shier , Ricardo Koller , Reiji Watanabe , Paolo Bonzini , Sean Christopherson , Oliver Upton , stable@kernel.org X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220406_165625_853944_505A7919 X-CRM114-Status: GOOD ( 18.22 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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 --- virt/kvm/kvm_main.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c index 70e05af5ebea..e39a6f56fc47 100644 --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c @@ -932,7 +932,7 @@ static void kvm_destroy_vm_debugfs(struct kvm *kvm) 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); @@ -955,6 +955,12 @@ static int kvm_create_vm_debugfs(struct kvm *kvm, int fd) 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; @@ -5479,7 +5485,7 @@ static void kvm_uevent_notify_change(unsigned int type, struct kvm *kvm) } 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) {