]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
procfs: make /self and /thread_self dentries persistent
authorAl Viro <viro@zeniv.linux.org.uk>
Mon, 26 Feb 2024 06:55:36 +0000 (01:55 -0500)
committerAl Viro <viro@zeniv.linux.org.uk>
Sun, 16 Nov 2025 06:35:02 +0000 (01:35 -0500)
... and there's no need to remember those pointers anywhere - ->kill_sb()
no longer needs to bother since kill_anon_super() will take care of
them anyway and proc_pid_readdir() only wants the inumbers, which
we had in a couple of static variables all along.

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
fs/proc/base.c
fs/proc/internal.h
fs/proc/root.c
fs/proc/self.c
fs/proc/thread_self.c
include/linux/proc_fs.h

index 6299878e3d97e6ee07489c5a4dd09ee638c05c82..869677a26332dba9962172914c1de7996fe49c76 100644 (file)
@@ -3585,14 +3585,12 @@ int proc_pid_readdir(struct file *file, struct dir_context *ctx)
                return 0;
 
        if (pos == TGID_OFFSET - 2) {
-               struct inode *inode = d_inode(fs_info->proc_self);
-               if (!dir_emit(ctx, "self", 4, inode->i_ino, DT_LNK))
+               if (!dir_emit(ctx, "self", 4, self_inum, DT_LNK))
                        return 0;
                ctx->pos = pos = pos + 1;
        }
        if (pos == TGID_OFFSET - 1) {
-               struct inode *inode = d_inode(fs_info->proc_thread_self);
-               if (!dir_emit(ctx, "thread-self", 11, inode->i_ino, DT_LNK))
+               if (!dir_emit(ctx, "thread-self", 11, thread_self_inum, DT_LNK))
                        return 0;
                ctx->pos = pos = pos + 1;
        }
index d1598576506c1e7b161e0967027ab361cfb0313f..c1e8eb984da817086b609bfdba084e7d59b5c3ef 100644 (file)
@@ -373,6 +373,7 @@ static inline void proc_tty_init(void) {}
 extern struct proc_dir_entry proc_root;
 
 extern void proc_self_init(void);
+extern unsigned self_inum, thread_self_inum;
 
 /*
  * task_[no]mmu.c
index 1e24e085c7d5a191148064fa68301d9acd0fc43e..d8ca41d823e440b03de1dd25fb3807da4b46a2ed 100644 (file)
@@ -347,17 +347,11 @@ static void proc_kill_sb(struct super_block *sb)
 {
        struct proc_fs_info *fs_info = proc_sb_info(sb);
 
-       if (!fs_info) {
-               kill_anon_super(sb);
-               return;
-       }
-
-       dput(fs_info->proc_self);
-       dput(fs_info->proc_thread_self);
-
        kill_anon_super(sb);
-       put_pid_ns(fs_info->pid_ns);
-       kfree_rcu(fs_info, rcu);
+       if (fs_info) {
+               put_pid_ns(fs_info->pid_ns);
+               kfree_rcu(fs_info, rcu);
+       }
 }
 
 static struct file_system_type proc_fs_type = {
index b46fbfd226811f09f9bff408340b63ed2fc375ed..62d2c0cfe35c58b9ab3d6a603984aff2c0bdbb4e 100644 (file)
@@ -31,12 +31,11 @@ static const struct inode_operations proc_self_inode_operations = {
        .get_link       = proc_self_get_link,
 };
 
-static unsigned self_inum __ro_after_init;
+unsigned self_inum __ro_after_init;
 
 int proc_setup_self(struct super_block *s)
 {
        struct inode *root_inode = d_inode(s->s_root);
-       struct proc_fs_info *fs_info = proc_sb_info(s);
        struct dentry *self;
        int ret = -ENOMEM;
 
@@ -51,18 +50,15 @@ int proc_setup_self(struct super_block *s)
                        inode->i_uid = GLOBAL_ROOT_UID;
                        inode->i_gid = GLOBAL_ROOT_GID;
                        inode->i_op = &proc_self_inode_operations;
-                       d_add(self, inode);
+                       d_make_persistent(self, inode);
                        ret = 0;
-               } else {
-                       dput(self);
                }
+               dput(self);
        }
        inode_unlock(root_inode);
 
        if (ret)
                pr_err("proc_fill_super: can't allocate /proc/self\n");
-       else
-               fs_info->proc_self = self;
 
        return ret;
 }
index 0e5050d6ab64729a20da80e95e62529dde821069..d6113dbe58e059e10c7dd93eecc40e06f3afec39 100644 (file)
@@ -31,12 +31,11 @@ static const struct inode_operations proc_thread_self_inode_operations = {
        .get_link       = proc_thread_self_get_link,
 };
 
-static unsigned thread_self_inum __ro_after_init;
+unsigned thread_self_inum __ro_after_init;
 
 int proc_setup_thread_self(struct super_block *s)
 {
        struct inode *root_inode = d_inode(s->s_root);
-       struct proc_fs_info *fs_info = proc_sb_info(s);
        struct dentry *thread_self;
        int ret = -ENOMEM;
 
@@ -51,19 +50,15 @@ int proc_setup_thread_self(struct super_block *s)
                        inode->i_uid = GLOBAL_ROOT_UID;
                        inode->i_gid = GLOBAL_ROOT_GID;
                        inode->i_op = &proc_thread_self_inode_operations;
-                       d_add(thread_self, inode);
+                       d_make_persistent(thread_self, inode);
                        ret = 0;
-               } else {
-                       dput(thread_self);
                }
+               dput(thread_self);
        }
        inode_unlock(root_inode);
 
        if (ret)
                pr_err("proc_fill_super: can't allocate /proc/thread-self\n");
-       else
-               fs_info->proc_thread_self = thread_self;
-
        return ret;
 }
 
index f139377f4b319c9d839943ae3d53bc28f250889d..19d1c5e5f335016a43ec3dfd90bf8936377e5c68 100644 (file)
@@ -66,8 +66,6 @@ enum proc_pidonly {
 
 struct proc_fs_info {
        struct pid_namespace *pid_ns;
-       struct dentry *proc_self;        /* For /proc/self */
-       struct dentry *proc_thread_self; /* For /proc/thread-self */
        kgid_t pid_gid;
        enum proc_hidepid hide_pid;
        enum proc_pidonly pidonly;