Bug 2579505 (CVE-2026-129834) - CVE-2026-129834 rsyslog: imdtls: late DTLS handshake bypasses permitted-peer check
Summary: CVE-2026-129834 rsyslog: imdtls: late DTLS handshake bypasses permitted-peer ...
Keywords:
Status: NEW
Alias: CVE-2026-129834
Product: Security Response
Classification: Other
Component: vulnerability
Version: unspecified
Hardware: All
OS: Linux
medium
medium
Target Milestone: ---
Assignee: Product Security
QA Contact:
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2026-11-20 17:43 UTC by OSIDB Bzimport
Modified: 2026-11-23 14:57 UTC (History)
2 users (show)

Fixed In Version:
Clone Of:
Environment:
Last Closed:
Embargoed:


Attachments (Terms of Use)

Description OSIDB Bzimport 2026-11-20 17:43:21 UTC
* subj: [vs-plain] rsyslog imdtls late DTLS handshake bypasses imdtls cves: GHSA-4chq-f2r9-5jp8-R3    | CVE-2026-129834

PRIVATE — embargoed distributor notice

Issue R3: late DTLS handshake bypasses imdtls permitted-peer check.

With tls.authmode=name or fingerprint and tls.permittedpeer, a
CA-signed but non-permitted client can pace the final DTLS handshake
flight so SSL_accept returns before completion. Completion during
SSL_read can then process application data without the manual
permitted-peer check, allowing message injection into the pinned
input. This path was reproduced with a short configured timeout in
name and fingerprint modes on public main using OpenSSL 3.0.13 and
3.5.5; other timing, kernel, and OpenSSL combinations have not all
been established. GHSA-8v8w-f8wf-475j / PR #7617 closed sessions after
a failed check; this path skips the check.

Affected versions: rsyslog >= 8.2402.0. Proposed Medium 4.3,
CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:U/C:N/I:L/A:N; CWE-295. A CA-signed but
non-permitted client certificate is required.
Reporter credit: fairuzan. CVE requested; assignment pending (GitHub
request event 1355640). The primary combined-advisory score is High
7.5 for the R1/R2 availability paths; R3 has its distinct conditional
integrity subscore.

Restrict access to the optional imdtls input and tightly control
client-certificate issuance until the daily stable fix is available.

The attached source-only patch is the common production fix for the
three separately notified R1/R2/R3 findings under this one GHSA. Apply
it once against base a6c1f4023df4f4e783158ea3837796dc0ef45e4e, or a
main tree with unchanged plugins/imdtls/imdtls.c. It was validated at
private PR #11 head f18d0bd694a23ac3deff50f075b3e5748c9e6cda. Patch:
GHSA-4chq-f2r9-5jp8-source-only.patch; 13,137 bytes; SHA-256
5978bdfc2a3bf4d9029cdb2412c7a294fb678d106972f0de013b526472b1262e. The
source paths overlap; this is one shared patch, not three
independently composable patches.

Proposed public disclosure date/time: 2026-11-17 at 16:00 UTC (17:00
CET / 11:00 EST). Keep this report and patch confidential until the
coordinated public disclosure. Fixed version: 2026-11-17 daily stable;
package availability is not yet claimed.

** 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


Note You need to log in before you can comment on or make changes to this bug.