lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:   Tue, 10 May 2022 17:51:07 +0200
From:   Christian Brauner <brauner@...nel.org>
To:     "Serge E. Hallyn" <serge@...lyn.com>
Cc:     Stefan Berger <stefanb@...ux.ibm.com>,
        linux-integrity@...r.kernel.org, zohar@...ux.ibm.com,
        christian.brauner@...ntu.com, containers@...ts.linux.dev,
        dmitry.kasatkin@...il.com, ebiederm@...ssion.com,
        krzysztof.struczynski@...wei.com, roberto.sassu@...wei.com,
        mpeters@...hat.com, lhinds@...hat.com, lsturman@...hat.com,
        puiterwi@...hat.com, jejb@...ux.ibm.com, jamjoom@...ibm.com,
        linux-kernel@...r.kernel.org, paul@...l-moore.com, rgb@...hat.com,
        linux-security-module@...r.kernel.org, jmorris@...ei.org,
        jpenumak@...hat.com, John Johansen <john.johansen@...onical.com>,
        Matthew Garrett <mjg59@...f.ucam.org>,
        Micah Morton <mortonm@...omium.org>,
        Kentaro Takeda <takedakn@...data.co.jp>,
        Jarkko Sakkinen <jarkko@...nel.org>
Subject: Re: [PATCH v12 01/26] securityfs: rework dentry creation

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 <brauner@...nel.org>
> > > > 
> > > > 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()
  }

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