History

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 c59f415a7cb6, 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.

Alexey Gladkov committed 6 years ago

Commit 9d78ede1 parent 2dd80839 files · +15 −15Browse files

Unified · Split

9 files
  1. fs/locks.c +2 −2
  2. fs/proc/array.c +1 −1
  3. fs/proc/base.c +5 −5
  4. fs/proc/self.c +1 −1
  5. fs/proc/thread_self.c +1 −1
  6. include/linux/proc_fs.h +2 −2
  7. kernel/fork.c +1 −1
  8. net/ipv6/ip6_flowlabel.c +1 −1
  9. security/tomoyo/realpath.c +1 −1
fs/locks.c+2−2
@@ -2823,7 +2823,7 @@ static void lock_get_status(struct seq_file *f, struct file_lock *fl, · 2822 unmodified lines
28232823 {
28242824 struct inode *inode = NULL;
28252825 unsigned int fl_pid;
2826− struct pid_namespace *proc_pidns = proc_pid_ns(file_inode(f->file));
2826+ struct pid_namespace *proc_pidns = proc_pid_ns(file_inode(f->file)->i_sb);
28272827
28282828 fl_pid = locks_translate_pid(fl, proc_pidns);
28292829 /*
@@ -2901,7 +2901,7 @@ static int locks_show(struct seq_file *f, void *v) · 71 unmodified lines
29012901 {
29022902 struct locks_iterator *iter = f->private;
29032903 struct file_lock *fl, *bfl;
2904− struct pid_namespace *proc_pidns = proc_pid_ns(file_inode(f->file));
2904+ struct pid_namespace *proc_pidns = proc_pid_ns(file_inode(f->file)->i_sb);
29052905
29062906 fl = hlist_entry(v, struct file_lock, fl_link);
29072907
fs/proc/array.c+1−1
@@ -728,7 +728,7 @@ static int children_seq_show(struct seq_file *seq, void *v) · 727 unmodified lines
728728 {
729729 struct inode *inode = file_inode(seq->file);
730730
731− seq_printf(seq, "%d ", pid_nr_ns(v, proc_pid_ns(inode)));
731+ seq_printf(seq, "%d ", pid_nr_ns(v, proc_pid_ns(inode->i_sb)));
732732 return 0;
733733 }
734734
fs/proc/base.c+5−5
@@ -754,7 +754,7 @@ static const struct inode_operations proc_def_inode_operations = { · 753 unmodified lines
754754 static int proc_single_show(struct seq_file *m, void *v)
755755 {
756756 struct inode *inode = m->private;
757− struct pid_namespace *ns = proc_pid_ns(inode);
757+ struct pid_namespace *ns = proc_pid_ns(inode->i_sb);
758758 struct pid *pid = proc_pid(inode);
759759 struct task_struct *task;
760760 int ret;
@@ -1423,7 +1423,7 @@ static const struct file_operations proc_fail_nth_operations = { · 662 unmodified lines
14231423 static int sched_show(struct seq_file *m, void *v)
14241424 {
14251425 struct inode *inode = m->private;
1426− struct pid_namespace *ns = proc_pid_ns(inode);
1426+ struct pid_namespace *ns = proc_pid_ns(inode->i_sb);
14271427 struct task_struct *p;
14281428
14291429 p = get_proc_task(inode);
@@ -2466,7 +2466,7 @@ static int proc_timers_open(struct inode *inode, struct file *file) · 1036 unmodified lines
24662466 return -ENOMEM;
24672467
24682468 tp->pid = proc_pid(inode);
2469− tp->ns = proc_pid_ns(inode);
2469+ tp->ns = proc_pid_ns(inode->i_sb);
24702470 return 0;
24712471 }
24722472
@@ -3377,7 +3377,7 @@ int proc_pid_readdir(struct file *file, struct dir_context *ctx) · 904 unmodified lines
33773377 {
33783378 struct tgid_iter iter;
33793379 struct proc_fs_info *fs_info = proc_sb_info(file_inode(file)->i_sb);
3380− struct pid_namespace *ns = proc_pid_ns(file_inode(file));
3380+ struct pid_namespace *ns = proc_pid_ns(file_inode(file)->i_sb);
33813381 loff_t pos = ctx->pos;
33823382
33833383 if (pos >= PID_MAX_LIMIT + TGID_OFFSET)
@@ -3730,7 +3730,7 @@ static int proc_task_readdir(struct file *file, struct dir_context *ctx) · 346 unmodified lines
37303730 /* f_version caches the tgid value that the last readdir call couldn't
37313731 * return. lseek aka telldir automagically resets f_version to 0.
37323732 */
3733− ns = proc_pid_ns(inode);
3733+ ns = proc_pid_ns(inode->i_sb);
37343734 tid = (int)file->f_version;
37353735 file->f_version = 0;
37363736 for (task = first_tid(proc_pid(inode), tid, ctx->pos - 2, ns);
fs/proc/self.c+1−1
@@ -12,7 +12,7 @@ static const char *proc_self_get_link(struct dentry *dentry, · 11 unmodified lines
1212 struct inode *inode,
1313 struct delayed_call *done)
1414 {
15− struct pid_namespace *ns = proc_pid_ns(inode);
15+ struct pid_namespace *ns = proc_pid_ns(inode->i_sb);
1616 pid_t tgid = task_tgid_nr_ns(current, ns);
1717 char *name;
1818
fs/proc/thread_self.c+1−1
@@ -12,7 +12,7 @@ static const char *proc_thread_self_get_link(struct dentry *dentry, · 11 unmodified lines
1212 struct inode *inode,
1313 struct delayed_call *done)
1414 {
15− struct pid_namespace *ns = proc_pid_ns(inode);
15+ struct pid_namespace *ns = proc_pid_ns(inode->i_sb);
1616 pid_t tgid = task_tgid_nr_ns(current, ns);
1717 pid_t pid = task_pid_nr_ns(current, ns);
1818 char *name;
include/linux/proc_fs.h+2−2
@@ -202,9 +202,9 @@ int open_related_ns(struct ns_common *ns, · 201 unmodified lines
202202 struct ns_common *(*get_ns)(struct ns_common *ns));
203203
204204 /* get the associated pid namespace for a file in procfs */
205−static inline struct pid_namespace *proc_pid_ns(const struct inode *inode)
205+static inline struct pid_namespace *proc_pid_ns(struct super_block *sb)
206206 {
207− return proc_sb_info(inode->i_sb)->pid_ns;
207+ return proc_sb_info(sb)->pid_ns;
208208 }
209209
210210 #endif /* _LINUX_PROC_FS_H */
kernel/fork.c+1−1
@@ -1745,7 +1745,7 @@ static void pidfd_show_fdinfo(struct seq_file *m, struct file *f) · 1744 unmodified lines
17451745 pid_t nr = -1;
17461746
17471747 if (likely(pid_has_task(pid, PIDTYPE_PID))) {
1748− ns = proc_pid_ns(file_inode(m->file));
1748+ ns = proc_pid_ns(file_inode(m->file)->i_sb);
17491749 nr = pid_nr_ns(pid, ns);
17501750 }
17511751
net/ipv6/ip6_flowlabel.c+1−1
@@ -779,7 +779,7 @@ static void *ip6fl_seq_start(struct seq_file *seq, loff_t *pos) · 778 unmodified lines
779779 {
780780 struct ip6fl_iter_state *state = ip6fl_seq_private(seq);
781781
782− state->pid_ns = proc_pid_ns(file_inode(seq->file));
782+ state->pid_ns = proc_pid_ns(file_inode(seq->file)->i_sb);
783783
784784 rcu_read_lock_bh();
785785 return *pos ? ip6fl_get_idx(seq, *pos - 1) : SEQ_START_TOKEN;
security/tomoyo/realpath.c+1−1
@@ -162,7 +162,7 @@ static char *tomoyo_get_local_path(struct dentry *dentry, char * const buffer, · 161 unmodified lines
162162 if (sb->s_magic == PROC_SUPER_MAGIC && *pos == '/') {
163163 char *ep;
164164 const pid_t pid = (pid_t) simple_strtoul(pos + 1, &ep, 10);
165− struct pid_namespace *proc_pidns = proc_pid_ns(d_inode(dentry));
165+ struct pid_namespace *proc_pidns = proc_pid_ns(sb);
166166
167167 if (*ep == '/' && pid && pid ==
168168 task_tgid_nr_ns(current, proc_pidns)) {