9bb5d6
Use __pthread_attr_copy in mq_notify (bug 27896)
9bb5d6
9bb5d6
Make a deep copy of the pthread attribute object to remove a potential
9bb5d6
use-after-free issue.
9bb5d6
9bb5d6
(cherry picked from commit 42d359350510506b87101cf77202fefcbfc790cb)
9bb5d6
9bb5d6
# Conflicts:
9bb5d6
#	NEWS
9bb5d6
9bb5d6
diff --git a/sysdeps/unix/sysv/linux/mq_notify.c b/sysdeps/unix/sysv/linux/mq_notify.c
9bb5d6
index 3563e82cd4f4b552..c4091169306ffde8 100644
9bb5d6
--- a/sysdeps/unix/sysv/linux/mq_notify.c
9bb5d6
+++ b/sysdeps/unix/sysv/linux/mq_notify.c
9bb5d6
@@ -135,8 +135,11 @@ helper_thread (void *arg)
9bb5d6
 	    (void) __pthread_barrier_wait (&notify_barrier);
9bb5d6
 	}
9bb5d6
       else if (data.raw[NOTIFY_COOKIE_LEN - 1] == NOTIFY_REMOVED)
9bb5d6
-	/* The only state we keep is the copy of the thread attributes.  */
9bb5d6
-	free (data.attr);
9bb5d6
+	{
9bb5d6
+	  /* The only state we keep is the copy of the thread attributes.  */
9bb5d6
+	  pthread_attr_destroy (data.attr);
9bb5d6
+	  free (data.attr);
9bb5d6
+	}
9bb5d6
     }
9bb5d6
   return NULL;
9bb5d6
 }
9bb5d6
@@ -257,8 +260,7 @@ mq_notify (mqd_t mqdes, const struct sigevent *notification)
9bb5d6
       if (data.attr == NULL)
9bb5d6
 	return -1;
9bb5d6
 
9bb5d6
-      memcpy (data.attr, notification->sigev_notify_attributes,
9bb5d6
-	      sizeof (pthread_attr_t));
9bb5d6
+      __pthread_attr_copy (data.attr, notification->sigev_notify_attributes);
9bb5d6
     }
9bb5d6
 
9bb5d6
   /* Construct the new request.  */
9bb5d6
@@ -272,7 +274,10 @@ mq_notify (mqd_t mqdes, const struct sigevent *notification)
9bb5d6
 
9bb5d6
   /* If it failed, free the allocated memory.  */
9bb5d6
   if (__glibc_unlikely (retval != 0))
9bb5d6
-    free (data.attr);
9bb5d6
+    {
9bb5d6
+      pthread_attr_destroy (data.attr);
9bb5d6
+      free (data.attr);
9bb5d6
+    }
9bb5d6
 
9bb5d6
   return retval;
9bb5d6
 }