From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.5 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E34F1C4338F for ; Tue, 3 Aug 2021 13:12:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id CB7A360F93 for ; Tue, 3 Aug 2021 13:12:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236426AbhHCNMV (ORCPT ); Tue, 3 Aug 2021 09:12:21 -0400 Received: from mail.kernel.org ([198.145.29.99]:33300 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236351AbhHCNME (ORCPT ); Tue, 3 Aug 2021 09:12:04 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 607A360F8F; Tue, 3 Aug 2021 13:11:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1627996313; bh=G9QZGioog0e7pS11z7Di9y9T7Cul6LuoangPMjmp7do=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=sQCZPKuox08viEWmQ1Vwdngj3jDYEtbBL3Z9zsohNDjLiqS1XGHC3OPoIDWEJzKDE ncOVT/DxqvlWY5abrYUO9v9/4XOJOaVaRJ0eVngCzWjg9f/cwgFCJbAlbpyENrNDRu heB9jxxVK0kD3RAAb5EqjdYJOMyc8DMQdf/Ap8rk= Date: Tue, 3 Aug 2021 15:11:51 +0200 From: Greg KH To: Paolo Bonzini Cc: Alexey Kardashevskiy , "Kernel Mailing List, Linux" , kvm Subject: Re: [RFC PATCH kernel] KVM: Stop leaking memory in debugfs Message-ID: References: <20210730043217.953384-1-aik@ozlabs.ru> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Aug 03, 2021 at 02:52:17PM +0200, Paolo Bonzini wrote: > On Tue, Aug 3, 2021 at 1:16 PM Greg KH wrote: > > On Fri, Jul 30, 2021 at 02:32:17PM +1000, Alexey Kardashevskiy wrote: > > > snprintf(dir_name, sizeof(dir_name), "%d-%d", task_pid_nr(current), fd); > > > kvm->debugfs_dentry = debugfs_create_dir(dir_name, kvm_debugfs_dir); > > > + if (IS_ERR_OR_NULL(kvm->debugfs_dentry)) { > > > + pr_err("Failed to create %s\n", dir_name); > > > + return 0; > > > + } > > > > It should not matter if you fail a debugfs call at all. > > > > If there is a larger race at work here, please fix that root cause, do > > not paper over it by attempting to have debugfs catch the issue for you. > > I don't think it's a race, it's really just a bug that is intrinsic in how > the debugfs files are named. You can just do something like this: > > #include > #include > #include > #include > #include > #include > #include > int main() { > int kvmfd = open("/dev/kvm", O_RDONLY); > int fd = ioctl(kvmfd, KVM_CREATE_VM, 0); > if (fork() == 0) { > printf("before: %d\n", fd); > sleep(2); > } else { > close(fd); > sleep(1); > int fd = ioctl(kvmfd, KVM_CREATE_VM, 0); > printf("after: %d\n", fd); > wait(NULL); > } > } > > So Alexey's patch is okay and I've queued it, though with pr_warn_ratelimited > instead of pr_err. So userspace can create kvm resources with duplicate names? That feels wrong to me. But if all that is "duplicate" is the debugfs kvm directory, why not ask debugfs if it is already present before trying to create it again? That way you will not have debugfs complain about duplicate files/directories. thanks, greg k-h