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