19187537 iberror() of open-fabrics dumps core because of buffer overrun
authorboris.chiu@oracle.com
Mon, 03 Nov 2014 13:22:00 -0800
changeset 2187 391c8a50fa82
parent 2186 7efbe05bf862
child 2188 bbabf4f00a89
19187537 iberror() of open-fabrics dumps core because of buffer overrun 19195181 wrong handling of getaddrinfo() retval in open-fabrics dumps core 19448949 libibverbs cleanup incomplete
components/open-fabrics/infiniband-diags/patches/base.patch
components/open-fabrics/libibverbs/patches/base.patch
components/open-fabrics/libibverbs/solaris_compatibility.c
components/open-fabrics/perftest/patches/base.patch
--- a/components/open-fabrics/infiniband-diags/patches/base.patch	Fri Oct 31 07:12:22 2014 -0700
+++ b/components/open-fabrics/infiniband-diags/patches/base.patch	Mon Nov 03 13:22:00 2014 -0800
@@ -1,3 +1,6 @@
+# This patch was developed in-house. Since it is Solaris-specific,
+# it is not suitable for upstream.
+#
 diff -r -u /tmp/infiniband-diags-1.5.8/Makefile.am infiniband-diags-1.5.8/Makefile.am
 --- /tmp/infiniband-diags-1.5.8/Makefile.am	Wed Feb 16 02:13:21 2011
 +++ infiniband-diags-1.5.8/Makefile.am	Fri Feb 25 03:09:22 2011
@@ -1928,7 +1931,18 @@
 diff -r -u /tmp/infiniband-diags-1.5.8/src/ibdiag_common.c infiniband-diags-1.5.8/src/ibdiag_common.c
 --- /tmp/infiniband-diags-1.5.8/src/ibdiag_common.c	Wed Feb 16 02:13:21 2011
 +++ infiniband-diags-1.5.8/src/ibdiag_common.c	Tue May  3 13:50:05 2011
