9bb5d6
commit b805aebd42364fe696e417808a700fdb9800c9e8
9bb5d6
Author: Nikita Popov <npv1310@gmail.com>
9bb5d6
Date:   Mon Aug 9 20:17:34 2021 +0530
9bb5d6
9bb5d6
    librt: fix NULL pointer dereference (bug 28213)
9bb5d6
    
9bb5d6
    Helper thread frees copied attribute on NOTIFY_REMOVED message
9bb5d6
    received from the OS kernel.  Unfortunately, it fails to check whether
9bb5d6
    copied attribute actually exists (data.attr != NULL).  This worked
9bb5d6
    earlier because free() checks passed pointer before actually
9bb5d6
    attempting to release corresponding memory.  But
9bb5d6
    __pthread_attr_destroy assumes pointer is not NULL.
9bb5d6
    
9bb5d6
    So passing NULL pointer to __pthread_attr_destroy will result in
9bb5d6
    segmentation fault.  This scenario is possible if
9bb5d6
    notification->sigev_notify_attributes == NULL (which means default
9bb5d6
    thread attributes should be used).
9bb5d6
    
9bb5d6
    Signed-off-by: Nikita Popov <npv1310@gmail.com>
9bb5d6
    Reviewed-by: Siddhesh Poyarekar <siddhesh@sourceware.org>
9bb5d6
9bb5d6
diff --git a/sysdeps/unix/sysv/linux/mq_notify.c b/sysdeps/unix/sysv/linux/mq_notify.c
9bb5d6
index 45449571d14c379f..581959d621135fb0 100644
9bb5d6
--- a/sysdeps/unix/sysv/linux/mq_notify.c
9bb5d6
+++ b/sysdeps/unix/sysv/linux/mq_notify.c
9bb5d6
@@ -134,7 +134,7 @@ helper_thread (void *arg)
9bb5d6
 	       to wait until it is done with it.  */
9bb5d6
 	    (void) __pthread_barrier_wait (&notify_barrier);
9bb5d6
 	}
9bb5d6
-      else if (data.raw[NOTIFY_COOKIE_LEN - 1] == NOTIFY_REMOVED)
9bb5d6
+      else if (data.raw[NOTIFY_COOKIE_LEN - 1] == NOTIFY_REMOVED && data.attr != NULL)
9bb5d6
 	{
9bb5d6
 	  /* The only state we keep is the copy of the thread attributes.  */
9bb5d6
 	  pthread_attr_destroy (data.attr);