mirror of
https://github.com/Fishwaldo/Star64_linux.git
synced 2025-07-10 16:42:21 +00:00
fix race between exit_itimers() and /proc/pid/timers
commit d5b36a4dbd
upstream.
As Chris explains, the comment above exit_itimers() is not correct,
we can race with proc_timers_seq_ops. Change exit_itimers() to clear
signal->posix_timers with ->siglock held.
Cc: <stable@vger.kernel.org>
Reported-by: chris@accessvector.net
Signed-off-by: Oleg Nesterov <oleg@redhat.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
parent
9fbc46b832
commit
51fc55e41c
4 changed files with 17 additions and 8 deletions
|
@ -1298,7 +1298,7 @@ int begin_new_exec(struct linux_binprm * bprm)
|
||||||
bprm->mm = NULL;
|
bprm->mm = NULL;
|
||||||
|
|
||||||
#ifdef CONFIG_POSIX_TIMERS
|
#ifdef CONFIG_POSIX_TIMERS
|
||||||
exit_itimers(me->signal);
|
exit_itimers(me);
|
||||||
flush_itimer_signals();
|
flush_itimer_signals();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -81,7 +81,7 @@ static inline void exit_thread(struct task_struct *tsk)
|
||||||
extern void do_group_exit(int);
|
extern void do_group_exit(int);
|
||||||
|
|
||||||
extern void exit_files(struct task_struct *);
|
extern void exit_files(struct task_struct *);
|
||||||
extern void exit_itimers(struct signal_struct *);
|
extern void exit_itimers(struct task_struct *);
|
||||||
|
|
||||||
extern pid_t kernel_clone(struct kernel_clone_args *kargs);
|
extern pid_t kernel_clone(struct kernel_clone_args *kargs);
|
||||||
struct task_struct *create_io_thread(int (*fn)(void *), void *arg, int node);
|
struct task_struct *create_io_thread(int (*fn)(void *), void *arg, int node);
|
||||||
|
|
|
@ -796,7 +796,7 @@ void __noreturn do_exit(long code)
|
||||||
|
|
||||||
#ifdef CONFIG_POSIX_TIMERS
|
#ifdef CONFIG_POSIX_TIMERS
|
||||||
hrtimer_cancel(&tsk->signal->real_timer);
|
hrtimer_cancel(&tsk->signal->real_timer);
|
||||||
exit_itimers(tsk->signal);
|
exit_itimers(tsk);
|
||||||
#endif
|
#endif
|
||||||
if (tsk->mm)
|
if (tsk->mm)
|
||||||
setmax_mm_hiwater_rss(&tsk->signal->maxrss, tsk->mm);
|
setmax_mm_hiwater_rss(&tsk->signal->maxrss, tsk->mm);
|
||||||
|
|
|
@ -1051,15 +1051,24 @@ retry_delete:
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This is called by do_exit or de_thread, only when there are no more
|
* This is called by do_exit or de_thread, only when nobody else can
|
||||||
* references to the shared signal_struct.
|
* modify the signal->posix_timers list. Yet we need sighand->siglock
|
||||||
|
* to prevent the race with /proc/pid/timers.
|
||||||
*/
|
*/
|
||||||
void exit_itimers(struct signal_struct *sig)
|
void exit_itimers(struct task_struct *tsk)
|
||||||
{
|
{
|
||||||
|
struct list_head timers;
|
||||||
struct k_itimer *tmr;
|
struct k_itimer *tmr;
|
||||||
|
|
||||||
while (!list_empty(&sig->posix_timers)) {
|
if (list_empty(&tsk->signal->posix_timers))
|
||||||
tmr = list_entry(sig->posix_timers.next, struct k_itimer, list);
|
return;
|
||||||
|
|
||||||
|
spin_lock_irq(&tsk->sighand->siglock);
|
||||||
|
list_replace_init(&tsk->signal->posix_timers, &timers);
|
||||||
|
spin_unlock_irq(&tsk->sighand->siglock);
|
||||||
|
|
||||||
|
while (!list_empty(&timers)) {
|
||||||
|
tmr = list_first_entry(&timers, struct k_itimer, list);
|
||||||
itimer_delete(tmr);
|
itimer_delete(tmr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue