Bug 2579441 (CVE-2026-129836)

Summary: CVE-2026-129836 rsyslog: imdtls: incomplete handshake listener stall
Product: [Other] Security Response Reporter: OSIDB Bzimport <bzimport>
Component: vulnerabilityAssignee: Product Security <prodsec-ir-bot>
Status: NEW --- QA Contact:
Severity: high Docs Contact:
Priority: high    
Version: unspecifiedCC: rhel-process-autobot, watson-tool-maintainers
Target Milestone: ---Keywords: Security
Target Release: ---   
Hardware: All   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: ---
Doc Text:
A flaw was found in rsyslog. This vulnerability allows a remote attacker to cause a denial of service (DoS) by initiating a Datagram Transport Layer Security (DTLS) connection and leaving the cryptographic handshake incomplete. In configurations where the imdtls input module is active, this stalled connection blocks the shared listener, preventing other clients from connecting and transmitting log messages.
Story Points: ---
Clone Of: Environment:
Last Closed: Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description OSIDB Bzimport 2026-11-20 17:30:39 UTC
* subj: [vs-plain] rsyslog imdtls incomplete-handshake listener stall cves: GHSA-4chq-f2r9-5jp8-R1    | CVE-2026-129836

PRIVATE — embargoed source fix for rsyslog imdtls (4chq-R1)

This is the R1 incomplete-DTLS-handshake listener-stall issue from
private GHSA-4chq-f2r9-5jp8. After the DTLS cookie exchange, a remote
client can leave the handshake incomplete and block the shared imdtls
listener in SSL_accept before presenting a certificate. Other clients
of that input are not served while it waits. The path was reproduced
on public main. The optional imdtls input must be configured and
exposed.

Affected: rsyslog >= 8.2402.0. Primary combined-advisory CVSS v3.1
High 7.5 (AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:H); CWE-400. CVE
requested; assignment pending (GitHub request event 1355640).
Reporter: fairuzan.

The attached source-only patch is the common production fix for this
issue and the separately notified R2 and R3 findings. Apply it once,
against rsyslog base a6c1f4023df4f4e783158ea3837796dc0ef45e4e or a
main tree with unchanged plugins/imdtls/imdtls.c. Private candidate PR
#11 exact head is f18d0bd694a23ac3deff50f075b3e5748c9e6cda. Patch
SHA-256: 5978bdfc2a3bf4d9029cdb2412c7a294fb678d106972f0de013b526472b1262e;
size 13,137 bytes. The patch also contains the guards needed for
R2/R3, which share code paths; it is not three independent changes.
Tests are in the private candidate.

Proposed public disclosure date/time: 2026-11-17 at 16:00 UTC (17:00
CET / 11:00 EST). Fixed-version label: 2026-11-17 daily stable;
package availability is not yet claimed. Please keep this private
until the coordinated public disclosure. A public oss-security post is
prepared separately for R1 and will be scheduled after the coordinated
publication.

** Patch

#+begin_src diff
diff --git a/plugins/imdtls/imdtls.c b/plugins/imdtls/imdtls.c
index 88b45374f..65e2eb268 100644
--- a/plugins/imdtls/imdtls.c
+++ b/plugins/imdtls/imdtls.c
@@ -35,6 +35,7 @@
 #include <poll.h>
 #include <assert.h>
 #include <time.h>
+#include <limits.h>
 
 // --- Include openssl headers as well
 #include <openssl/ssl.h>
@@ -98,6 +99,10 @@ struct dtlsClient_s {
     SSL *sslClient; /* DTSL (SSL) Client */
     time_t lastActivityTime; /* Last Activity Time */
     int clientfd; /* ClientFD */
+    int peerVerified; /* post-handshake permitted-peer check completed */
+    long verifiedRenegotiations; /* handshake generation covered by peerVerified */
+    short pollEvents; /* readiness needed by the handshake */
+    int drainPending; /* continue after the per-client read limit */
 };
 
 // Use typedef to define a type 'dtlsClient_t' based on 'struct dtlsClient_s'
@@ -572,6 +577,32 @@ static void DTLScleanupSession(instanceConf_t *inst, int idx) {
     }
     inst->dtlsClients[idx]->sslClient = NULL;
     inst->dtlsClients[idx]->lastActivityTime = 0;
+    inst->dtlsClients[idx]->peerVerified = 0;
+    inst->dtlsClients[idx]->verifiedRenegotiations = 0;
+    inst->dtlsClients[idx]->pollEvents = POLLIN;
+    inst->dtlsClients[idx]->drainPending = 0;
+}
+
+static int DTLSVerifySession(instanceConf_t *inst, int idx) {
+    dtlsClient_t *client = inst->dtlsClients[idx];
+    if (!SSL_is_init_finished(client->sslClient)) {
+        client->peerVerified = 0;
+        return 0;
+    }
+    long renegotiations = SSL_total_renegotiations(client->sslClient);
+    if (client->peerVerified && client->verifiedRenegotiations == renegotiations) {
+        return 1;
+    }
+
+    if (imdtls_verify_callback(1, client->sslClient) == 0) {
+        LogMsg(0, RS_RET_NO_ERRCODE, LOG_WARNING, "imdtls: Cert Verify FAILED for DTLS client idx (%d)", idx);
+        DTLScleanupSession(inst, idx);
+        return 0;
+    }
+    client->peerVerified = 1;
+    client->verifiedRenegotiations = renegotiations;
+    DBGPRINTF("imdtls: Cert Verify SUCCESS for DTLS client idx (%d)\n", idx);
+    return 1;
 }
 
 static void DTLSAcceptSession(instanceConf_t *inst, int idx) {
@@ -587,7 +618,7 @@ static void DTLSAcceptSession(instanceConf_t *inst, int idx) {
         if (ret <= 0) {
             err = SSL_get_error(ssl, ret);
             if (err == SSL_ERROR_WANT_READ || err == SSL_ERROR_WANT_WRITE) {
-                // Non-blocking operation did not complete; retry later
+                inst->dtlsClients[idx]->pollEvents = (err == SSL_ERROR_WANT_WRITE) ? POLLIN | POLLOUT : POLLIN;
                 DBGPRINTF("imdtls: SSL_accept didn't complete (%d). Will retry.\n", err);
             } else if (err == SSL_ERROR_SYSCALL) {
                 DBGPRINTF("imdtls: SSL_accept failed SSL_ERROR_SYSCALL idx (%d), removing client.\n", idx);
@@ -602,18 +633,12 @@ static void DTLSAcceptSession(instanceConf_t *inst, int idx) {
         } else {
             DBGPRINTF("imdtls: SSL_accept success idx (%d), adding client.\n", idx);
             inst->dtlsClients[idx]->lastActivityTime = time(NULL);
-
-            int status = 1;
-            status = imdtls_verify_callback(status, ssl);
-            if (status == 0) {
-                LogMsg(0, RS_RET_NO_ERRCODE, LOG_WARNING, "imdtls: Cert Verify FAILED for DTLS client idx (%d)", idx);
-                DTLScleanupSession(inst, idx);
-            } else {
-                DBGPRINTF("imdtls: Cert Verify SUCCESS for DTLS client idx (%d)\n", idx);
-            }
+            inst->dtlsClients[idx]->pollEvents = POLLIN;
+            DTLSVerifySession(inst, idx);
         }
     } else {
         DBGPRINTF("imdtls: SSL_get_state for DTLS client idx (%d) is %d\n", idx, ret);
+        DTLSVerifySession(inst, idx);
     }
 }
 
@@ -630,26 +655,44 @@ static void DTLSReadClient(instanceConf_t *inst, int idx, short revents) {
     int err;
     SSL *ssl = inst->dtlsClients[idx]->sslClient;
     DBGPRINTF("imdtls: DEBUG Check Client activity on index %d.\n", idx);
-    if (revents & POLLIN) {
+    if (revents & (POLLIN | POLLOUT)) {
         if (ssl == NULL) {
             DBGPRINTF("imdtls: DTLSHandleSessions MISSING SSL OBJ for index %d.\n", idx);
             return;
         }
+        if (!SSL_is_init_finished(ssl)) {
+            DTLSAcceptSession(inst, idx);
+            ssl = inst->dtlsClients[idx]->sslClient;
+            if (ssl == NULL || !SSL_is_init_finished(ssl)) {
+                return;
+            }
+        }
+        if (!DTLSVerifySession(inst, idx) || !(revents & inst->dtlsClients[idx]->pollEvents)) {
+            return;
+        }
         DBGPRINTF("imdtls: Read Client activity on index %d.\n", idx);
         char buf[MAX_DTLS_MSGSIZE];
         int len = 0;
+        int reads = 0;
+        inst->dtlsClients[idx]->drainPending = 0;
         do {
             len = SSL_read(ssl, buf, sizeof(buf) - 1);
             if (len > 0) {
+                inst->dtlsClients[idx]->pollEvents = POLLIN;
+                if (!DTLSVerifySession(inst, idx)) {
+                    return;
+                }
                 buf[len] = '\0';
                 processMsg(inst, inst->dtlsClients[idx], buf, len);
             } else {
                 err = SSL_get_error(ssl, len);
                 if (err == SSL_ERROR_WANT_READ) {
+                    inst->dtlsClients[idx]->pollEvents = POLLIN;
                     DBGPRINTF("imdtls: SSL_ERROR_WANT_READ flush rbio on index %d.\n", idx);
                     BIO *rbio = SSL_get_rbio(ssl);
                     BIO_flush(rbio);
                 } else if (err == SSL_ERROR_WANT_WRITE) {
+                    inst->dtlsClients[idx]->pollEvents = POLLIN | POLLOUT;
                     DBGPRINTF("imdtls: SSL_ERROR_WANT_WRITE flush wbio on index %d.\n", idx);
                     BIO *wbio = SSL_get_wbio(ssl);
                     BIO_flush(wbio);
@@ -668,7 +711,15 @@ static void DTLSReadClient(instanceConf_t *inst, int idx, short revents) {
                     break;
                 }
             }
-        } while (len > 0);
+            ++reads;
+        } while (len > 0 && reads < 32);
+        /* OpenSSL can retain complete DTLS records after the datagram socket
+         * has been drained. Retry once on the next loop after the limit,
+         * even if poll reports no new socket data. A WANT_READ clears this
+         * flag, so an incomplete record cannot spin the event loop. */
+        if (len > 0 && reads == 32) {
+            inst->dtlsClients[idx]->drainPending = 1;
+        }
     }
 }
 
@@ -678,6 +729,8 @@ static void DTLSHandleSessions(instanceConf_t *inst) {
     int optval = 1;
     int fdcount = 0;
     int ret, err;
+    int pollTimeout = -1;
+    time_t now = time(NULL);
     memset(clientIdxByPollSlot, -1, sizeof(clientIdxByPollSlot));
     memset(fds, 0, sizeof(fds));
     fds[0].fd = inst->sockfd;
@@ -696,13 +749,36 @@ static void DTLSHandleSessions(instanceConf_t *inst) {
             fdcount++;
             DBGPRINTF("imdtls: DTLSHandleSessions handle client %d (%d)\n", fdcount, clientfd);
             fds[fdcount].fd = clientfd;
-            fds[fdcount].events = POLLIN;
+            fds[fdcount].events = inst->dtlsClients[i]->pollEvents;
             clientIdxByPollSlot[fdcount] = i;
+            if (inst->dtlsClients[i]->drainPending) {
+                pollTimeout = 0;
+            }
+
+            /* A nonblocking DTLS handshake needs its retransmission timer
+             * serviced even if no socket becomes ready. */
+            if (!SSL_is_init_finished(inst->dtlsClients[i]->sslClient)) {
+                struct timeval tv;
+                if (DTLSv1_get_timeout(inst->dtlsClients[i]->sslClient, &tv)) {
+                    long long ms = (long long)tv.tv_sec * 1000 + (tv.tv_usec + 999) / 1000;
+                    int delay = ms > INT_MAX ? INT_MAX : (int)ms;
+                    if (pollTimeout < 0 || delay < pollTimeout) {
+                        pollTimeout = delay;
+                    }
+                }
+            }
+            long long idleSeconds =
+                (long long)inst->timeout - (long long)difftime(now, inst->dtlsClients[i]->lastActivityTime);
+            long long idleMs = idleSeconds <= 0 ? 0 : idleSeconds * 1000;
+            int idleDelay = idleMs > INT_MAX ? INT_MAX : (int)idleMs;
+            if (pollTimeout < 0 || idleDelay < pollTimeout) {
+                pollTimeout = idleDelay;
+            }
         }
     }
 
     DBGPRINTF("imdtls: Waiting for poll (clients %d) ...\n", fdcount);
-    ret = poll(fds, fdcount + 1, -1);
+    ret = poll(fds, fdcount + 1, pollTimeout);
     if (glbl.GetGlobalInputTermState() == 1) {
         DBGPRINTF("imdtls: DTLSHandleSessions Terminate State\n");
         return; /* terminate input! */
@@ -716,14 +792,25 @@ static void DTLSHandleSessions(instanceConf_t *inst) {
     DBGPRINTF("imdtls: DTLSHandleSessions handle client sockets (%d) \n", fdcount);
     for (int i = 1; i <= fdcount; ++i) {
         if (clientIdxByPollSlot[i] >= 0) {
-            DTLSReadClient(inst, clientIdxByPollSlot[i], fds[i].revents);
+            int idx = clientIdxByPollSlot[i];
+            short revents = fds[i].revents | (inst->dtlsClients[idx]->drainPending ? POLLIN : 0);
+            DTLSReadClient(inst, idx, revents);
         }
     }
 
     // Check session timeouts
     for (int i = 0; i < MAX_DTLS_CLIENTS; ++i) {
         if (inst->dtlsClients[i]->sslClient != NULL) {
-            if (difftime(time(NULL), inst->dtlsClients[i]->lastActivityTime) > inst->timeout) {
+            if (!SSL_is_init_finished(inst->dtlsClients[i]->sslClient)) {
+                struct timeval tv;
+                if (DTLSv1_get_timeout(inst->dtlsClients[i]->sslClient, &tv) && tv.tv_sec == 0 && tv.tv_usec == 0 &&
+                    DTLSv1_handle_timeout(inst->dtlsClients[i]->sslClient) < 0) {
+                    DBGPRINTF("imdtls: DTLS retransmission failed for client index %d.\n", i);
+                    DTLScleanupSession(inst, i);
+                    continue;
+                }
+            }
+            if (difftime(time(NULL), inst->dtlsClients[i]->lastActivityTime) >= inst->timeout) {
                 DBGPRINTF("imdtls: Session timeout (%d) for client index %d.\n", i, inst->timeout);
                 DTLScleanupSession(inst, i);
                 continue;
@@ -832,12 +919,25 @@ static void DTLSHandleSessions(instanceConf_t *inst) {
                     int addedClient = 0;
                     BIO_ctrl_set_connected(rbio, client_addr);
                     DBGPRINTF("imdtls: BIO_connect succeeded.\n");
+                    /* BIO_connect can reset the socket's blocking mode. Set
+                     * O_NONBLOCK only after the BIO has been connected. */
+                    int flags = fcntl(clientfd, F_GETFL, 0);
+                    if (flags < 0 || fcntl(clientfd, F_SETFL, flags | O_NONBLOCK) < 0) {
+                        LogError(0, NO_ERRCODE, "imdtls: unable to make client socket non-blocking");
+                        close(clientfd);
+                        SSL_free(ssl);
+                        break;
+                    }
 
                     // Add to DTLS Clients
                     for (int i = 0; i < MAX_DTLS_CLIENTS; ++i) {
                         if (inst->dtlsClients[i]->sslClient == NULL) {
                             inst->dtlsClients[i]->sslClient = ssl;
                             inst->dtlsClients[i]->lastActivityTime = time(NULL);
+                            inst->dtlsClients[i]->peerVerified = 0;
+                            inst->dtlsClients[i]->verifiedRenegotiations = 0;
+                            inst->dtlsClients[i]->pollEvents = POLLIN;
+                            inst->dtlsClients[i]->drainPending = 0;
                             DBGPRINTF("imdtls: New Client added at idx %d.\n", i);
                             DTLSAcceptSession(inst, i);
                             addedClient = 1;
@@ -857,10 +957,11 @@ static void DTLSHandleSessions(instanceConf_t *inst) {
                 /* Retry on EAGAIN (recv timeout, no datagram) and on ret == 0
                  * with an empty error queue (no usable handshake data yet). */
                 if (err == SSL_ERROR_SYSCALL && (errno == EAGAIN || (ret == 0 && ERR_peek_error() == 0))) {
-                    DBGPRINTF("imdtls: DTLSv1_listen RET %d (ERR %d / ERRNO %d), retry\n", ret, err, errno);
-                    // Wait little and retry DTLSv1_listen
-                    srSleep(0, 100000);
-                    continue;
+                    DBGPRINTF("imdtls: DTLSv1_listen RET %d (ERR %d / ERRNO %d), defer\n", ret, err, errno);
+                    /* DTLSv1_listen is stateless across the cookie exchange.
+                     * Return to poll instead of waiting here for a second flight. */
+                    SSL_free(ssl);
+                    break;
                 } else {
                     DBGPRINTF("imdtls: DTLSv1_listen RET %d (ERR %d / ERRNO %d), abort\n", ret, err, errno);
                     net_ossl.osslLastOpenSSLErrorMsg(NULL, err, ssl, LOG_WARNING, "DTLSHandleSessions",
#+end_src