From: zhang jiao timerfd_setup() reinitializes the timer on every timerfd_settime() invocation. For the hrtimer based clockids this goes through hrtimer_setup(), which zeroes the whole hrtimer including the expiry time which is stored in the embedded timerqueue node. For the alarm based clockids (CLOCK_REALTIME_ALARM and CLOCK_BOOTTIME_ALARM) timerfd_setup() uses alarm_init(), which only reinitializes the timerqueue node linkage and the alarm state. The expiry time, which alarm_start_timer() stores in alarm->node.expires, survives that reinitialization. As a consequence, disarming an alarm timerfd with timerfd_settime() and an all zero it_value leaves the expiry time of the previous arming in place. The remaining time of a timerfd is reported by timerfd_gettime(), by the old_value copyout of a subsequent timerfd_settime() and by the fdinfo file. A disarmed alarm timerfd therefore keeps reporting a non-zero it_value until the stale expiry time has passed, while the hrtimer based clockids correctly report zero as required by POSIX. Reset the expiry time when disarming an alarm based timerfd, which matches what the memset() in hrtimer_setup() establishes for the hrtimer based clockids. Fixes: 11ffa9d6065f ("timerfd: Add alarm timers") Cc: Todd Poynor Cc: Thomas Gleixner Cc: Signed-off-by: zhang jiao --- fs/timerfd.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/fs/timerfd.c b/fs/timerfd.c index fe845af0b74e..d7cc704e4afa 100644 --- a/fs/timerfd.c +++ b/fs/timerfd.c @@ -247,6 +247,8 @@ static int timerfd_setup(struct timerfd_ctx *ctx, int flags, ctx->clockid == CLOCK_REALTIME_ALARM ? ALARM_REALTIME : ALARM_BOOTTIME, timerfd_alarmproc); + if (!texp) + ctx->t.alarm.node.expires = 0; } else { hrtimer_setup(&ctx->t.tmr, timerfd_tmrproc, clockid, htmode); } -- 2.33.0