Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

taskstats: add_del_listener() should ignore !valid listeners

When send_cpu_listeners() finds the orphaned listener it marks it as
!valid and drops listeners->sem. Before it takes this sem for writing,
s->pid can be reused and add_del_listener() can wrongly try to re-use
this entry.

Change add_del_listener() to check ->valid = T.

Signed-off-by: Oleg Nesterov <oleg@redhat.com>
Reviewed-by: Vasiliy Kulikov <segoon@openwall.com>
Acked-by: Balbir Singh <bsingharora@gmail.com>
Cc: Jerome Marchand <jmarchan@redhat.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

authored by

Oleg Nesterov and committed by
Linus Torvalds
a7295898 dfc428b6

+1 -1
+1 -1
kernel/taskstats.c
··· 304 304 listeners = &per_cpu(listener_array, cpu); 305 305 down_write(&listeners->sem); 306 306 list_for_each_entry(s2, &listeners->list, list) { 307 - if (s2->pid == pid) 307 + if (s2->pid == pid && s2->valid) 308 308 goto exists; 309 309 } 310 310 list_add(&s->list, &listeners->list);