]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
Fix potential deadlock in output
authorVictor Julien <victor@inliniac.net>
Wed, 29 Apr 2015 13:03:23 +0000 (15:03 +0200)
committerVictor Julien <victor@inliniac.net>
Thu, 30 Apr 2015 10:53:39 +0000 (12:53 +0200)
Coverity:
** CID 1296115:  Program hangs  (ORDER_REVERSAL)
/src/tm-threads.c: 1670 in TmThreadClearThreadsFamily()

The problem is with the by default unused '%m' output parameter.
To get the thread vars it takes the tv_root_lock. This may already
be locked by the calling thread. Also, it could lead to a case of
wrong lock order between the tv_root_lock and the thread_store_lock.

Very unlikely to happen though.

As the %m param isn't really used (by default) this patch just
disables it.

src/util-debug.c

index 8283c99c5f37ca720667ac3dfe06a0385fbb4630..7a78987dda5d7a143113a1da4c5222642efded1f 100644 (file)
@@ -358,12 +358,19 @@ SCError SCLogMessage(SCLogLevel log_level, char **msg, const char *file,
                 substr = temp_fmt;
                 substr++;
                 break;
-
             case SC_LOG_FMT_TM:
                 temp_fmt[0] = '\0';
+/* disabled to prevent dead lock:
+ * log or alloc (which calls log on error) can call TmThreadsGetCallingThread
+ * which will lock tv_root_lock. This can happen while we already hold this
+ * lock. */
+#if 0
                 ThreadVars *tv = TmThreadsGetCallingThread();
                 cw = snprintf(temp, SC_LOG_MAX_LOG_MSG_LEN - (temp - *msg),
                               "%s%s", substr, ((tv != NULL)? tv->name: "UNKNOWN TM"));
+#endif
+                cw = snprintf(temp, SC_LOG_MAX_LOG_MSG_LEN - (temp - *msg),
+                              "%s%s", substr, "N/A");
                 if (cw < 0)
                     goto error;
                 temp += cw;
@@ -371,7 +378,6 @@ SCError SCLogMessage(SCLogLevel log_level, char **msg, const char *file,
                 substr = temp_fmt;
                 substr++;
                 break;
-
             case SC_LOG_FMT_LOG_LEVEL:
                 temp_fmt[0] = '\0';
                 s = SCMapEnumValueToName(log_level, sc_log_level_map);