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