[email protected]@ -330,7 +330,7 @@
[email protected]@ -322,15 +322,17 @@
+ 	char buf[512];
+ 	va_list va;
+ 	int n;
++	int bufsz;
+ 
+ 	va_start(va, msg);
+-	n = vsprintf(buf, msg, va);
++	bufsz = strlen(msg) < sizeof (buf) ? strlen(msg) : sizeof (buf);
++	n = vsnprintf(buf, bufsz, msg, va);
+ 	va_end(va);
+ 	buf[n] = 0;
  
  	if (ibdebug)
  		printf("%s: iberror: [pid %d] %s: failed: %s\n",
--- a/components/open-fabrics/libibverbs/patches/base.patch	Fri Oct 31 07:12:22 2014 -0700
+++ b/components/open-fabrics/libibverbs/patches/base.patch	Mon Nov 03 13:22:00 2014 -0800
@@ -1,3 +1,6 @@
+# This patch was developed in-house. Since it is Solaris-specific,
+# it is not suitable for upstream.
+#
 diff -r -u /tmp/846623/libibverbs-1.1.4/Makefile.am libibverbs-1.1.4/Makefile.am
 --- /tmp/846623/libibverbs-1.1.4/Makefile.am	Thu Feb  3 01:53:17 2011
 +++ libibverbs-1.1.4/Makefile.am	Fri Feb 11 04:02:12 2011
@@ -2524,6 +2527,27 @@
  device_list.o: examples/device_list.c
  @[email protected]	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT device_list.o -MD -MP -MF $(DEPDIR)/device_list.Tpo -c -o device_list.o `test -f 'examples/device_list.c' || echo '$(srcdir)/'`examples/device_list.c
  @[email protected]	$(AM_V_at)$(am__mv) $(DEPDIR)/device_list.Tpo $(DEPDIR)/device_list.Po
+diff -r -u /tmp/846623/libibverbs-1.1.4/examples/uc_pingpong.c libibverbs-1.1.4/examples/uc_pingpong.c
+--- /tmp/846623/libibverbs-1.1.4/examples/uc_pingpong.c	Thu Mar 10 06:58:21 2011
++++ libibverbs-1.1.4/examples/uc_pingpong.c	Tue Aug 19 10:46:28 2014
[email protected]@ -144,7 +144,7 @@
+ 
+ 	n = getaddrinfo(servername, service, &hints, &res);
+ 
+-	if (n < 0) {
++	if (n != 0) {
+ 		fprintf(stderr, "%s for %s:%d\n", gai_strerror(n), servername, port);
+ 		free(service);
+ 		return NULL;
[email protected]@ -219,7 +219,7 @@
+ 
+ 	n = getaddrinfo(NULL, service, &hints, &res);
+ 
+-	if (n < 0) {
++	if (n != 0) {
+ 		fprintf(stderr, "%s for port %d\n", gai_strerror(n), port);
+ 		free(service);
+ 		return NULL;
 diff -r -u /tmp/846623/libibverbs-1.1.4/examples/asyncwatch.c libibverbs-1.1.4/examples/asyncwatch.c
 --- /tmp/846623/libibverbs-1.1.4/examples/asyncwatch.c	Thu Mar 10 06:58:21 2011
 +++ libibverbs-1.1.4/examples/asyncwatch.c	Fri Feb 11 04:02:18 2011
@@ -2916,51 +2940,87 @@
 diff -r -u /tmp/846623/libibverbs-1.1.4/examples/srq_pingpong.c libibverbs-1.1.4/examples/srq_pingpong.c
 --- /tmp/846623/libibverbs-1.1.4/examples/srq_pingpong.c	Thu Mar 10 06:58:21 2011
 +++ libibverbs-1.1.4/examples/srq_pingpong.c	Wed Jun  8 09:46:34 2011
[email protected]@ -171,6 +171,12 @@
[email protected]@ -165,8 +165,13 @@
+ 
+ 	n = getaddrinfo(servername, service, &hints, &res);
+ 
+-	if (n < 0) {
+-		fprintf(stderr, "%s for %s:%d\n", gai_strerror(n), servername, port);
++	if (n != 0) {
++		if (n == EAI_NONAME)
++			fprintf(stderr,
++			    "Name or service not known for %s:%d\n", servername, port);
++		else
++			fprintf(stderr,
++			    "%s for %s:%d\n", gai_strerror(n), servername, port);
+ 		free(service);
  		return NULL;
  	}
[email protected]@ -253,7 +258,7 @@
  
-+	if (n == EAI_NONAME) {
-+		fprintf(stderr, "Name or service not known for %s:%d\n", servername, port);
-+		free(service);
-+		return NULL;
-+	}
-+
- 	for (t = res; t; t = t->ai_next) {
- 		sockfd = socket(t->ai_family, t->ai_socktype, t->ai_protocol);
- 		if (sockfd >= 0) {
+ 	n = getaddrinfo(NULL, service, &hints, &res);
+ 
+-	if (n < 0) {
++	if (n != 0) {
+ 		fprintf(stderr, "%s for port %d\n", gai_strerror(n), port);
+ 		free(service);
+ 		return NULL;
 diff -r -u /tmp/846623/libibverbs-1.1.4/examples/ud_pingpong.c libibverbs-1.1.4/examples/ud_pingpong.c
 --- /tmp/846623/libibverbs-1.1.4/examples/ud_pingpong.c	Thu Mar 10 06:58:21 2011
 +++ libibverbs-1.1.4/examples/ud_pingpong.c	Wed Jun  8 09:46:34 2011
[email protected]@ -149,6 +149,12 @@
[email protected]@ -143,8 +143,13 @@
+ 
+ 	n = getaddrinfo(servername, service, &hints, &res);
+ 
+-	if (n < 0) {
+-		fprintf(stderr, "%s for %s:%d\n", gai_strerror(n), servername, port);
++	if (n != 0) {
++		if (n == EAI_NONAME)
++			fprintf(stderr,
++			    "Name or service not known for %s:%d\n", servername, port);
++		else
++			fprintf(stderr,
++			    "%s for %s:%d\n", gai_strerror(n), servername, port);
+ 		free(service);
  		return NULL;
  	}
[email protected]@ -217,7 +222,7 @@
  
-+	if (n == EAI_NONAME) {
-+		fprintf(stderr, "Name or service not known for %s:%d\n", servername, port);
-+		free(service);
-+		return NULL;
-+	}
-+
- 	for (t = res; t; t = t->ai_next) {
- 		sockfd = socket(t->ai_family, t->ai_socktype, t->ai_protocol);
- 		if (sockfd >= 0) {
+ 	n = getaddrinfo(NULL, service, &hints, &res);
+ 
+-	if (n < 0) {
++	if (n != 0) {
+ 		fprintf(stderr, "%s for port %d\n", gai_strerror(n), port);
+ 		free(service);
+ 		return NULL;
 diff -r -u /tmp/846623/libibverbs-1.1.4/examples/rc_pingpong.c libibverbs-1.1.4/examples/rc_pingpong.c
 --- /tmp/846623/libibverbs-1.1.4/examples/rc_pingpong.c	Thu Mar 10 06:58:21 2011
 +++ libibverbs-1.1.4/examples/rc_pingpong.c	Wed Jun  8 09:46:34 2011
[email protected]@ -161,6 +161,12 @@
[email protected]@ -155,8 +155,13 @@
+ 
+ 	n = getaddrinfo(servername, service, &hints, &res);
+ 
+-	if (n < 0) {
+-		fprintf(stderr, "%s for %s:%d\n", gai_strerror(n), servername, port);
++	if (n != 0) {
++		if (n == EAI_NONAME)
++			fprintf(stderr,
++			    "Name or service not known for %s:%d\n", servername, port);
++		else
++			fprintf(stderr,
++			    "%s for %s:%d\n", gai_strerror(n), servername, port);
+ 		free(service);
  		return NULL;
  	}
[email protected]@ -230,7 +235,7 @@
  
-+	if (n == EAI_NONAME) {
-+		fprintf(stderr, "Name or service not known for %s:%d\n", servername, port);
-+		free(service);
-+		return NULL;
-+	}
-+
- 	for (t = res; t; t = t->ai_next) {
- 		sockfd = socket(t->ai_family, t->ai_socktype, t->ai_protocol);
- 		if (sockfd >= 0) {
+ 	n = getaddrinfo(NULL, service, &hints, &res);
+ 
+-	if (n < 0) {
++	if (n != 0) {
+ 		fprintf(stderr, "%s for port %d\n", gai_strerror(n), port);
+ 		free(service);
+ 		return NULL;
 diff -r -u /tmp/846623/libibverbs-1.1.4/examples/device_list.c libibverbs-1.1.4/examples/device_list.c
 --- /tmp/846623/libibverbs-1.1.4/examples/device_list.c	Sun Nov  1 06:47:19 2009
 +++ libibverbs-1.1.4/examples/device_list.c	Fri Feb 11 04:02:18 2011
--- a/components/open-fabrics/libibverbs/solaris_compatibility.c	Fri Oct 31 07:12:22 2014 -0700
+++ b/components/open-fabrics/libibverbs/solaris_compatibility.c	Mon Nov 03 13:22:00 2014 -0800
@@ -371,13 +371,8 @@
 	uverbs_cache_info_t	info;
 	int			dev_num, fd, i, bufsize, hca_cnt;
 	char			uverbs_devpath[MAXPATHLEN];
-#ifndef	IB_USER_VERBS_V2_IN_V1
 	sol_uverbs_info_t	*uverbs_infop;
 	sol_uverbs_hca_info_t	*hca_infop;
-#else
-	sol_uverbs_info_v2_t	*uverbs_infop;
-	sol_uverbs_hca_info_v2_t	*hca_infop;
-#endif
 	char *buf;
 
 	snprintf(uverbs_devpath, MAXPATHLEN, "%s/%s%d",
@@ -394,20 +389,11 @@
 		goto error_exit1;
 	}
 
-#ifndef	IB_USER_VERBS_V2_IN_V1
 	bufsize = sizeof (sol_uverbs_info_t) + sizeof (sol_uverbs_hca_info_t) *
 	    MAX_HCAS;
-#else
-	bufsize = sizeof (sol_uverbs_info_v2_t) +
-	    sizeof (sol_uverbs_hca_info_v2_t) * MAX_HCAS;
-#endif
 	buf = malloc(bufsize);
 	memset(buf, 0, bufsize);
-#ifndef	IB_USER_VERBS_V2_IN_V1
 	uverbs_infop = (sol_uverbs_info_t *)buf;
-#else
-	uverbs_infop = (sol_uverbs_info_v2_t *)buf;
-#endif
 	uverbs_infop->uverbs_hca_cnt = MAX_HCAS;
 
 	if (ioctl(fd, UVERBS_IOCTL_GET_HCA_INFO, uverbs_infop) != 0) {
--- a/components/open-fabrics/perftest/patches/base.patch	Fri Oct 31 07:12:22 2014 -0700
+++ b/components/open-fabrics/perftest/patches/base.patch	Mon Nov 03 13:22:00 2014 -0800
@@ -1,3 +1,6 @@
+# This patch was developed in-house. Since it is Solaris-specific,
+# it is not suitable for upstream.
+#
 diff -r -u /tmp/perftest-1.3.0/Makefile perftest-1.3.0/Makefile
 --- /tmp/perftest-1.3.0/Makefile	Thu Jan 20 01:37:35 2011
 +++ perftest-1.3.0/Makefile	Fri Feb 11 04:12:45 2011
@@ -214,9 +217,12 @@
  
  #include <infiniband/verbs.h>
  #include <rdma/rdma_cma.h>
[email protected]@ -144,7 +147,7 @@
[email protected]@ -142,9 +145,9 @@
  
- 	if (n < 0) {
+ 	n = getaddrinfo(data->servername, service, &hints, &res);
+ 
+-	if (n < 0) {
++	if (n != 0) {
  		fprintf(stderr, "%d:%s: %s for %s:%d\n", 
 -				pid, __func__, gai_strerror(n),
 +				(int)pid, __func__, gai_strerror(n),
@@ -343,11 +349,13 @@
  			free(data->rem_dest);
  			goto err;
  		}
[email protected]@ -347,7 +350,7 @@
[email protected]@ -346,8 +349,8 @@
+ 	if (asprintf(&service, "%d", data->port) < 0)
  		goto err5;
  
- 	if ( (n = getaddrinfo(NULL, service, &hints, &res)) < 0 ) {
+-	if ( (n = getaddrinfo(NULL, service, &hints, &res)) < 0 ) {
 -		fprintf(stderr, "%d:%s: %s for port %d\n", pid, __func__, 
++	if ( (n = getaddrinfo(NULL, service, &hints, &res) != 0) ) {
 +		fprintf(stderr, "%d:%s: %s for port %d\n", (int)pid, __func__, 
  					gai_strerror(n), data->port);
  		goto err5;
@@ -828,6 +836,15 @@
  				return 1;
  			}
  			ccnt += 1;
[email protected]@ -1265,7 +1277,7 @@
+ 		
+ 		write(data.sockfd, "done", sizeof "done");
+ 		close(data.sockfd);
+-		
++
+ 	}
+ 	
+ 	print_report(iters, data.size, duplex, tposted, tcompleted);
 diff -r -u /tmp/perftest-1.3.0/rdma_lat.c perftest-1.3.0/rdma_lat.c
 --- /tmp/perftest-1.3.0/rdma_lat.c	Wed Apr  7 09:44:33 2010
 +++ perftest-1.3.0/rdma_lat.c	Fri Feb 11 04:12:46 2011
@@ -874,9 +891,12 @@
  			&rem_dest->psn, &rem_dest->rkey, &rem_dest->vaddr);
  
  	if (parsed != 5) {
[email protected]@ -220,7 +229,7 @@
[email protected]@ -218,9 +227,9 @@
  
- 	if (n < 0) {
+ 	n = getaddrinfo(data->servername, service, &hints, &res);
+ 
+-	if (n < 0) {
++	if (n != 0) {
  		fprintf(stderr, "%d:%s: %s for %s:%d\n", 
 -				pid, __func__, gai_strerror(n),
 +				(int)pid, __func__, gai_strerror(n),
@@ -962,11 +982,13 @@
  			goto err3;
  		}
  		ctx = pp_init_ctx(data->ib_dev, data);
[email protected]@ -393,7 +402,7 @@
[email protected]@ -392,8 +401,8 @@
+ 	if (asprintf(&service, "%d", data->port) < 0)
  		goto err5;
  
- 	if ( (n = getaddrinfo(NULL, service, &hints, &res)) < 0 ) {
+-	if ( (n = getaddrinfo(NULL, service, &hints, &res)) < 0 ) {
 -		fprintf(stderr, "%d:%s: %s for port %d\n", pid, __func__, 
++	if ( (n = getaddrinfo(NULL, service, &hints, &res) != 0) ) {
 +		fprintf(stderr, "%d:%s: %s for port %d\n", (int)pid, __func__, 
  					gai_strerror(n), data->port);
  		goto err5;
@@ -1384,6 +1406,24 @@
  	} else {
  
  		switch (params->mtu) {
[email protected]@ -791,7 +807,7 @@
+ 
+ 	n = getaddrinfo(servername, service, &hints, &res);
+ 
+-	if (n < 0) {
++	if (n != 0) {
+ 		fprintf(stderr, "%s for %s:%d\n", gai_strerror(n), servername, port);
+ 		return n;
+ 	}
[email protected]@ -835,7 +851,7 @@
+ 
+ 	n = getaddrinfo(NULL, service, &hints, &res);
+ 
+-	if (n < 0) {
++	if (n != 0) {
+ 		fprintf(stderr, "%s for port %d\n", gai_strerror(n), port);
+ 		return n;
+ 	}
 @@ -869,7 +885,6 @@
  		close(sockfd);
  		return connfd;