naccyde / rpms / systemd

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