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]
Message-ID: <20241108204102.1752206-2-stsp2@yandex.ru>
Date: Fri,  8 Nov 2024 23:41:01 +0300
From: Stas Sergeev <stsp2@...dex.ru>
To: linux-kernel@...r.kernel.org
Cc: Stas Sergeev <stsp2@...dex.ru>,
	Eric Biederman <ebiederm@...ssion.com>,
	Andy Lutomirski <luto@...nel.org>,
	Aleksa Sarai <cyphar@...har.com>,
	Alexander Viro <viro@...iv.linux.org.uk>,
	Christian Brauner <brauner@...nel.org>,
	Jan Kara <jack@...e.cz>,
	Thomas Gleixner <tglx@...utronix.de>,
	Jeff Layton <jlayton@...nel.org>,
	John Johansen <john.johansen@...onical.com>,
	Chengming Zhou <chengming.zhou@...ux.dev>,
	Casey Schaufler <casey@...aufler-ca.com>,
	Adrian Ratiu <adrian.ratiu@...labora.com>,
	Felix Moessbauer <felix.moessbauer@...mens.com>,
	Jens Axboe <axboe@...nel.dk>,
	Oleg Nesterov <oleg@...hat.com>,
	"Serge E. Hallyn" <serge@...lyn.com>,
	Kees Cook <kees@...nel.org>,
	linux-fsdevel@...r.kernel.org,
	"Peter Zijlstra (Intel)" <peterz@...radead.org>
Subject: [PATCH v3 1/2] procfs: avoid some usages of seq_file private data

seq_file private data carries the inode pointer here.
Replace
`struct inode *inode = m->private;`
with:
`struct inode *inode = file_inode(m->file);`
to avoid the reliance on private data.

This is needed so that `proc_single_show()` can be used by
custom fops that utilize seq_file private data for other things.
This is used in the next patch.

The private data argument of corresponding single_open() calls
is NULLified.
Note that timens_offsets_show() already had `file_inode(m->file)`
so the NULLification in `timens_offsets_open()` is unpaired.

Signed-off-by: Stas Sergeev <stsp2@...dex.ru>

CC: Eric Biederman <ebiederm@...ssion.com>
CC: Andy Lutomirski <luto@...nel.org>
CC: Aleksa Sarai <cyphar@...har.com>
CC: Christian Brauner <brauner@...nel.org>
CC: Thomas Gleixner <tglx@...utronix.de>
CC: Jeff Layton <jlayton@...nel.org>
CC: Kees Cook <kees@...nel.org>
CC: "Peter Zijlstra (Intel)" <peterz@...radead.org>
CC: Al Viro <viro@...iv.linux.org.uk>
CC: Felix Moessbauer <felix.moessbauer@...mens.com>
CC: Adrian Ratiu <adrian.ratiu@...labora.com>
CC: Casey Schaufler <casey@...aufler-ca.com>
CC: linux-kernel@...r.kernel.org
CC: linux-fsdevel@...r.kernel.org
CC: Jan Kara <jack@...e.cz>
CC: Chengming Zhou <chengming.zhou@...ux.dev>
CC: Jens Axboe <axboe@...nel.dk>
CC: Oleg Nesterov <oleg@...hat.com>
Cc: "Serge E. Hallyn" <serge@...lyn.com>
---
 fs/proc/base.c | 34 +++++++++++++---------------------
 1 file changed, 13 insertions(+), 21 deletions(-)

