linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Paul Moore <paul@paul-moore.com>
To: Al Viro <viro@zeniv.linux.org.uk>
Cc: linux-fsdevel@vger.kernel.org, torvalds@linux-foundation.org,
	 brauner@kernel.org, jack@suse.cz, raven@themaw.net,
	miklos@szeredi.hu,  a.hindborg@kernel.org, linux-mm@kvack.org,
	linux-efi@vger.kernel.org,  ocfs2-devel@lists.linux.dev,
	kees@kernel.org, rostedt@goodmis.org,
	 gregkh@linuxfoundation.org, linux-usb@vger.kernel.org,
	casey@schaufler-ca.com,  linuxppc-dev@lists.ozlabs.org,
	borntraeger@linux.ibm.com
Subject: Re: [PATCH 31/39] convert selinuxfs
Date: Sun, 21 Sep 2025 22:50:02 -0400	[thread overview]
Message-ID: <CAHC9VhTy2j+hkT24hM1J2GH+12wp63DArRo6BGTvTwGX2k4CnA@mail.gmail.com> (raw)
In-Reply-To: <20250921222619.GO39973@ZenIV>

On Sun, Sep 21, 2025 at 6:26 PM Al Viro <viro@zeniv.linux.org.uk> wrote:
> On Sun, Sep 21, 2025 at 04:44:28PM -0400, Paul Moore wrote:
> > On Sat, Sep 20, 2025 at 3:48 AM Al Viro <viro@zeniv.linux.org.uk> wrote:
> > >
> > > Tree has invariant part + two subtrees that get replaced upon each
> > > policy load.  Invariant parts stay for the lifetime of filesystem,
> > > these two subdirs - from policy load to policy load (serialized
> > > on lock_rename(root, ...)).
> > >
> > > All object creations are via d_alloc_name()+d_add() inside selinuxfs,
> > > all removals are via simple_recursive_removal().
> > >
> > > Turn those d_add() into d_make_persistent()+dput() and that's mostly it.
> > > Don't bother to store the dentry of /policy_capabilities - it belongs
> > > to invariant part of tree and we only use it to populate that directory,
> > > so there's no reason to keep it around afterwards.
> >
> > Minor comment on that below, as well as a comment style nitpick, but
> > overall no major concerns from me.
>
> FWIW, how's this for the preparatory part?
>
> commit 17f3b70a28233078dd3dae3cf773b68fcd899950
> Author: Al Viro <viro@zeniv.linux.org.uk>
> Date:   Sun Sep 21 18:09:48 2025 -0400
>
>     selinuxfs: don't stash the dentry of /policy_capabilities
>
>     Don't bother to store the dentry of /policy_capabilities - it belongs
>     to invariant part of tree and we only use it to populate that directory,
>     so there's no reason to keep it around afterwards.
>
>     Same situation as with /avc, /ss, etc.  There are two directories that
>     get replaced on policy load - /class and /booleans.  These we need to
>     stash (and update the pointers on policy reload); /policy_capabilities
>     is not in the same boat.
>
>     Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>

Looks good to me, ACK below.  For me personally, it's a bit late to
take non-bugfix stuff for the upcoming merge window so I would defer
this for a few weeks, but if you want to take it now that's your call.
Also your call if you would prefer this to go in with the rest of the
patchset you've working on, or if you want me to take it via the
SELinux tree.  Let me know.

Acked-by: Paul Moore <paul@paul-moore.com>

