[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#990803: unblock: libvdestack/0.1.2-1 debdiff



I forgot to attach the debdiff

	renzo
diff -Nru libvdestack-0.1.1/CMakeLists.txt libvdestack-0.1.2/CMakeLists.txt
--- libvdestack-0.1.1/CMakeLists.txt	2020-12-05 17:00:01.000000000 +0100
+++ libvdestack-0.1.2/CMakeLists.txt	2021-06-29 16:29:41.000000000 +0200
@@ -2,7 +2,7 @@
 project("vdestack"
     DESCRIPTION "A network namespace as a library, i.e. Internet of Threads through Network Namespaces."
     HOMEPAGE_URL "https://github.com/rd235/libvdestack";
-    VERSION 0.1.0
+    VERSION 0.1.2
     LANGUAGES C)
 
 include(GNUInstallDirs)
@@ -10,8 +10,8 @@
 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_FORTIFY_SOURCE=2 -O2 -pedantic -Wall -Wextra")
 
 set(CMAKE_REQUIRED_QUIET TRUE)
-set(LIBS_REQUIRED vdeplug cap execs)
-set(HEADERS_REQUIRED libvdeplug.h sys/capability.h execs.h)
+set(LIBS_REQUIRED vdeplug cap execs pthread)
+set(HEADERS_REQUIRED libvdeplug.h sys/capability.h execs.h pthread.h)
 set(PROJECT_PC_REQUIRES "vdeplug cap execs")
 
 foreach(THISLIB IN LISTS LIBS_REQUIRED)
@@ -32,7 +32,7 @@
 include_directories(${CMAKE_CURRENT_SOURCE_DIR})
 
 add_library(vdestack SHARED vdestack.c)
-target_link_libraries(vdestack -lcap -lexecs -lvdeplug)
+target_link_libraries(vdestack -lcap -lexecs -lvdeplug -lpthread)
 
 set_target_properties(vdestack PROPERTIES VERSION ${PROJECT_VERSION}
         SOVERSION ${PROJECT_VERSION_MAJOR})
diff -Nru libvdestack-0.1.1/debian/changelog libvdestack-0.1.2/debian/changelog
--- libvdestack-0.1.1/debian/changelog	2021-01-08 19:52:31.000000000 +0100
+++ libvdestack-0.1.2/debian/changelog	2021-07-07 18:27:00.000000000 +0200
@@ -1,3 +1,9 @@
+libvdestack (0.1.2-1) unstable; urgency=medium
+
+  * New Upstream Release: fix a race condition bug
+
+ -- Renzo Davoli <renzo@cs.unibo.it>  Wed, 07 Jul 2021 18:27:00 +0200
+
 libvdestack (0.1.1-1) unstable; urgency=medium
 
   * New Upstream Release
diff -Nru libvdestack-0.1.1/man/libvdestack.3 libvdestack-0.1.2/man/libvdestack.3
--- libvdestack-0.1.1/man/libvdestack.3	2020-12-05 17:00:01.000000000 +0100
+++ libvdestack-0.1.2/man/libvdestack.3	2021-06-29 16:29:41.000000000 +0200
@@ -20,9 +20,9 @@
 .\" Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
 .\" MA 02110-1301 USA.
 .\"
-.\" generated with Ronn-NG/v0.8.0
-.\" http://github.com/apjanke/ronn-ng/tree/0.8.0
-.TH "LIBVDESTACK" "3" "December 2019" "VirtualSquare"
+.\" generated with Ronn-NG/v0.9.1
+.\" http://github.com/apjanke/ronn-ng/tree/0.9.1
+.TH "LIBVDESTACK" "3" "June 2021" "VirtualSquare"
 .SH "NAME"
 vde_addstack, vde_delstack, vde_stackcmd, vde_msocket \- vde network namespace as a user library
 .SH "SYNOPSIS"
@@ -44,7 +44,7 @@
 .P
 \fBvde_delstack\fR destroys a vdestack when it is no longer needed\.
 .P
-\fBvde_stackcmd\fR run a command or a comma separated sequence of commands in the private network namespace\. The purpose of this function is to configure the networking parameters and options (e\.g\. IP address, routing)\. For security reasons, commands must be specified using full pathnames\.
+\fBvde_stackcmd\fR run a command or a comma separated sequence of commands in the private network namespace\. The purpose of this function is to configure the networking parameters and options (e\.g\. IP address, routing)\. For security reasons, commands must be specified using full pathnames\. Do not use this function to start long lasting or non terminating programs, the caller waits for the termination of the command sequence\.
 .P
 \fBvde_msocket\fR has the same semantics of \fBsocket\fR(2) except that the socket is defined in the scope of the network namespace whose descriptor is the first argument\. The remaining arguments are those defined in socket(2)\.
 .P
@@ -84,6 +84,6 @@
 .SH "SEE ALSO"
 \fBsocket\fR(2), \fBvde_plug\fR(1)
 .SH "BUGS"
-Bug reports should be addressed to \fI\%mailto:info@virtualsquare\.org\fR
+Bug reports should be addressed to \fIinfo@virtualsquare\.org\fR
 .SH "AUTHOR"
 VirtualSquare\. Project leader: Renzo Davoli\.
diff -Nru libvdestack-0.1.1/man/libvdestack.3.ronn libvdestack-0.1.2/man/libvdestack.3.ronn
--- libvdestack-0.1.1/man/libvdestack.3.ronn	2020-12-05 17:00:01.000000000 +0100
+++ libvdestack-0.1.2/man/libvdestack.3.ronn	2021-06-29 16:29:41.000000000 +0200
@@ -57,7 +57,8 @@
 
 `vde_stackcmd`  run  a  command or a comma separated sequence of commands in the private network namespace.  The purpose of
 this function is to configure the networking parameters and options (e.g. IP address, routing).   For  security  reasons,
-commands must be specified using full pathnames.
+commands must be specified using full pathnames. Do not use this function to start long lasting or non terminating programs,
+the caller waits for the termination of the command sequence.
 
 `vde_msocket`  has  the same semantics of `socket`(2) except that the socket is defined in the scope of the network namespace
 whose descriptor is the first argument. The remaining arguments are those defined in socket(2).
diff -Nru libvdestack-0.1.1/man/vde_addstack.3 libvdestack-0.1.2/man/vde_addstack.3
--- libvdestack-0.1.1/man/vde_addstack.3	2020-12-05 17:00:01.000000000 +0100
+++ libvdestack-0.1.2/man/vde_addstack.3	2021-06-29 16:29:41.000000000 +0200
@@ -20,9 +20,9 @@
 .\" Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
 .\" MA 02110-1301 USA.
 .\"
-.\" generated with Ronn-NG/v0.8.0
-.\" http://github.com/apjanke/ronn-ng/tree/0.8.0
-.TH "LIBVDESTACK" "3" "December 2019" "VirtualSquare"
+.\" generated with Ronn-NG/v0.9.1
+.\" http://github.com/apjanke/ronn-ng/tree/0.9.1
+.TH "LIBVDESTACK" "3" "June 2021" "VirtualSquare"
 .SH "NAME"
 vde_addstack, vde_delstack, vde_stackcmd, vde_msocket \- vde network namespace as a user library
 .SH "SYNOPSIS"
@@ -44,7 +44,7 @@
 .P
 \fBvde_delstack\fR destroys a vdestack when it is no longer needed\.
 .P
-\fBvde_stackcmd\fR run a command or a comma separated sequence of commands in the private network namespace\. The purpose of this function is to configure the networking parameters and options (e\.g\. IP address, routing)\. For security reasons, commands must be specified using full pathnames\.
+\fBvde_stackcmd\fR run a command or a comma separated sequence of commands in the private network namespace\. The purpose of this function is to configure the networking parameters and options (e\.g\. IP address, routing)\. For security reasons, commands must be specified using full pathnames\. Do not use this function to start long lasting or non terminating programs, the caller waits for the termination of the command sequence\.
 .P
 \fBvde_msocket\fR has the same semantics of \fBsocket\fR(2) except that the socket is defined in the scope of the network namespace whose descriptor is the first argument\. The remaining arguments are those defined in socket(2)\.
 .P
@@ -84,6 +84,6 @@
 .SH "SEE ALSO"
 \fBsocket\fR(2), \fBvde_plug\fR(1)
 .SH "BUGS"
-Bug reports should be addressed to \fI\%mailto:info@virtualsquare\.org\fR
+Bug reports should be addressed to \fIinfo@virtualsquare\.org\fR
 .SH "AUTHOR"
 VirtualSquare\. Project leader: Renzo Davoli\.
diff -Nru libvdestack-0.1.1/man/vde_delstack.3 libvdestack-0.1.2/man/vde_delstack.3
--- libvdestack-0.1.1/man/vde_delstack.3	2020-12-05 17:00:01.000000000 +0100
+++ libvdestack-0.1.2/man/vde_delstack.3	2021-06-29 16:29:41.000000000 +0200
@@ -20,9 +20,9 @@
 .\" Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
 .\" MA 02110-1301 USA.
 .\"
-.\" generated with Ronn-NG/v0.8.0
-.\" http://github.com/apjanke/ronn-ng/tree/0.8.0
-.TH "LIBVDESTACK" "3" "December 2019" "VirtualSquare"
+.\" generated with Ronn-NG/v0.9.1
+.\" http://github.com/apjanke/ronn-ng/tree/0.9.1
+.TH "LIBVDESTACK" "3" "June 2021" "VirtualSquare"
 .SH "NAME"
 vde_addstack, vde_delstack, vde_stackcmd, vde_msocket \- vde network namespace as a user library
 .SH "SYNOPSIS"
@@ -44,7 +44,7 @@
 .P
 \fBvde_delstack\fR destroys a vdestack when it is no longer needed\.
 .P
-\fBvde_stackcmd\fR run a command or a comma separated sequence of commands in the private network namespace\. The purpose of this function is to configure the networking parameters and options (e\.g\. IP address, routing)\. For security reasons, commands must be specified using full pathnames\.
+\fBvde_stackcmd\fR run a command or a comma separated sequence of commands in the private network namespace\. The purpose of this function is to configure the networking parameters and options (e\.g\. IP address, routing)\. For security reasons, commands must be specified using full pathnames\. Do not use this function to start long lasting or non terminating programs, the caller waits for the termination of the command sequence\.
 .P
 \fBvde_msocket\fR has the same semantics of \fBsocket\fR(2) except that the socket is defined in the scope of the network namespace whose descriptor is the first argument\. The remaining arguments are those defined in socket(2)\.
 .P
@@ -84,6 +84,6 @@
 .SH "SEE ALSO"
 \fBsocket\fR(2), \fBvde_plug\fR(1)
 .SH "BUGS"
-Bug reports should be addressed to \fI\%mailto:info@virtualsquare\.org\fR
+Bug reports should be addressed to \fIinfo@virtualsquare\.org\fR
 .SH "AUTHOR"
 VirtualSquare\. Project leader: Renzo Davoli\.
diff -Nru libvdestack-0.1.1/man/vde_msocket.3 libvdestack-0.1.2/man/vde_msocket.3
--- libvdestack-0.1.1/man/vde_msocket.3	2020-12-05 17:00:01.000000000 +0100
+++ libvdestack-0.1.2/man/vde_msocket.3	2021-06-29 16:29:41.000000000 +0200
@@ -20,9 +20,9 @@
 .\" Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
 .\" MA 02110-1301 USA.
 .\"
-.\" generated with Ronn-NG/v0.8.0
-.\" http://github.com/apjanke/ronn-ng/tree/0.8.0
-.TH "LIBVDESTACK" "3" "December 2019" "VirtualSquare"
+.\" generated with Ronn-NG/v0.9.1
+.\" http://github.com/apjanke/ronn-ng/tree/0.9.1
+.TH "LIBVDESTACK" "3" "June 2021" "VirtualSquare"
 .SH "NAME"
 vde_addstack, vde_delstack, vde_stackcmd, vde_msocket \- vde network namespace as a user library
 .SH "SYNOPSIS"
@@ -44,7 +44,7 @@
 .P
 \fBvde_delstack\fR destroys a vdestack when it is no longer needed\.
 .P
-\fBvde_stackcmd\fR run a command or a comma separated sequence of commands in the private network namespace\. The purpose of this function is to configure the networking parameters and options (e\.g\. IP address, routing)\. For security reasons, commands must be specified using full pathnames\.
+\fBvde_stackcmd\fR run a command or a comma separated sequence of commands in the private network namespace\. The purpose of this function is to configure the networking parameters and options (e\.g\. IP address, routing)\. For security reasons, commands must be specified using full pathnames\. Do not use this function to start long lasting or non terminating programs, the caller waits for the termination of the command sequence\.
 .P
 \fBvde_msocket\fR has the same semantics of \fBsocket\fR(2) except that the socket is defined in the scope of the network namespace whose descriptor is the first argument\. The remaining arguments are those defined in socket(2)\.
 .P
@@ -84,6 +84,6 @@
 .SH "SEE ALSO"
 \fBsocket\fR(2), \fBvde_plug\fR(1)
 .SH "BUGS"
-Bug reports should be addressed to \fI\%mailto:info@virtualsquare\.org\fR
+Bug reports should be addressed to \fIinfo@virtualsquare\.org\fR
 .SH "AUTHOR"
 VirtualSquare\. Project leader: Renzo Davoli\.
diff -Nru libvdestack-0.1.1/man/vde_stackcmd.3 libvdestack-0.1.2/man/vde_stackcmd.3
--- libvdestack-0.1.1/man/vde_stackcmd.3	2020-12-05 17:00:01.000000000 +0100
+++ libvdestack-0.1.2/man/vde_stackcmd.3	2021-06-29 16:29:41.000000000 +0200
@@ -20,9 +20,9 @@
 .\" Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
 .\" MA 02110-1301 USA.
 .\"
-.\" generated with Ronn-NG/v0.8.0
-.\" http://github.com/apjanke/ronn-ng/tree/0.8.0
-.TH "LIBVDESTACK" "3" "December 2019" "VirtualSquare"
+.\" generated with Ronn-NG/v0.9.1
+.\" http://github.com/apjanke/ronn-ng/tree/0.9.1
+.TH "LIBVDESTACK" "3" "June 2021" "VirtualSquare"
 .SH "NAME"
 vde_addstack, vde_delstack, vde_stackcmd, vde_msocket \- vde network namespace as a user library
 .SH "SYNOPSIS"
@@ -44,7 +44,7 @@
 .P
 \fBvde_delstack\fR destroys a vdestack when it is no longer needed\.
 .P
-\fBvde_stackcmd\fR run a command or a comma separated sequence of commands in the private network namespace\. The purpose of this function is to configure the networking parameters and options (e\.g\. IP address, routing)\. For security reasons, commands must be specified using full pathnames\.
+\fBvde_stackcmd\fR run a command or a comma separated sequence of commands in the private network namespace\. The purpose of this function is to configure the networking parameters and options (e\.g\. IP address, routing)\. For security reasons, commands must be specified using full pathnames\. Do not use this function to start long lasting or non terminating programs, the caller waits for the termination of the command sequence\.
 .P
 \fBvde_msocket\fR has the same semantics of \fBsocket\fR(2) except that the socket is defined in the scope of the network namespace whose descriptor is the first argument\. The remaining arguments are those defined in socket(2)\.
 .P
@@ -84,6 +84,6 @@
 .SH "SEE ALSO"
 \fBsocket\fR(2), \fBvde_plug\fR(1)
 .SH "BUGS"
-Bug reports should be addressed to \fI\%mailto:info@virtualsquare\.org\fR
+Bug reports should be addressed to \fIinfo@virtualsquare\.org\fR
 .SH "AUTHOR"
 VirtualSquare\. Project leader: Renzo Davoli\.
diff -Nru libvdestack-0.1.1/vdestack.c libvdestack-0.1.2/vdestack.c
--- libvdestack-0.1.1/vdestack.c	2020-12-05 17:00:01.000000000 +0100
+++ libvdestack-0.1.2/vdestack.c	2021-06-29 16:29:41.000000000 +0200
@@ -28,6 +28,7 @@
 #include <sched.h>
 #include <limits.h>
 #include <errno.h>
+#include <pthread.h>
 #include <sys/capability.h>
 #include <sys/prctl.h>
 #include <sys/ioctl.h>
@@ -74,6 +75,7 @@
 
 struct vdestack {
 	pid_t pid;
+	pthread_mutex_t mutex;
 	int cmdpipe[2]; // socketpair for commands;
 	pid_t cmdpid;
 	int sfd;
@@ -352,6 +354,9 @@
 	struct vdestack *stack = malloc(sizeof(*stack) + ifnameoklen + 1);
 
 	if (stack) {
+		if (pthread_mutex_init(&stack->mutex, NULL) != 0)
+			goto err_mutex;
+
 		stack->child_stack =
 			mmap(0, CHILD_STACK_SIZE, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0);
 		if (stack->child_stack == NULL)
@@ -392,6 +397,8 @@
 err_cmdpipe:
 	munmap(stack->child_stack, CHILD_STACK_SIZE);
 err_child_stack:
+	pthread_mutex_destroy(&stack->mutex);
+err_mutex:
 	free(stack);
 	return NULL;
 }
@@ -406,6 +413,7 @@
 	close(stack->cmdpipe[APPSIDE]);
 	waitpid(stack->pid, NULL, 0);
 	munmap(stack->child_stack, CHILD_STACK_SIZE);
+	pthread_mutex_destroy(&stack->mutex);
 	free(stack);
 }
 
@@ -414,13 +422,18 @@
 	struct vdecmd cmd = {argv, 0, 0, 0};
 	struct vdereply reply;
 
+	pthread_mutex_lock(&stack->mutex);
 	if (write(stack->cmdpipe[APPSIDE],  &cmd, sizeof(cmd)) < 0 ||
 			read(stack->cmdpipe[APPSIDE], &reply, sizeof(reply)) < 0)
-		return -1;
+		goto errmsg;
 
+	pthread_mutex_unlock(&stack->mutex);
 	if (reply.rval < 0)
 		errno = reply.err;
 	return reply.rval;
+errmsg:
+	pthread_mutex_unlock(&stack->mutex);
+	return -1;
 }
 
 /* parse the args, allowing multiple comma separated commands on a single line */
@@ -432,11 +445,16 @@
 	struct vdecmd cmd = {NULL, domain, type, protocol};
 	struct vdereply reply;
 
+	pthread_mutex_lock(&stack->mutex);
 	if (write(stack->cmdpipe[APPSIDE],  &cmd, sizeof(cmd)) < 0 ||
 			read(stack->cmdpipe[APPSIDE], &reply, sizeof(reply)) < 0)
-		return -1;
+		goto errmsg;
 
+	pthread_mutex_unlock(&stack->mutex);
 	if (reply.rval < 0)
 		errno = reply.err;
 	return reply.rval;
+errmsg:
+	pthread_mutex_unlock(&stack->mutex);
+	return -1;
 }

Reply to: