Source: sslh
Version: 2.1.4-1
Severity: important
Tags: patch security
X-Debbugs-Cc: [email protected]

Hi,

I prepared a trixie fix for CVE-2025-52936 from upstream commit
0fe9bd5a956a123342ff12352b25bff8025dac69. PID-file creation now uses
O_NOFOLLOW and checks writes. The tested trixie debdiff is attached.
The tracker lists 2.1.4-1 as vulnerable with no-dsa (Minor issue).
The earlier BTS report #1108284 is archived.

Both builds passed; the existing suite passed 97 TAP assertions on
each. Lintian output was empty on both builds.

Hopefully it helps for the next trixie point release! Happy to
adjust anything

Dickson

Prepared with AI assistance (OpenAI Codex) and reviewed by me
before sending.
diff -Nru '--exclude=.pc' inspection/common.c packaged/common.c
--- inspection/common.c	2024-06-26 17:17:48.000000000 +0000
+++ packaged/common.c	2026-11-26 10:43:28.589663782 +0000
@@ -849,24 +849,44 @@
 /* Writes my PID */
 void write_pid_file(const char* pidfile)
 {
-    FILE *f;
-    int res;
+    int fd;
+    char pidbuf[32];
+    size_t len, written = 0;
+    ssize_t res;
 
-    f = fopen(pidfile, "w");
-    if (!f) {
-        print_message(msg_system_error, "write_pid_file: %s: %s\n", pidfile, strerror(errno));
+    /* Format PID as string */
+    len = snprintf(pidbuf, sizeof(pidbuf), "%d\n", getpid());
+    if (len >= sizeof(pidbuf)) {
+        print_message(msg_system_error, "write_pid_file: PID string too long\n");
         return;
     }
 
-    res = fprintf(f, "%d\n", getpid());
-    if (res < 0) {
-        print_message(msg_system_error, "write_pid_file: fprintf: %s\n", strerror(errno));
+    /* Open file with O_NOFOLLOW to prevent symlink attacks */
+    fd = open(pidfile, O_WRONLY | O_CREAT | O_TRUNC
+#ifdef O_NOFOLLOW
+                | O_NOFOLLOW
+#endif
+                ,0644);
+
+    if (fd == -1) {
+        print_message(msg_system_error, "write_pid_file: %s: %s\n", pidfile, strerror(errno));
         return;
     }
 
-    res = fclose(f);
-    if (res == EOF) {
-        print_message(msg_system_error, "write_pid_file: fclose: %s\n", strerror(errno));
-        return;
+    /* Write PID to file with proper error handling */
+    while (written < len) {
+        res = write(fd, pidbuf + written, len - written);
+        if (res == -1) {
+            if (errno == EINTR || errno == EAGAIN)
+                continue;
+            print_message(msg_system_error, "write_pid_file: write: %s\n", strerror(errno));
+            break;
+        }
+        written += res;
+    }
+
+    /* Close file */
+    if (close(fd) == -1) {
+        print_message(msg_system_error, "write_pid_file: close: %s\n", strerror(errno));
     }
 }
diff -Nru '--exclude=.pc' inspection/debian/changelog packaged/debian/changelog
--- inspection/debian/changelog	2025-01-05 18:59:07.000000000 +0000
+++ packaged/debian/changelog	2026-11-26 10:43:28.598663886 +0000
@@ -1,3 +1,9 @@
+sslh (2.1.4-1+deb13u1) trixie; urgency=medium
+
+  * Backport upstream fix for CVE-2025-52936 (reject PID file symlinks).
+
+ -- Dickson Wu <[email protected]>  Wed, 25 Nov 2026 23:15:00 +0000
+
 sslh (2.1.4-1) unstable; urgency=medium
 
   * New upstream release.
diff -Nru '--exclude=.pc' inspection/debian/patches/CVE-2025-52936.patch packaged/debian/patches/CVE-2025-52936.patch
--- inspection/debian/patches/CVE-2025-52936.patch	1970-01-01 00:00:00.000000000 +0000
+++ packaged/debian/patches/CVE-2025-52936.patch	2026-11-26 10:45:23.990992015 +0000
@@ -0,0 +1,65 @@
+Description: Refuse symlinked PID files and handle writes explicitly
+Origin: upstream, https://github.com/yrutschle/sslh/commit/0fe9bd5a956a123342ff12352b25bff8025dac69
+Bug-Debian: https://bugs.debian.org/1108284
+Applied-Upstream: 0fe9bd5a956a123342ff12352b25bff8025dac69
+Last-Update: 2026-11-25
+
+--- a/common.c
++++ b/common.c
+@@ -849,24 +849,44 @@ void drop_privileges(const char* user_name, const char* chroot_path)
+ /* Writes my PID */
+ void write_pid_file(const char* pidfile)
+ {
+-    FILE *f;
+-    int res;
++    int fd;
++    char pidbuf[32];
++    size_t len, written = 0;
++    ssize_t res;
++
++    /* Format PID as string */
++    len = snprintf(pidbuf, sizeof(pidbuf), "%d\n", getpid());
++    if (len >= sizeof(pidbuf)) {
++        print_message(msg_system_error, "write_pid_file: PID string too long\n");
++        return;
++    }
+ 
+-    f = fopen(pidfile, "w");
+-    if (!f) {
++    /* Open file with O_NOFOLLOW to prevent symlink attacks */
++    fd = open(pidfile, O_WRONLY | O_CREAT | O_TRUNC
++#ifdef O_NOFOLLOW
++                | O_NOFOLLOW
++#endif
++                ,0644);
++
++    if (fd == -1) {
+         print_message(msg_system_error, "write_pid_file: %s: %s\n", pidfile, strerror(errno));
+         return;
+     }
+ 
+-    res = fprintf(f, "%d\n", getpid());
+-    if (res < 0) {
+-        print_message(msg_system_error, "write_pid_file: fprintf: %s\n", strerror(errno));
+-        return;
++    /* Write PID to file with proper error handling */
++    while (written < len) {
++        res = write(fd, pidbuf + written, len - written);
++        if (res == -1) {
++            if (errno == EINTR || errno == EAGAIN)
++                continue;
++            print_message(msg_system_error, "write_pid_file: write: %s\n", strerror(errno));
++            break;
++        }
++        written += res;
+     }
+ 
+-    res = fclose(f);
+-    if (res == EOF) {
+-        print_message(msg_system_error, "write_pid_file: fclose: %s\n", strerror(errno));
+-        return;
++    /* Close file */
++    if (close(fd) == -1) {
++        print_message(msg_system_error, "write_pid_file: close: %s\n", strerror(errno));
+     }
+ }
diff -Nru '--exclude=.pc' inspection/debian/patches/series packaged/debian/patches/series
--- inspection/debian/patches/series	2024-09-08 21:31:37.000000000 +0000
+++ packaged/debian/patches/series	2026-11-26 10:43:28.591663805 +0000
@@ -5,3 +5,4 @@
 t_verbose_no_opt
 fix-missing-havelandlock-template
 avoid_blocking_on_data
+CVE-2025-52936.patch

Reply via email to