Package: perl
Version: 5.20.2-3+deb8u9
Severity: important
Tags: upstream patch

Dear Maintainer,
Sys::Syslog module is not thread-safe, reopening syslog connection
(could be internal/automatic after transient transport error, without user 
calling openlog/closelog) can crash multithreaded process 
(Apache event MPM with mod_perl in my case).
You can find upstream bug report at 
https://rt.perl.org/Public/Bug/Display.html?id=132679 ,
attached patch (serializing access to shared variable with straightforward 
locking)
has been tested on jessie.

-- System Information:
Debian Release: 8.10
  APT prefers oldstable-updates
  APT policy: (860, 'oldstable-updates'), (850, 'oldstable')
Architecture: amd64 (x86_64)
Foreign Architectures: i386

Kernel: Linux 3.16.0-4-amd64 (SMP w/4 CPU cores)
Locale: LANG=en_US.UTF-8, LC_CTYPE=en_US.UTF-8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/bash
Init: systemd (via /run/systemd/system)

Versions of packages perl depends on:
ii  dpkg          1.17.27
ii  libbz2-1.0    1.0.6-7+b3
ii  libc6         2.19-18+deb8u10
ii  libdb5.3      5.3.28-9+deb8u1
ii  libgdbm3      1.8.3-13.1
ii  perl-base     5.20.2-3+deb8u9
ii  perl-modules  5.20.2-3+deb8u9
ii  zlib1g        1:1.2.8.dfsg-2+b1

Versions of packages perl recommends:
ii  netbase  5.3
ii  rename   0.20-3

Versions of packages perl suggests:
pn  libterm-readline-gnu-perl | libterm-readline-perl-perl  <none>
ii  make                                                    4.0-8.1
ii  perl-doc                                                5.20.2-3+deb8u9

-- no debconf information
Index: perl-5.20.2/cpan/Sys-Syslog/Syslog.xs
===================================================================
--- perl-5.20.2.orig/cpan/Sys-Syslog/Syslog.xs
+++ perl-5.20.2/cpan/Sys-Syslog/Syslog.xs
@@ -31,6 +31,9 @@
 
 static SV *ident_svptr;
 
+#ifdef USE_ITHREADS
+STATIC perl_mutex ident_mutex;
+#endif
 
 #ifndef LOG_FAC
 #define LOG_FACMASK     0x03f8
@@ -102,9 +105,21 @@ openlog_xs(ident, option, facility)
         STRLEN len;
         char*  ident_pv;
     CODE:
+#ifdef USE_ITHREADS
+	MUTEX_LOCK(&ident_mutex);
+#endif
+        if (ident_svptr) {
+        	closelog();
+            	SvREFCNT_dec(ident_svptr);
+                ident_svptr = NULL;
+        }
         ident_svptr = newSVsv(ident);
         ident_pv    = SvPV(ident_svptr, len);
         openlog(ident_pv, option, facility);
+#ifdef USE_ITHREADS
+	MUTEX_UNLOCK(&ident_mutex);
+#endif
+
 
 void
 syslog_xs(priority, message)
@@ -128,15 +143,25 @@ closelog_xs()
     PREINIT:
         U32 refcnt;
     CODE:
-        if (!ident_svptr)
-            return;
-        closelog();
-        refcnt = SvREFCNT(ident_svptr);
-        if (refcnt) {
-            SvREFCNT_dec(ident_svptr);
-            if (refcnt == 1)
+#ifdef USE_ITHREADS
+	MUTEX_LOCK(&ident_mutex);
+#endif
+        if (ident_svptr) {
+        	closelog();
+            	SvREFCNT_dec(ident_svptr);
                 ident_svptr = NULL;
         }
+#ifdef USE_ITHREADS
+	MUTEX_UNLOCK(&ident_mutex);
+#endif
+
+BOOT:
+{
+#ifdef USE_ITHREADS
+        MUTEX_INIT(&ident_mutex);
+#endif
+	ident_svptr = 0;
+}
 
 #else  /* HAVE_SYSLOG */
 

Reply via email to