25845f
commit 8e31cafb268938729a1314806a924d73fb1991c5
25845f
Author: Torvald Riegel <triegel@redhat.com>
25845f
Date:   Wed Dec 21 13:37:19 2016 +0100
25845f
25845f
    Clear list of acquired robust mutexes in the child process after forking.
25845f
    
25845f
    Robust mutexes acquired at the time of a call to fork() do not remain
25845f
    acquired by the forked child process.  We have to clear the list of
25845f
    acquired robust mutexes before registering this list with the kernel;
25845f
    otherwise, if some of the robust mutexes are process-shared, the parent
25845f
    process can alter the child's robust mutex list, which can lead to
25845f
    deadlocks or even modification of memory that may not be occupied by a
25845f
    mutex anymore.
25845f
    
25845f
            [BZ #19402]
25845f
            * sysdeps/nptl/fork.c (__libc_fork): Clear list of acquired robust
25845f
            mutexes.
25845f
25845f
Index: glibc-2.17-c758a686/nptl/sysdeps/unix/sysv/linux/fork.c
25845f
===================================================================
25845f
--- glibc-2.17-c758a686.orig/nptl/sysdeps/unix/sysv/linux/fork.c
25845f
+++ glibc-2.17-c758a686/nptl/sysdeps/unix/sysv/linux/fork.c
25845f
@@ -161,12 +161,20 @@ __libc_fork (void)
25845f
 #endif
25845f
 
25845f
 #ifdef __NR_set_robust_list
25845f
-      /* Initialize the robust mutex list which has been reset during
25845f
-	 the fork.  We do not check for errors since if it fails here
25845f
-	 it failed at process start as well and noone could have used
25845f
-	 robust mutexes.  We also do not have to set
25845f
-	 self->robust_head.futex_offset since we inherit the correct
25845f
-	 value from the parent.  */
25845f
+      /* Initialize the robust mutex list setting in the kernel which has
25845f
+	 been reset during the fork.  We do not check for errors because if
25845f
+	 it fails here, it must have failed at process startup as well and
25845f
+	 nobody could have used robust mutexes.
25845f
+	 Before we do that, we have to clear the list of robust mutexes
25845f
+	 because we do not inherit ownership of mutexes from the parent.
25845f
+	 We do not have to set self->robust_head.futex_offset since we do
25845f
+	 inherit the correct value from the parent.  We do not need to clear
25845f
+	 the pending operation because it must have been zero when fork was
25845f
+	 called.  */
25845f
+# ifdef __PTHREAD_MUTEX_HAVE_PREV
25845f
+      self->robust_prev = &self->robust_head;
25845f
+# endif
25845f
+      self->robust_head.list = &self->robust_head;
25845f
 # ifdef SHARED
25845f
       if (__builtin_expect (__libc_pthread_functions_init, 0))
25845f
 	PTHFCT_CALL (ptr_set_robust, (self));