pid: annotate data-races around pid_ns->pid_allocated
Subsystems (4)
PATCH v2 1/1 pid: annotate data-races around pid_ns->pid_allocated
Suppress syzbot reports by annotating these accesses using data_race().
--- kernel/fork.c | 2 +- kernel/pid.c | 8 ++++---- kernel/pid_namespace.c | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-)
kernel/fork.c +1 -1
@@ -2584,7 +2584,7 @@ __latent_entropy struct task_struct *copy_process(rseq_fork (p, clone_flags);/* Don't start children in a dying pid namespace */ -if (unlikely (!(ns_of_pid (pid)->pid_allocated &PIDNS_ADDING ))) { +if (unlikely (!(data_race (ns_of_pid (pid)->pid_allocated &PIDNS_ADDING )))) { retval = -ENOMEM ; goto bad_fork_core_free; }
kernel/pid.c +4 -4
@@ -122,7 +122,7 @@ void free_pid(struct pid *pid)for (i =0 ; i <= pid->level; i++) {struct upid *upid = pid->numbers + i;struct pid_namespace *ns = upid->ns; -switch (--ns->pid_allocated) { +switch (data_race (--ns->pid_allocated)) {case 2 :case 1 :/* When all that is left in the pid namespace
@@ -134,7 +134,7 @@ void free_pid(struct pid *pid)case PIDNS_ADDING :/* Handle a fork failure of the first process */ WARN_ON (ns->child_reaper); - ns->pid_allocated =0 ; +data_race (ns->pid_allocated =0 );break ; }
@@ -271,13 +271,13 @@ struct pid *alloc_pid(struct pid_namespace *ns, pid_t *set_tid, upid = pid->numbers + ns->level;idr_preload (GFP_KERNEL );spin_lock (&pidmap_lock); -if (!(ns->pid_allocated &PIDNS_ADDING )) +if (!(data_race (ns->pid_allocated &PIDNS_ADDING ))) goto out_unlock;pidfs_add_pid (pid);for ( ; upid >= pid->numbers; --upid) {/* Make the PID visible to find_pid_ns. */ idr_replace (&upid->ns->idr, pid, upid->nr); - upid->ns->pid_allocated++; +data_race (upid->ns->pid_allocated++); }spin_unlock (&pidmap_lock);idr_preload_end ();
kernel/pid_namespace.c +1 -1
@@ -268,7 +268,7 @@ void zap_pid_ns_processes(struct pid_namespace *pid_ns)*/ for (;;) {set_current_state (TASK_INTERRUPTIBLE ); -if (pid_ns->pid_allocated == init_pids) +if (data_race (pid_ns->pid_allocated == init_pids))break ;schedule (); }
Signature · 1 line
2.47.1
Quoted 1 line · Jiayuan Chen
Suppress syzbot reports by annotating these accesses using
data_race().
Thanks for trying this approach.scripts/checkpatch.pl has quite some remarks about the current form :-) I mean, the data_race annotation should document why the race is harmless. I only glanced over this so I can't tell myself whether it's a bug or OK.
Quoted 3 lines
How can I get to see full syzbot reports? (Stacktrace would be helpful, I cannot resolve those as message-ids on (LK)ML.)
Thanks,
Michal
Quoted 25 lines · Michal Koutný
Quoted 3 lines · Jiayuan Chen
Suppress syzbot reports by annotating these accesses using
data_race().Thanks for trying this approach.
scripts/checkpatch.plhas quite some remarks about the current form :-)I mean, the
data_raceannotation should document why the race isharmless. I only glanced over this so I can't tell myself whether it's a
bug or OK.
Quoted 7 lines
Reported-by [email protected]Reported-by [email protected]Reported-by [email protected]
Quoted 8 lines
How can I get to see full syzbot reports? (Stacktrace would be helpful,
I cannot resolve those as message-ids on (LK)ML.)
Thanks,
Michal
Hi Michal,
We can find such reports at https://syzkaller.appspot.com/upstream/s/kernel
kernel/fork.c __latent_entropy struct task_struct *copy_process( · line 2587
Quoted 7 lines · Jiayuan Chen
kernel/fork.c +1
-1@@ -2584,7 +2584,7 @@ __latent_entropy struct task_struct *copy_process(rseq_fork (p, clone_flags);/* Don't start children in a dying pid namespace */ -if (unlikely (!(ns_of_pid (pid)->pid_allocated &PIDNS_ADDING ))) { +if (unlikely (!(data_race (ns_of_pid (pid)->pid_allocated &PIDNS_ADDING )))) {
Well. data_race() just hides the potential problem. READ_ONCE() makes more sense imo, even if I think there are no real problems with the current code.
Either way,
kernel/pid.c struct pid *alloc_pid(struct pid_namespace *ns, pid_t *set_tid, · line 274
Quoted 6 lines
kernel/pid.c +1
-1@@ -271,13 +271,13 @@ struct pid *alloc_pid(struct pid_namespace *ns, pid_t *set_tid, upid = pid->numbers + ns->level;idr_preload (GFP_KERNEL );spin_lock (&pidmap_lock); -if (!(ns->pid_allocated &PIDNS_ADDING )) +if (!(data_race (ns->pid_allocated &PIDNS_ADDING )))
again, you do not need data_race() or READ_ONCE() if you read the data protected by pidmap_lock. But you still need WRITE_ONCE() when ->pid_allocated is modified.
Oleg.