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