Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp6141943iob; Tue, 10 May 2022 11:15:44 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyDzDkVDJQhHbBNaz2T+LrMe0xNtA7ajJLFTxZ+gyHgb+OftuG/qjg+YVIVs7JX2k/WwcGT X-Received: by 2002:a17:907:3e21:b0:6f4:6c7c:c781 with SMTP id hp33-20020a1709073e2100b006f46c7cc781mr20407034ejc.735.1652206544660; Tue, 10 May 2022 11:15:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652206544; cv=none; d=google.com; s=arc-20160816; b=kZKEZuF5Trmp2Qj4BX9Izg9TAg2etD4mzi4aS3c8iHXGfMgAH8goqQKb8z4Gjp9KzT 0iLkjs8trFqknIHQv+hZR7aphPaWfQK8K1tuSVA/cXZri39nT4HiWoOW8BPnNdPBusKB xMaNnVPdbVB4caQnSUtghEzGWoBfhxK8MVgaCbSXg8vNmvrr+3EljEKnVTXYxlRYmSVk iznkBrRY/mzQVisyJp5hoInGgWCMGHMnaMDswHzdqX56JXliNR6DHJUh/awS1RuocsvR abow6G+OBWK7suJCtxMmyzwC/xhCUd+1b2/SYkX7Qi8t3Ie/ZeyW+iC886gla0F2A9xO BYvA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=w/VgDcHIQVd1VFujA77tRAjsVEp14iczx4s/7PxxuSM=; b=YpwFE4xsl5cKGJgyHFylJkvjVJP+XSLQrgE9uS+bc6YoSS5vk737jOwZRA5FOcbueL J+245PcKtga8wkscnYwOhzngmc0mLh0bhzsIwTHDr01NJuMH/bfyM1sZoxrB5q/gHWcZ s9m6xLDCdjkU86E2SaRYCmzwZ+hdglcyde6diYaXl7mBMnA5FZm//swptxCL7Xm+rd2Y WSO15verB1NTyQVRB75JbJPOgLQreSlLtTJjyI///y7jkvQnPCrXjaQVNND/9AqYyDFn aYLiRPFcS8zByjU0oNoV0+34qcmMIfaXqVk3C3Gwjk5e7744YE03ym53e1PnP8h7hgGF RxDw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=akwaLFkg; 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=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id o23-20020a056402039700b00425c46cc98esi15931098edv.92.2022.05.10.11.15.19; Tue, 10 May 2022 11:15:44 -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=@kernel.org header.s=k20201202 header.b=akwaLFkg; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347022AbiEJQDa (ORCPT + 99 others); Tue, 10 May 2022 12:03:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49822 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347876AbiEJP6K (ORCPT ); Tue, 10 May 2022 11:58:10 -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 D1BC462CF2; Tue, 10 May 2022 08:51:19 -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 1EA0161373; Tue, 10 May 2022 15:51:17 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 88345C385A6; Tue, 10 May 2022 15:51:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1652197876; bh=6JxcE5t9KXVE8fMNIQQ+vlROON2kYoaeG2ur0y4wic8=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=akwaLFkg0R/3GizbON24I88jiLQHcxNG8NGP6pKgKS5C20Khy1Y7xZNOmJ1vAelWH rklD2/xr0jvYdgTPQ+bgI54Yis5lQ6qpm8zKgAAGNREmUk4dP47T37AtmFAVt+9ZLn 7ybau9gnxTutbjks0xu5bdYaLWBF0fhuuYhnHQ/NGnWoLHD6xpBik/lQlltS3OxC8m 5DPiB0+mHyrLbixkwNyrsKK7V/DIGaYhx8ekCyDDC39Oq0NGXSFIMw4oGVoLfqe1Ad SQJXjYjCBSBCP0Tfxpj4Wnb/XvmucYWbOg/cO1t+HaI8YoTDuVXsRzdCbUGDmZqWDy MHmI9I4lAIjAA== Date: Tue, 10 May 2022 17:51:07 +0200 From: Christian Brauner To: "Serge E. Hallyn" Cc: 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: <20220510155107.srxifzuqfstvet2f@wittgenstein> 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> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20220510141025.GA7290@mail.hallyn.com> 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 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() }