From: Frederic Weisbecker frederic@kernel.org
mainline inclusion from mainline-v5.15-rc3 commit 8cd9da85d2bd87ce889043e7b1735723dd10eb89 category: bugfix bugzilla: https://gitee.com/openeuler/kernel/issues/I9JNPZ
Reference: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit?id...
--------------------------------
Resetting/stopping an itimer eventually leads to it being reprogrammed with an actual "0" value. As a result the itimer expires on the next tick, triggering an unexpected signal.
To fix this, make sure that struct signal_struct::it[CPUCLOCK_PROF/VIRT]::expires is set to 0 when setitimer() passes a 0 it_value, indicating that the timer must stop.
Fixes: 406dd42bd1ba ("posix-cpu-timers: Force next expiration recalc after itimer reset") Reported-by: Victor Stinner vstinner@redhat.com Reported-by: Chris Hixon linux-kernel-bugs@hixontech.com Signed-off-by: Frederic Weisbecker frederic@kernel.org Signed-off-by: Thomas Gleixner tglx@linutronix.de Link: https://lore.kernel.org/r/20210913145332.232023-1-frederic@kernel.org Signed-off-by: Xiongfeng Wang wangxiongfeng2@huawei.com --- kernel/time/posix-cpu-timers.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/kernel/time/posix-cpu-timers.c b/kernel/time/posix-cpu-timers.c index e5a1c157543e..4bb0add650d5 100644 --- a/kernel/time/posix-cpu-timers.c +++ b/kernel/time/posix-cpu-timers.c @@ -1357,7 +1357,8 @@ void set_process_cpu_timer(struct task_struct *tsk, unsigned int clkid, } }
- *newval += now; + if (*newval) + *newval += now; }
/*