Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp6649985iob; Wed, 11 May 2022 02:15:30 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyRboKJh69iivGQqi962oYrbrtbyDU0rGoWSdLmNF427tzeN4P24m0uuHB/zLnHwf5m9I/g X-Received: by 2002:a17:907:9805:b0:6f4:fe0e:5547 with SMTP id ji5-20020a170907980500b006f4fe0e5547mr23575832ejc.426.1652260529889; Wed, 11 May 2022 02:15:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652260529; cv=none; d=google.com; s=arc-20160816; b=ljjLqPM9sWi5W8fE4vkXQga+qzdlwc7jj5T/riy9j76jasNgnlU7LVv0Kyxy1YhaoZ fSkXq+Z4KiPcI67HIb/ibg/J+axumYCFTIlNZLDce+s0mIDdnqor3S62BrbH/jVv2ASJ fZaqE/5EPlqNTcAORk69vbBRs2duGNoJ96Kb/W3wBW9NbvA71q9WvG1KTP3JlKoOcT/r Pd0oEdZE1+X3+FvH1lN50zWD0hCyjFF/qRPfcuJqp4abqa+iu7BRSD1r9PIllsUSXfQD qmV1dOS2qCuPimAmYsxY8J+Rxa4X8b7mJY37U0HkrRg4SCKsClnCb1QF0Gfo6t08GW2f kHpw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date; bh=QBNAXw3GGs0zox2rP0uBeZAodjAqL+kxsYRyiQa3Ehg=; b=ZFVyQx7SffW3damk04AwGYCbIqGy6fAfc289CplQaPhNqLtTklyAwqOtipiAAYCaBk y2AmP/FP87JnRkFoMCmsaqCV/ieWNsUNKnPCYSRL0DSgMCjxQuFk3N8XVOLmkNX4JpDB 2d9x6cHrTuZNzDt9Ab6UoYkhXcY3Df+Xafi/ICe5TF6l05LTRxj2LvK8hl3zBPls62Dq BaYDBrKFZ1T0L1zlGrvv/+OwelWGBizrWYOM9aJeJTQwUMJehoCAf1dWQ14Gw7TuUwgc AerALtaLDbep7opVRkqYJBCM1WnERIx46IEjLQlV4zOmV4MULSthOpF8DUVVKU7lygbD 4TpQ== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id dm21-20020a170907949500b006f3a88ccf8dsi1812871ejc.333.2022.05.11.02.15.05; Wed, 11 May 2022 02:15:29 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235255AbiEJUmA (ORCPT + 99 others); Tue, 10 May 2022 16:42:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43240 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236481AbiEJUl6 (ORCPT ); Tue, 10 May 2022 16:41:58 -0400 Received: from mail.hallyn.com (mail.hallyn.com [178.63.66.53]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 02A08527E8; Tue, 10 May 2022 13:41:52 -0700 (PDT) Received: by mail.hallyn.com (Postfix, from userid 1001) id 404B979C; Tue, 10 May 2022 15:41:51 -0500 (CDT) Date: Tue, 10 May 2022 15:41:51 -0500 From: "Serge E. Hallyn" To: Christian Brauner Cc: "Serge E. Hallyn" , Stefan Berger , linux-integrity@vger.kernel.org, zohar@linux.ibm.com, christian.brauner@ubuntu.com, containers@lists.linux.dev, dmitry.kasatkin@gmail.com, ebiederm@xmission.com, krzysztof.struczynski@huawei.com, roberto.sassu@huawei.com, mpeters@redhat.com, lhinds@redhat.com, lsturman@redhat.com, puiterwi@redhat.com, jejb@linux.ibm.com, jamjoom@us.ibm.com, linux-kernel@vger.kernel.org, paul@paul-moore.com, rgb@redhat.com, linux-security-module@vger.kernel.org, jmorris@namei.org, jpenumak@redhat.com, John Johansen , Matthew Garrett , Micah Morton , Kentaro Takeda , Jarkko Sakkinen Subject: Re: [PATCH v12 01/26] securityfs: rework dentry creation Message-ID: <20220510204151.GA12935@mail.hallyn.com> References: <20220420140633.753772-1-stefanb@linux.ibm.com> <20220420140633.753772-2-stefanb@linux.ibm.com> <20220509195414.GA30894@mail.hallyn.com> <20220510102525.hlt2rm3k3hg5r6gg@wittgenstein> <20220510141025.GA7290@mail.hallyn.com> <20220510155107.srxifzuqfstvet2f@wittgenstein> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220510155107.srxifzuqfstvet2f@wittgenstein> User-Agent: Mutt/1.9.4 (2018-02-28) X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_PASS, 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 On Tue, May 10, 2022 at 05:51:07PM +0200, Christian Brauner wrote: > On Tue, May 10, 2022 at 09:10:25AM -0500, Serge Hallyn wrote: > > On Tue, May 10, 2022 at 12:25:25PM +0200, Christian Brauner wrote: > > > On Mon, May 09, 2022 at 02:54:14PM -0500, Serge Hallyn wrote: > > > > On Wed, Apr 20, 2022 at 10:06:08AM -0400, Stefan Berger wrote: > > > > > From: Christian Brauner > > > > > > > > > > When securityfs creates a new file or directory via > > > > > securityfs_create_dentry() it will take an additional reference on the > > > > > newly created dentry after it has attached the new inode to the new > > > > > dentry and added it to the hashqueues. > > > > > If we contrast this with debugfs which has the same underlying logic as > > > > > securityfs. It uses a similar pairing as securityfs. Where securityfs > > > > > has the securityfs_create_dentry() and securityfs_remove() pairing, > > > > > debugfs has the __debugfs_create_file() and debugfs_remove() pairing. > > > > > > > > > > In contrast to securityfs, debugfs doesn't take an additional reference > > > > > on the newly created dentry in __debugfs_create_file() which would need > > > > > to be put in debugfs_remove(). > > > > > > > > > > The additional dget() isn't a problem per se. In the current > > > > > implementation of securityfs each created dentry pins the filesystem via > > > > > > > > Is 'via' an extra word here or is there a missing word? > > > > > > > > I'll delay the rest of my response as the missing word may answer my > > > > remaining question :) > > > > > > It can be both. It should either be removed or it should be followed by > > > "securityfs_create_dentry()". securityfs_create_dentry() takes two > > > references one in lookup_one_len() and another one explicitly via > > > dget(). The latter one isn't needed. Some of that has been covered in an > > > earlier thread: > > > https://lore.kernel.org/lkml/20220105101815.ldsm4s5yx7pmuiil@wittgenstein > > > > Yes, I saw that two references were being taken. And near as I can tell, > > the second one was never being dropped. So if you tell me that before this > > patch the dentries are never freed, then I'm happy. Otherwise, I'm > > bothered the fact that no matching dput is being deleted in the code (to > > match the extra dget being removed). So where is the code where the final > > dput was happening, and is it the d_delete() you're adding which is making > > it so that that dput won't be called now? > > * So consider mounting securityfs _without this patch applied_: > > mount -t securityfs /sfs > > and assume we only have a single user that creates a file "foo" via > > securityfs_create_file() > { > lookup_one_len(); // first dget() > dget(); // second dget() > } > > now assume that user at some point calls > > void securityfs_remove() > { > if (d_is_dir(dentry)) > simple_rmdir(dir, dentry); // first dput() > else > simple_unlink(dir, dentry); // first dput() > dput(dentry); // second dput() > } > > * Now consider mounting securityfs _with this patch applied_: > > securityfs_create_file() > { > lookup_one_len(); // first dget() > } > > void securityfs_remove() > { > dget(); // second dget() > if (d_is_dir(dentry)) > simple_rmdir(dir, dentry); // first dput() > else > simple_unlink(dir, dentry); // first dput() > dput(dentry); // second dput() > } Thanks, I get it now Reviewed-by: Serge Hallyn