From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 7814) id C7F23395185D; Mon, 16 Aug 2021 17:13:53 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C7F23395185D Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Fangrui Song To: glibc-cvs@sourceware.org Subject: [glibc/maskray/lld] librt: fix NULL pointer dereference (bug 28213) X-Act-Checkin: glibc X-Git-Author: Nikita Popov X-Git-Refname: refs/heads/maskray/lld X-Git-Oldrev: 60b4dd25790342b40e8942e3a4115f511a6b6911 X-Git-Newrev: b805aebd42364fe696e417808a700fdb9800c9e8 Message-Id: <20210816171353.C7F23395185D@sourceware.org> Date: Mon, 16 Aug 2021 17:13:53 +0000 (GMT) X-BeenThere: glibc-cvs@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Glibc-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 16 Aug 2021 17:13:53 -0000 https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=b805aebd42364fe696e417808a700fdb9800c9e8 commit b805aebd42364fe696e417808a700fdb9800c9e8 Author: Nikita Popov Date: Mon Aug 9 20:17:34 2021 +0530 librt: fix NULL pointer dereference (bug 28213) Helper thread frees copied attribute on NOTIFY_REMOVED message received from the OS kernel. Unfortunately, it fails to check whether copied attribute actually exists (data.attr != NULL). This worked earlier because free() checks passed pointer before actually attempting to release corresponding memory. But __pthread_attr_destroy assumes pointer is not NULL. So passing NULL pointer to __pthread_attr_destroy will result in segmentation fault. This scenario is possible if notification->sigev_notify_attributes == NULL (which means default thread attributes should be used). Signed-off-by: Nikita Popov Reviewed-by: Siddhesh Poyarekar Diff: --- sysdeps/unix/sysv/linux/mq_notify.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sysdeps/unix/sysv/linux/mq_notify.c b/sysdeps/unix/sysv/linux/mq_notify.c index 9799dcdaa4..eccae2e4c6 100644 --- a/sysdeps/unix/sysv/linux/mq_notify.c +++ b/sysdeps/unix/sysv/linux/mq_notify.c @@ -131,7 +131,7 @@ helper_thread (void *arg) to wait until it is done with it. */ (void) __pthread_barrier_wait (¬ify_barrier); } - else if (data.raw[NOTIFY_COOKIE_LEN - 1] == NOTIFY_REMOVED) + else if (data.raw[NOTIFY_COOKIE_LEN - 1] == NOTIFY_REMOVED && data.attr != NULL) { /* The only state we keep is the copy of the thread attributes. */ __pthread_attr_destroy (data.attr);