naccyde / rpms / systemd

Forked from rpms/systemd a year ago
Clone
Pablo Greco 48fc63
From 2b0874a8a0ff4bced5da0c25a4b3f3fbd2595e23 Mon Sep 17 00:00:00 2001
Pablo Greco 48fc63
From: Michal Sekletar <msekleta@redhat.com>
Pablo Greco 48fc63
Date: Wed, 1 May 2019 15:58:44 +0200
Pablo Greco 48fc63
Subject: [PATCH] udev: check age against both timeouts to prevent integer
Pablo Greco 48fc63
 wraparound
Pablo Greco 48fc63
Pablo Greco 48fc63
If we get back to while loop after timeout_warn (roughly 60s)
Pablo Greco 48fc63
expired for the first time, but before age of the event is larger than
Pablo Greco 48fc63
second timeout (roughly 120s) we would try to recompute timeout_warn
Pablo Greco 48fc63
again. Previously the following code,
Pablo Greco 48fc63
Pablo Greco 48fc63
if (timeout_warn_usec > 0)
Pablo Greco 48fc63
        timeout_warn = ((timeout_warn_usec - age_usec) / USEC_PER_MSEC) + MSEC_PER_SEC;
Pablo Greco 48fc63
Pablo Greco 48fc63
would cause an integer wraparound because (timeout_warn_usec - age_usec)
Pablo Greco 48fc63
is negative however both timeout_warn_usec and age_usec are
Pablo Greco 48fc63
unsigned.
Pablo Greco 48fc63
Pablo Greco 48fc63
This can happen if we get SIGTERM from the main daemon while waiting in
Pablo Greco 48fc63
the second poll(), i.e. after timeout_warn already expired, because on
Pablo Greco 48fc63
SIGTERM we just take a note of that happening in event->sigterm and
Pablo Greco 48fc63
continue.
Pablo Greco 48fc63
Pablo Greco 48fc63
Related: #1697909
Pablo Greco 48fc63
---
Pablo Greco 48fc63
 src/udev/udev-event.c | 2 +-
Pablo Greco 48fc63
 1 file changed, 1 insertion(+), 1 deletion(-)
Pablo Greco 48fc63
Pablo Greco 48fc63
diff --git a/src/udev/udev-event.c b/src/udev/udev-event.c
Pablo Greco 48fc63
index 07b82d093e..5550ec93de 100644
Pablo Greco 48fc63
--- a/src/udev/udev-event.c
Pablo Greco 48fc63
+++ b/src/udev/udev-event.c
Pablo Greco 48fc63
@@ -559,7 +559,7 @@ static int spawn_wait(struct udev_event *event,
Pablo Greco 48fc63
                         usec_t age_usec;
Pablo Greco 48fc63
 
Pablo Greco 48fc63
                         age_usec = now(CLOCK_MONOTONIC) - event->birth_usec;
Pablo Greco 48fc63
-                        if (age_usec >= timeout_usec)
Pablo Greco 48fc63
+                        if (age_usec >= timeout_usec || age_usec >= timeout_warn_usec)
Pablo Greco 48fc63
                                 timeout = 1000;
Pablo Greco 48fc63
                         else {
Pablo Greco 48fc63
                                 if (timeout_warn_usec > 0)