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