On Mon, Oct 24, 2016 at 01:15:27PM +0200, Oleg Nesterov wrote: > Yes, current is still valid. > > But nothing protects current->group_leader or parent/real_parent, they > can point to the exited/freed task. We really need to nullify them in > __unhash_process() to catch the problems like this, I wanted to do this > many times... > > So you simply can't know your tgid or even tid after release_task() calls > __unhash_process(). Actually after exit_notify() unless the exiting task > autoreaps itself. > > How about the trivial fix below? > > Oleg. > > --- x/kernel/events/core.c > +++ x/kernel/events/core.c > @@ -1257,7 +1257,7 @@ static u32 perf_event_pid(struct perf_ev > if (event->parent) > event = event->parent; > > - return task_tgid_nr_ns(p, event->ns); > + return pid_alive(p) ? task_tgid_nr_ns(p, event->ns) : 0; > } > > static u32 perf_event_tid(struct perf_event *event, struct task_struct *p)
Should we do the same for perf_event_tid() and report -1 as the pid/tid in the !alive case? -1 should be an obvious invalid pid since we limit the pid-space to less than 32 bits.

