Skip to content

Commit c3bca5d

Browse files
labbottKAGA-KOKO
authored andcommitted
posix-cpu-timers: Ensure set_process_cpu_timer is always evaluated
Commit a9445e4 ("posix-cpu-timers: Make set_process_cpu_timer() more robust") moved the check into the 'if' statement. Unfortunately, it did so on the right side of an && which means that it may get short circuited and never evaluated. This is easily reproduced with: $ cat loop.c void main() { struct rlimit res; /* set the CPU time limit */ getrlimit(RLIMIT_CPU,&res); res.rlim_cur = 2; res.rlim_max = 2; setrlimit(RLIMIT_CPU,&res); while (1); } Which will hang forever instead of being killed. Fix this by pulling the evaluation out of the if statement but checking the return value instead. Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1568337 Fixes: a9445e4 ("posix-cpu-timers: Make set_process_cpu_timer() more robust") Signed-off-by: Laura Abbott <labbott@redhat.com> Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Cc: stable@vger.kernel.org Cc: "Max R . P . Grossmann" <m@max.pm> Cc: John Stultz <john.stultz@linaro.org> Link: https://lkml.kernel.org/r/20180417215742.2521-1-labbott@redhat.com
1 parent e142aa0 commit c3bca5d

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

kernel/time/posix-cpu-timers.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1205,10 +1205,12 @@ void set_process_cpu_timer(struct task_struct *tsk, unsigned int clock_idx,
12051205
u64 *newval, u64 *oldval)
12061206
{
12071207
u64 now;
1208+
int ret;
12081209

12091210
WARN_ON_ONCE(clock_idx == CPUCLOCK_SCHED);
1211+
ret = cpu_timer_sample_group(clock_idx, tsk, &now);
12101212

1211-
if (oldval && cpu_timer_sample_group(clock_idx, tsk, &now) != -EINVAL) {
1213+
if (oldval && ret != -EINVAL) {
12121214
/*
12131215
* We are setting itimer. The *oldval is absolute and we update
12141216
* it to be relative, *newval argument is relative and we update

0 commit comments

Comments
 (0)