22086045 libibmad used [s]random(3c) functions unsafely s11u3-sru
authorboris.chiu@oracle.com
Mon, 19 Sep 2016 15:30:46 -0700
branchs11u3-sru
changeset 6927 af9bb41e858d
parent 6908 df2381fc3597
child 6937 1366743d2272
22086045 libibmad used [s]random(3c) functions unsafely
components/open-fabrics/libibmad/patches/002-libibmad-diskmon_trid.patch
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/components/open-fabrics/libibmad/patches/002-libibmad-diskmon_trid.patch	Mon Sep 19 15:30:46 2016 -0700
@@ -0,0 +1,49 @@
+#This patch was developed both in-house and from outside. We plan to submit it
+#upstream, but do not yet have a target date for doing so
+#
+# HG changeset patch
+# Parent  b0c54b9f271e37d7b605138bcdd0c26844892c3d
+22086045 libibmad used [s]random(3c) functions unsafely
+
+diff -r b0c54b9f271e src/mad.c
+--- a/src/mad.c	Mon Aug 15 14:55:29 2016 -0700
++++ b/src/mad.c	Mon Aug 15 15:01:53 2016 -0700
[email protected]@ -41,6 +41,9 @@
+ #include <stdlib.h>
+ #include <string.h>
+ #include <time.h>
++#if defined(__SVR4) && defined(__sun)
++#include <pthread.h>
++#endif
+ #include <errno.h>
+ 
+ #include <infiniband/umad.h>
[email protected]@ -48,6 +51,10 @@
+ 
+ #include "mad_internal.h"
+ 
++#if defined(__SVR4) && defined(__sun)
++static pthread_mutex_t trid_mutex = PTHREAD_MUTEX_INITIALIZER;
++#endif
++
+ #undef DEBUG
+ #define DEBUG	if (ibdebug)	IBWARN
+ 
[email protected]@ -63,11 +70,17 @@
+ 	static uint64_t trid;
+ 	uint64_t next;
+ 
++#if defined(__SVR4) && defined(__sun)
++	(void) pthread_mutex_lock(&trid_mutex);
++#endif
+ 	if (!trid) {
+ 		srandom((int)time(0) * getpid());
+ 		trid = random();
+ 	}
+ 	next = ++trid;
++#if defined(__SVR4) && defined(__sun)
++	(void) pthread_mutex_unlock(&trid_mutex);
++#endif
+ 	next = GET_IB_USERLAND_TID(next);
+ 	return next;
+ }