Commit 9d78edea authored by Alexey Gladkov's avatar Alexey Gladkov Committed by Eric W. Biederman

proc: proc_pid_ns takes super_block as an argument

syzbot found that

  touch /proc/testfile

causes NULL pointer dereference at tomoyo_get_local_path()
because inode of the dentry is NULL.

Before c59f415a, Tomoyo received pid_ns from proc's s_fs_info
directly. Since proc_pid_ns() can only work with inode, using it in
the tomoyo_get_local_path() was wrong.

To avoid creating more functions for getting proc_ns, change the
argument type of the proc_pid_ns() function. Then, Tomoyo can use
the existing super_block to get pid_ns.

Link: https://lkml.kernel.org/r/0000000000002f0c7505a5b0e04c@google.com
Link: https://lkml.kernel.org/r/20200518180738.2939611-1-gladkov.alexey@gmail.com
Reported-by: syzbot+c1af344512918c61362c@syzkaller.appspotmail.com
Fixes: c59f415a ("Use proc_pid_ns() to get pid_namespace from the proc superblock")
Signed-off-by: default avatarAlexey Gladkov <gladkov.alexey@gmail.com>
Signed-off-by: default avatarEric W. Biederman <ebiederm@xmission.com>
parent 2dd8083f
...@@ -2823,7 +2823,7 @@ static void lock_get_status(struct seq_file *f, struct file_lock *fl, ...@@ -2823,7 +2823,7 @@ static void lock_get_status(struct seq_file *f, struct file_lock *fl,
{ {
struct inode *inode = NULL; struct inode *inode = NULL;
unsigned int fl_pid; unsigned int fl_pid;
struct pid_namespace *proc_pidns = proc_pid_ns(file_inode(f->file)); struct pid_namespace *proc_pidns = proc_pid_ns(file_inode(f->file)->i_sb);
fl_pid = locks_translate_pid(fl, proc_pidns); fl_pid = locks_translate_pid(fl, proc_pidns);
/* /*
...@@ -2901,7 +2901,7 @@ static int locks_show(struct seq_file *f, void *v) ...@@ -2901,7 +2901,7 @@ static int locks_show(struct seq_file *f, void *v)
{ {
struct locks_iterator *iter = f->private; struct locks_iterator *iter = f->private;
struct file_lock *fl, *bfl; struct file_lock *fl, *bfl;
struct pid_namespace *proc_pidns = proc_pid_ns(file_inode(f->file)); struct pid_namespace *proc_pidns = proc_pid_ns(file_inode(f->file)->i_sb);
fl = hlist_entry(v, struct file_lock, fl_link); fl = hlist_entry(v, struct file_lock, fl_link);
......
...@@ -728,7 +728,7 @@ static int children_seq_show(struct seq_file *seq, void *v) ...@@ -728,7 +728,7 @@ static int children_seq_show(struct seq_file *seq, void *v)
{ {
struct inode *inode = file_inode(seq->file); struct inode *inode = file_inode(seq->file);
seq_printf(seq, "%d ", pid_nr_ns(v, proc_pid_ns(inode))); seq_printf(seq, "%d ", pid_nr_ns(v, proc_pid_ns(inode->i_sb)));
return 0; return 0;
} }
......
...@@ -754,7 +754,7 @@ static const struct inode_operations proc_def_inode_operations = { ...@@ -754,7 +754,7 @@ static const struct inode_operations proc_def_inode_operations = {
static int proc_single_show(struct seq_file *m, void *v) static int proc_single_show(struct seq_file *m, void *v)
{ {
struct inode *inode = m->private; struct inode *inode = m->private;
struct pid_namespace *ns = proc_pid_ns(inode); struct pid_namespace *ns = proc_pid_ns(inode->i_sb);
struct pid *pid = proc_pid(inode); struct pid *pid = proc_pid(inode);
struct task_struct *task; struct task_struct *task;
int ret; int ret;
...@@ -1423,7 +1423,7 @@ static const struct file_operations proc_fail_nth_operations = { ...@@ -1423,7 +1423,7 @@ static const struct file_operations proc_fail_nth_operations = {
static int sched_show(struct seq_file *m, void *v) static int sched_show(struct seq_file *m, void *v)
{ {
struct inode *inode = m->private; struct inode *inode = m->private;
struct pid_namespace *ns = proc_pid_ns(inode); struct pid_namespace *ns = proc_pid_ns(inode->i_sb);
struct task_struct *p; struct task_struct *p;
p = get_proc_task(inode); p = get_proc_task(inode);
...@@ -2466,7 +2466,7 @@ static int proc_timers_open(struct inode *inode, struct file *file) ...@@ -2466,7 +2466,7 @@ static int proc_timers_open(struct inode *inode, struct file *file)
return -ENOMEM; return -ENOMEM;
tp->pid = proc_pid(inode); tp->pid = proc_pid(inode);
tp->ns = proc_pid_ns(inode); tp->ns = proc_pid_ns(inode->i_sb);
return 0; return 0;
} }
...@@ -3377,7 +3377,7 @@ int proc_pid_readdir(struct file *file, struct dir_context *ctx) ...@@ -3377,7 +3377,7 @@ int proc_pid_readdir(struct file *file, struct dir_context *ctx)
{ {
struct tgid_iter iter; struct tgid_iter iter;
struct proc_fs_info *fs_info = proc_sb_info(file_inode(file)->i_sb); struct proc_fs_info *fs_info = proc_sb_info(file_inode(file)->i_sb);
struct pid_namespace *ns = proc_pid_ns(file_inode(file)); struct pid_namespace *ns = proc_pid_ns(file_inode(file)->i_sb);
loff_t pos = ctx->pos; loff_t pos = ctx->pos;
if (pos >= PID_MAX_LIMIT + TGID_OFFSET) if (pos >= PID_MAX_LIMIT + TGID_OFFSET)
...@@ -3730,7 +3730,7 @@ static int proc_task_readdir(struct file *file, struct dir_context *ctx) ...@@ -3730,7 +3730,7 @@ static int proc_task_readdir(struct file *file, struct dir_context *ctx)
/* f_version caches the tgid value that the last readdir call couldn't /* f_version caches the tgid value that the last readdir call couldn't
* return. lseek aka telldir automagically resets f_version to 0. * return. lseek aka telldir automagically resets f_version to 0.
*/ */
ns = proc_pid_ns(inode); ns = proc_pid_ns(inode->i_sb);
tid = (int)file->f_version; tid = (int)file->f_version;
file->f_version = 0; file->f_version = 0;
for (task = first_tid(proc_pid(inode), tid, ctx->pos - 2, ns); for (task = first_tid(proc_pid(inode), tid, ctx->pos - 2, ns);
......
...@@ -12,7 +12,7 @@ static const char *proc_self_get_link(struct dentry *dentry, ...@@ -12,7 +12,7 @@ static const char *proc_self_get_link(struct dentry *dentry,
struct inode *inode, struct inode *inode,
struct delayed_call *done) struct delayed_call *done)
{ {
struct pid_namespace *ns = proc_pid_ns(inode); struct pid_namespace *ns = proc_pid_ns(inode->i_sb);
pid_t tgid = task_tgid_nr_ns(current, ns); pid_t tgid = task_tgid_nr_ns(current, ns);
char *name; char *name;
......
...@@ -12,7 +12,7 @@ static const char *proc_thread_self_get_link(struct dentry *dentry, ...@@ -12,7 +12,7 @@ static const char *proc_thread_self_get_link(struct dentry *dentry,
struct inode *inode, struct inode *inode,
struct delayed_call *done) struct delayed_call *done)
{ {
struct pid_namespace *ns = proc_pid_ns(inode); struct pid_namespace *ns = proc_pid_ns(inode->i_sb);
pid_t tgid = task_tgid_nr_ns(current, ns); pid_t tgid = task_tgid_nr_ns(current, ns);
pid_t pid = task_pid_nr_ns(current, ns); pid_t pid = task_pid_nr_ns(current, ns);
char *name; char *name;
......
...@@ -202,9 +202,9 @@ int open_related_ns(struct ns_common *ns, ...@@ -202,9 +202,9 @@ int open_related_ns(struct ns_common *ns,
struct ns_common *(*get_ns)(struct ns_common *ns)); struct ns_common *(*get_ns)(struct ns_common *ns));
/* get the associated pid namespace for a file in procfs */ /* get the associated pid namespace for a file in procfs */
static inline struct pid_namespace *proc_pid_ns(const struct inode *inode) static inline struct pid_namespace *proc_pid_ns(struct super_block *sb)
{ {
return proc_sb_info(inode->i_sb)->pid_ns; return proc_sb_info(sb)->pid_ns;
} }
#endif /* _LINUX_PROC_FS_H */ #endif /* _LINUX_PROC_FS_H */
...@@ -1745,7 +1745,7 @@ static void pidfd_show_fdinfo(struct seq_file *m, struct file *f) ...@@ -1745,7 +1745,7 @@ static void pidfd_show_fdinfo(struct seq_file *m, struct file *f)
pid_t nr = -1; pid_t nr = -1;
if (likely(pid_has_task(pid, PIDTYPE_PID))) { if (likely(pid_has_task(pid, PIDTYPE_PID))) {
ns = proc_pid_ns(file_inode(m->file)); ns = proc_pid_ns(file_inode(m->file)->i_sb);
nr = pid_nr_ns(pid, ns); nr = pid_nr_ns(pid, ns);
} }
......
...@@ -779,7 +779,7 @@ static void *ip6fl_seq_start(struct seq_file *seq, loff_t *pos) ...@@ -779,7 +779,7 @@ static void *ip6fl_seq_start(struct seq_file *seq, loff_t *pos)
{ {
struct ip6fl_iter_state *state = ip6fl_seq_private(seq); struct ip6fl_iter_state *state = ip6fl_seq_private(seq);
state->pid_ns = proc_pid_ns(file_inode(seq->file)); state->pid_ns = proc_pid_ns(file_inode(seq->file)->i_sb);
rcu_read_lock_bh(); rcu_read_lock_bh();
return *pos ? ip6fl_get_idx(seq, *pos - 1) : SEQ_START_TOKEN; return *pos ? ip6fl_get_idx(seq, *pos - 1) : SEQ_START_TOKEN;
......
...@@ -162,7 +162,7 @@ static char *tomoyo_get_local_path(struct dentry *dentry, char * const buffer, ...@@ -162,7 +162,7 @@ static char *tomoyo_get_local_path(struct dentry *dentry, char * const buffer,
if (sb->s_magic == PROC_SUPER_MAGIC && *pos == '/') { if (sb->s_magic == PROC_SUPER_MAGIC && *pos == '/') {
char *ep; char *ep;
const pid_t pid = (pid_t) simple_strtoul(pos + 1, &ep, 10); const pid_t pid = (pid_t) simple_strtoul(pos + 1, &ep, 10);
struct pid_namespace *proc_pidns = proc_pid_ns(d_inode(dentry)); struct pid_namespace *proc_pidns = proc_pid_ns(sb);
if (*ep == '/' && pid && pid == if (*ep == '/' && pid && pid ==
task_tgid_nr_ns(current, proc_pidns)) { task_tgid_nr_ns(current, proc_pidns)) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment