From: Ye Bin <yebin@huaweicloud.com>
To: tytso@mit.edu, adilger.kernel@dilger.ca, linux-ext4@vger.kernel.org
Cc: jack@suse.cz
Subject: [PATCH v2 1/4] ext4: register 'orphan_list' procfs
Date: Wed, 15 Apr 2026 18:55:02 +0800 [thread overview]
Message-ID: <20260415105505.342358-2-yebin@huaweicloud.com> (raw)
In-Reply-To: <20260415105505.342358-1-yebin@huaweicloud.com>
From: Ye Bin <yebin10@huawei.com>
This patch register '/proc/fs/ext4/XXX/orphan_list' procfs for show inode
orphan list about EXT4 file system.
In actual production environments, there may be inconsistencies in df/du,
sometimes due to kernel occupation, making it difficult to find such files,
and it is also difficult to operate in the current network environment. So
add "orphan_list" procfs to quickly query files that have been deleted but
are occupied.
Signed-off-by: Ye Bin <yebin10@huawei.com>
---
fs/ext4/ext4.h | 1 +
fs/ext4/orphan.c | 77 ++++++++++++++++++++++++++++++++++++++++++++++++
fs/ext4/sysfs.c | 2 ++
3 files changed, 80 insertions(+)
diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
index 0cf68f85dfd1..ccb0fd1e63e7 100644
--- a/fs/ext4/ext4.h
+++ b/fs/ext4/ext4.h
@@ -3875,6 +3875,7 @@ extern void ext4_stop_mmpd(struct ext4_sb_info *sbi);
extern const struct fsverity_operations ext4_verityops;
/* orphan.c */
+extern const struct proc_ops ext4_orphan_proc_ops;
extern int ext4_orphan_add(handle_t *, struct inode *);
extern int ext4_orphan_del(handle_t *, struct inode *);
extern void ext4_orphan_cleanup(struct super_block *sb,
diff --git a/fs/ext4/orphan.c b/fs/ext4/orphan.c
index 64ea47624233..f7e7f77e021e 100644
--- a/fs/ext4/orphan.c
+++ b/fs/ext4/orphan.c
@@ -4,6 +4,8 @@
#include <linux/fs.h>
#include <linux/quotaops.h>
#include <linux/buffer_head.h>
+#include <linux/proc_fs.h>
+#include <linux/seq_file.h>
#include "ext4.h"
#include "ext4_jbd2.h"
@@ -657,3 +659,78 @@ int ext4_orphan_file_empty(struct super_block *sb)
return 0;
return 1;
}
+
+struct ext4_proc_orphan {
+ struct ext4_inode_info cursor;
+};
+
+static void *ext4_orphan_seq_start(struct seq_file *seq, loff_t *pos)
+{
+ return NULL;
+}
+
+static void *ext4_orphan_seq_next(struct seq_file *seq, void *v, loff_t *pos)
+{
+ return NULL;
+}
+
+static int ext4_orphan_seq_show(struct seq_file *seq, void *v)
+{
+ return 0;
+}
+
+static void ext4_orphan_seq_stop(struct seq_file *seq, void *v)
+{
+}
+
+const struct seq_operations ext4_orphan_seq_ops = {
+ .start = ext4_orphan_seq_start,
+ .next = ext4_orphan_seq_next,
+ .stop = ext4_orphan_seq_stop,
+ .show = ext4_orphan_seq_show,
+};
+
+static int ext4_seq_orphan_open(struct inode *inode, struct file *file)
+{
+ int rc;
+ struct seq_file *m;
+ struct ext4_proc_orphan *private;
+
+ rc = seq_open_private(file, &ext4_orphan_seq_ops,
+ sizeof(struct ext4_proc_orphan));
+ if (!rc) {
+ m = file->private_data;
+ private = m->private;
+ INIT_LIST_HEAD(&private->cursor.i_orphan);
+ private->cursor.vfs_inode.i_ino = 0;
+ }
+
+ return rc;
+}
+
+static int ext4_seq_orphan_release(struct inode *inode, struct file *file)
+{
+ struct seq_file *seq = file->private_data;
+ struct ext4_proc_orphan *s = seq->private;
+ struct ext4_sb_info *sbi = EXT4_SB(pde_data(inode));
+
+ /*
+ * The function close_pdeo() is called when deleting the procfs
+ * in ext4_unregister_sysfs(), and this function is used to remove
+ * the entry from the 'pde->pde_openers' list. Therefore, when the
+ * file is closed, proc_reg_release() will not call close_pdeo()
+ * again because it cannot find the node on the 'pde->pde_openers'
+ * list. This prevents the UAF issue from occurring.
+ */
+ mutex_lock(&sbi->s_orphan_lock);
+ list_del(&s->cursor.i_orphan);
+ mutex_unlock(&sbi->s_orphan_lock);
+
+ return seq_release_private(inode, file);
+}
+
+const struct proc_ops ext4_orphan_proc_ops = {
+ .proc_open = ext4_seq_orphan_open,
+ .proc_read = seq_read,
+ .proc_release = ext4_seq_orphan_release,
+};
diff --git a/fs/ext4/sysfs.c b/fs/ext4/sysfs.c
index 923b375e017f..b40a934e30c9 100644
--- a/fs/ext4/sysfs.c
+++ b/fs/ext4/sysfs.c
@@ -639,6 +639,8 @@ int ext4_register_sysfs(struct super_block *sb)
ext4_seq_mb_stats_show, sb);
proc_create_seq_data("mb_structs_summary", 0444, sbi->s_proc,
&ext4_mb_seq_structs_summary_ops, sb);
+ proc_create_data("orphan_list", 0400, sbi->s_proc,
+ &ext4_orphan_proc_ops, sb);
}
return 0;
}
--
2.34.1
next prev parent reply other threads:[~2026-04-15 10:57 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-15 10:55 [PATCH v2 0/4] show orphan file inode detail info Ye Bin
2026-04-15 10:55 ` Ye Bin [this message]
2026-04-15 10:55 ` [PATCH v2 2/4] ext4: skip cursor node in ext4_orphan_del() Ye Bin
2026-04-15 23:56 ` Darrick J. Wong
2026-04-15 10:55 ` [PATCH v2 3/4] ext4: show inode orphan list detail information Ye Bin
2026-04-15 10:55 ` [PATCH v2 4/4] ext4: show orphan file inode detail info Ye Bin
2026-04-15 17:59 ` [PATCH v2 0/4] " Jan Kara
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=20260415105505.342358-2-yebin@huaweicloud.com \
--to=yebin@huaweicloud.com \
--cc=adilger.kernel@dilger.ca \
--cc=jack@suse.cz \
--cc=linux-ext4@vger.kernel.org \
--cc=tytso@mit.edu \
/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