> diff --git a/security/selinux/selinuxfs.c b/security/selinux/selinuxfs.c
> index 9aa1d03ab612..482a2cac9640 100644
> --- a/security/selinux/selinuxfs.c
> +++ b/security/selinux/selinuxfs.c
> @@ -75,7 +75,6 @@ struct selinux_fs_info {
>         struct dentry *class_dir;
>         unsigned long last_class_ino;
>         bool policy_opened;
> -       struct dentry *policycap_dir;
>         unsigned long last_ino;
>         struct super_block *sb;
>  };
> @@ -117,7 +116,6 @@ static void selinux_fs_info_free(struct super_block *sb)
>
>  #define BOOL_DIR_NAME "booleans"
>  #define CLASS_DIR_NAME "class"
> -#define POLICYCAP_DIR_NAME "policy_capabilities"
>
>  #define TMPBUFLEN      12
>  static ssize_t sel_read_enforce(struct file *filp, char __user *buf,
> @@ -1879,23 +1877,24 @@ static int sel_make_classes(struct selinux_policy *newpolicy,
>         return rc;
>  }
>
> -static int sel_make_policycap(struct selinux_fs_info *fsi)
> +static int sel_make_policycap(struct dentry *dir)
>  {
> +       struct super_block *sb = dir->d_sb;
>         unsigned int iter;
>         struct dentry *dentry = NULL;
>         struct inode *inode = NULL;
>
>         for (iter = 0; iter <= POLICYDB_CAP_MAX; iter++) {
>                 if (iter < ARRAY_SIZE(selinux_policycap_names))
> -                       dentry = d_alloc_name(fsi->policycap_dir,
> +                       dentry = d_alloc_name(dir,
>                                               selinux_policycap_names[iter]);
>                 else
> -                       dentry = d_alloc_name(fsi->policycap_dir, "unknown");
> +                       dentry = d_alloc_name(dir, "unknown");
>
>                 if (dentry == NULL)
>                         return -ENOMEM;
>
> -               inode = sel_make_inode(fsi->sb, S_IFREG | 0444);
> +               inode = sel_make_inode(sb, S_IFREG | 0444);
>                 if (inode == NULL) {
>                         dput(dentry);
>                         return -ENOMEM;
> @@ -2079,15 +2078,13 @@ static int sel_fill_super(struct super_block *sb, struct fs_context *fc)
>                 goto err;
>         }
>
> -       fsi->policycap_dir = sel_make_dir(sb->s_root, POLICYCAP_DIR_NAME,
> -                                         &fsi->last_ino);
> -       if (IS_ERR(fsi->policycap_dir)) {
> -               ret = PTR_ERR(fsi->policycap_dir);
> -               fsi->policycap_dir = NULL;
> +       dentry = sel_make_dir(sb->s_root, "policy_capabilities", &fsi->last_ino);
> +       if (IS_ERR(dentry)) {
> +               ret = PTR_ERR(dentry);
>                 goto err;
>         }
>
> -       ret = sel_make_policycap(fsi);
> +       ret = sel_make_policycap(dentry);
>         if (ret) {
>                 pr_err("SELinux: failed to load policy capabilities\n");
>                 goto err;

-- 
paul-moore.com


  reply	other threads:[~2025-09-22  2:50 UTC|newest]

Thread overview: 50+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-09-20  7:41 [PATCHES][RFC] the meat of tree-in-dcache series Al Viro
2025-09-20  7:47 ` [PATCH 01/39] new helper: simple_remove_by_name() Al Viro
2025-09-20  7:47   ` [PATCH 02/39] new helper: simple_done_creating() Al Viro
2025-09-20  7:47   ` [PATCH 03/39] introduce a flag for explicitly marking persistently pinned dentries Al Viro
2025-09-20  7:47   ` [PATCH 04/39] primitives for maintaining persisitency Al Viro
2025-09-20  7:47   ` [PATCH 05/39] convert simple_{link,unlink,rmdir,rename,fill_super}() to new primitives Al Viro
2025-09-20  7:47   ` [PATCH 06/39] convert ramfs and tmpfs Al Viro
2025-09-20  7:47   ` [PATCH 07/39] procfs: make /self and /thread_self dentries persistent Al Viro
2025-09-20  7:47   ` [PATCH 08/39] configfs, securityfs: kill_litter_super() not needed Al Viro
2025-09-24 16:56     ` Joel Becker
2025-09-20  7:47   ` [PATCH 09/39] convert xenfs Al Viro
2025-09-20  7:47   ` [PATCH 10/39] convert smackfs Al Viro
2025-09-22 15:11     ` Casey Schaufler
2025-09-20  7:47   ` [PATCH 11/39] convert hugetlbfs Al Viro
2025-09-20  7:47   ` [PATCH 12/39] convert mqueue Al Viro
2025-09-20  7:47   ` [PATCH 13/39] convert bpf Al Viro
2025-09-20  7:47   ` [PATCH 14/39] convert dlmfs Al Viro
2025-09-20  7:47   ` [PATCH 15/39] convert fuse_ctl Al Viro
2025-09-20  7:47   ` [PATCH 16/39] convert pstore Al Viro
2025-09-20  7:47   ` [PATCH 17/39] convert tracefs Al Viro
2025-09-20  7:47   ` [PATCH 18/39] convert debugfs Al Viro
2025-09-23  8:10     ` Greg KH
2025-09-20  7:47   ` [PATCH 19/39] debugfs: remove duplicate checks in callers of start_creating() Al Viro
2025-09-23  8:10     ` Greg KH
2025-09-20  7:47   ` [PATCH 20/39] convert efivarfs Al Viro
2025-09-20  7:47   ` [PATCH 21/39] convert spufs Al Viro
2025-09-20  7:47   ` [PATCH 22/39] convert ibmasmfs Al Viro
2025-09-20  7:47   ` [PATCH 23/39] ibmasmfs: get rid of ibmasmfs_dir_ops Al Viro
2025-09-20  7:47   ` [PATCH 24/39] convert devpts Al Viro
2025-09-20  7:47   ` [PATCH 25/39] binderfs: use simple_start_creating() Al Viro
2025-09-20  7:47   ` [PATCH 26/39] binderfs_binder_ctl_create(): kill a bogus check Al Viro
2025-09-20  7:47   ` [PATCH 27/39] convert binderfs Al Viro
2025-09-20  7:47   ` [PATCH 28/39] autofs_{rmdir,unlink}: dentry->d_fsdata->dentry == dentry there Al Viro
2025-09-20  7:47   ` [PATCH 29/39] convert autofs Al Viro
2025-09-20  7:47   ` [PATCH 30/39] convert binfmt_misc Al Viro
2025-09-20  7:47   ` [PATCH 31/39] convert selinuxfs Al Viro
2025-09-21 20:44     ` Paul Moore
2025-09-21 22:26       ` Al Viro
2025-09-22  2:50         ` Paul Moore [this message]
2025-09-22  3:52           ` Al Viro
2025-09-20  7:47   ` [PATCH 32/39] functionfs: switch to simple_remove_by_name() Al Viro
2025-09-20  7:47   ` [PATCH 33/39] convert functionfs Al Viro
2025-09-20  7:47   ` [PATCH 34/39] gadgetfs: switch to simple_remove_by_name() Al Viro
2025-09-20  7:47   ` [PATCH 35/39] convert gadgetfs Al Viro
2025-09-20  7:47   ` [PATCH 36/39] hypfs: don't pin dentries twice Al Viro
2025-09-20  7:47   ` [PATCH 37/39] hypfs: switch hypfs_create_str() to returning int Al Viro
2025-09-20  7:47   ` [PATCH 38/39] hypfs: swich hypfs_create_u64() " Al Viro
2025-09-20  7:47   ` [PATCH 39/39] convert hypfs Al Viro
2025-09-20 16:26 ` [PATCHES][RFC] the meat of tree-in-dcache series Linus Torvalds
2025-09-20 18:09   ` Al Viro

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAHC9VhTy2j+hkT24hM1J2GH+12wp63DArRo6BGTvTwGX2k4CnA@mail.gmail.com \
    --to=paul@paul-moore.com \
    --cc=a.hindborg@kernel.org \
    --cc=borntraeger@linux.ibm.com \
    --cc=brauner@kernel.org \
    --cc=casey@schaufler-ca.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=jack@suse.cz \
    --cc=kees@kernel.org \
    --cc=linux-efi@vger.kernel.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=linuxppc-dev@lists.ozlabs.org \
    --cc=miklos@szeredi.hu \
    --cc=ocfs2-devel@lists.linux.dev \
    --cc=raven@themaw.net \
    --cc=rostedt@goodmis.org \
    --cc=torvalds@linux-foundation.org \
    --cc=viro@zeniv.linux.org.uk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox