Commit 6279a751fe096a21dc7704e918d570d3ff06e769

Authored by Oleg Nesterov
Committed by Ingo Molnar
1 parent 633fe795b8

posix-timers: fix RLIMIT_CPU && fork()

See http://bugzilla.kernel.org/show_bug.cgi?id=12911

copy_signal() copies signal->rlim, but RLIMIT_CPU is "lost". Because
posix_cpu_timers_init_group() sets cputime_expires.prof_exp = 0 and thus
fastpath_timer_check() returns false unless we have other expired cpu timers.

Change copy_signal() to set cputime_expires.prof_exp if we have RLIMIT_CPU.
Also, set cputimer.running = 1 in that case. This is not strictly necessary,
but imho makes sense.

Reported-by: Peter Lojkin <ia6432@inbox.ru>
Signed-off-by: Oleg Nesterov <oleg@redhat.com>
Acked-by: Peter Zijlstra <peterz@infradead.org>
Cc: Peter Lojkin <ia6432@inbox.ru>
Cc: Roland McGrath <roland@redhat.com>
Cc: stable@kernel.org
LKML-Reference: <20090327000607.GA10104@redhat.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>

Showing 1 changed file with 9 additions and 4 deletions Side-by-side Diff

... ... @@ -808,6 +808,12 @@
808 808 sig->cputime_expires.virt_exp = cputime_zero;
809 809 sig->cputime_expires.sched_exp = 0;
810 810  
  811 + if (sig->rlim[RLIMIT_CPU].rlim_cur != RLIM_INFINITY) {
  812 + sig->cputime_expires.prof_exp =
  813 + secs_to_cputime(sig->rlim[RLIMIT_CPU].rlim_cur);
  814 + sig->cputimer.running = 1;
  815 + }
  816 +
811 817 /* The timer lists. */
812 818 INIT_LIST_HEAD(&sig->cpu_timers[0]);
813 819 INIT_LIST_HEAD(&sig->cpu_timers[1]);
814 820  
... ... @@ -823,11 +829,8 @@
823 829 atomic_inc(&current->signal->live);
824 830 return 0;
825 831 }
826   - sig = kmem_cache_alloc(signal_cachep, GFP_KERNEL);
827 832  
828   - if (sig)
829   - posix_cpu_timers_init_group(sig);
830   -
  833 + sig = kmem_cache_alloc(signal_cachep, GFP_KERNEL);
831 834 tsk->signal = sig;
832 835 if (!sig)
833 836 return -ENOMEM;
... ... @@ -864,6 +867,8 @@
864 867 task_lock(current->group_leader);
865 868 memcpy(sig->rlim, current->signal->rlim, sizeof sig->rlim);
866 869 task_unlock(current->group_leader);
  870 +
  871 + posix_cpu_timers_init_group(sig);
867 872  
868 873 acct_init_pacct(&sig->pacct);
869 874