Skip to content

Commit 9d78ede

Browse files
legionusebiederm
authored andcommitted
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 c59f415, 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/[email protected] Link: https://lkml.kernel.org/r/[email protected] Reported-by: [email protected] Fixes: c59f415 ("Use proc_pid_ns() to get pid_namespace from the proc superblock") Signed-off-by: Alexey Gladkov <[email protected]> Signed-off-by: Eric W. Biederman <[email protected]>
1 parent 2dd8083 commit 9d78ede

File tree

9 files changed

+15
-15
lines changed

9 files changed

+15
-15
lines changed

fs/locks.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2823,7 +2823,7 @@ static void lock_get_status(struct seq_file *f, struct file_lock *fl,
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)
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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -728,7 +728,7 @@ static int children_seq_show(struct seq_file *seq, void *v)
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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -754,7 +754,7 @@ static const struct inode_operations proc_def_inode_operations = {
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 = {
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)
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)
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)
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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ static const char *proc_self_get_link(struct dentry *dentry,
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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ static const char *proc_thread_self_get_link(struct dentry *dentry,
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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,9 +202,9 @@ int open_related_ns(struct ns_common *ns,
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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1745,7 +1745,7 @@ static void pidfd_show_fdinfo(struct seq_file *m, struct file *f)
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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -779,7 +779,7 @@ static void *ip6fl_seq_start(struct seq_file *seq, loff_t *pos)
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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ static char *tomoyo_get_local_path(struct dentry *dentry, char * const buffer,
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)) {

0 commit comments

Comments
 (0)