diff --git a/fs/proc/base.c b/fs/proc/base.c
index b31283d81c52..e7c8554ec95a 100644
--- a/fs/proc/base.c
+++ b/fs/proc/base.c
@@ -528,7 +528,7 @@ static int proc_pid_schedstat(struct seq_file *m, struct pid_namespace *ns,
 static int lstats_show_proc(struct seq_file *m, void *v)
 {
 	int i;
-	struct inode *inode = m->private;
+	struct inode *inode = file_inode(m->file);
 	struct task_struct *task = get_proc_task(inode);
 
 	if (!task)
@@ -557,7 +557,7 @@ static int lstats_show_proc(struct seq_file *m, void *v)
 
 static int lstats_open(struct inode *inode, struct file *file)
 {
-	return single_open(file, lstats_show_proc, inode);
+	return single_open(file, lstats_show_proc, NULL);
 }
 
 static ssize_t lstats_write(struct file *file, const char __user *buf,
@@ -800,7 +800,7 @@ static const struct inode_operations proc_def_inode_operations = {
 
 static int proc_single_show(struct seq_file *m, void *v)
 {
-	struct inode *inode = m->private;
+	struct inode *inode = file_inode(m->file);
 	struct pid_namespace *ns = proc_pid_ns(inode->i_sb);
 	struct pid *pid = proc_pid(inode);
 	struct task_struct *task;
@@ -818,7 +818,7 @@ static int proc_single_show(struct seq_file *m, void *v)
 
 static int proc_single_open(struct inode *inode, struct file *filp)
 {
-	return single_open(filp, proc_single_show, inode);
+	return single_open(filp, proc_single_show, NULL);
 }
 
 static const struct file_operations proc_single_file_operations = {
@@ -1494,7 +1494,7 @@ static const struct file_operations proc_fail_nth_operations = {
  */
 static int sched_show(struct seq_file *m, void *v)
 {
-	struct inode *inode = m->private;
+	struct inode *inode = file_inode(m->file);
 	struct pid_namespace *ns = proc_pid_ns(inode->i_sb);
 	struct task_struct *p;
 
@@ -1527,7 +1527,7 @@ sched_write(struct file *file, const char __user *buf,
 
 static int sched_open(struct inode *inode, struct file *filp)
 {
-	return single_open(filp, sched_show, inode);
+	return single_open(filp, sched_show, NULL);
 }
 
 static const struct file_operations proc_pid_sched_operations = {
@@ -1546,7 +1546,7 @@ static const struct file_operations proc_pid_sched_operations = {
  */
 static int sched_autogroup_show(struct seq_file *m, void *v)
 {
-	struct inode *inode = m->private;
+	struct inode *inode = file_inode(m->file);
 	struct task_struct *p;
 
 	p = get_proc_task(inode);
@@ -1593,15 +1593,7 @@ sched_autogroup_write(struct file *file, const char __user *buf,
 
 static int sched_autogroup_open(struct inode *inode, struct file *filp)
 {
-	int ret;
-
-	ret = single_open(filp, sched_autogroup_show, NULL);
-	if (!ret) {
-		struct seq_file *m = filp->private_data;
-
-		m->private = inode;
-	}
-	return ret;
+	return single_open(filp, sched_autogroup_show, NULL);
 }
 
 static const struct file_operations proc_pid_sched_autogroup_operations = {
@@ -1704,7 +1696,7 @@ static ssize_t timens_offsets_write(struct file *file, const char __user *buf,
 
 static int timens_offsets_open(struct inode *inode, struct file *filp)
 {
-	return single_open(filp, timens_offsets_show, inode);
+	return single_open(filp, timens_offsets_show, NULL);
 }
 
 static const struct file_operations proc_timens_offsets_operations = {
@@ -1745,7 +1737,7 @@ static ssize_t comm_write(struct file *file, const char __user *buf,
 
 static int comm_show(struct seq_file *m, void *v)
 {
-	struct inode *inode = m->private;
+	struct inode *inode = file_inode(m->file);
 	struct task_struct *p;
 
 	p = get_proc_task(inode);
@@ -1762,7 +1754,7 @@ static int comm_show(struct seq_file *m, void *v)
 
 static int comm_open(struct inode *inode, struct file *filp)
 {
-	return single_open(filp, comm_show, inode);
+	return single_open(filp, comm_show, NULL);
 }
 
 static const struct file_operations proc_pid_set_comm_operations = {
@@ -2641,7 +2633,7 @@ static ssize_t timerslack_ns_write(struct file *file, const char __user *buf,
 
 static int timerslack_ns_show(struct seq_file *m, void *v)
 {
-	struct inode *inode = m->private;
+	struct inode *inode = file_inode(m->file);
 	struct task_struct *p;
 	int err = 0;
 
@@ -2675,7 +2667,7 @@ static int timerslack_ns_show(struct seq_file *m, void *v)
 
 static int timerslack_ns_open(struct inode *inode, struct file *filp)
 {
-	return single_open(filp, timerslack_ns_show, inode);
+	return single_open(filp, timerslack_ns_show, NULL);
 }
 
 static const struct file_operations proc_pid_set_timerslack_ns_operations = {
-- 
2.47.0


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