From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from aloka.lostca.se (aloka.lostca.se [IPv6:2a01:4f8:120:624c::2]) by sourceware.org (Postfix) with ESMTPS id 0A2603857C7F for ; Thu, 10 Jun 2021 13:10:39 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 0A2603857C7F Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=lostca.se Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=lostca.se Received: from aloka.lostca.se (aloka [127.0.0.1]) by aloka.lostca.se (Postfix) with ESMTP id 9C13F1EAE4 for ; Thu, 10 Jun 2021 13:10:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=lostca.se; h=date:from:to :subject:message-id:mime-version:content-type; s=howrah; bh=ZfnF NYwXKbnpKjqOY6KrxNdJ5us=; b=Xfpf11usriKZzyZX9JQ7n2B39RvDFS2xwbLy 3pgRcApgryMbwvW+a6AJHUKlIBLS7ETVtKcZVzWrrhji64rBwYV9ORx074O95eDp x68dNE6bOH5hVIJiN4MCZnaffCUlf6AueQm+DTm0l4EzvvQjAvCmKB9xf/UaN4t9 8A27uOk= Received: from localhost (unknown [IPv6:2a01:4f8:120:624c::25]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) (Authenticated sender: spectre) by aloka.lostca.se (Postfix) with ESMTPSA id 4E3BF1EAE3 for ; Thu, 10 Jun 2021 13:10:37 +0000 (UTC) Date: Thu, 10 Jun 2021 13:10:37 +0000 From: Arjun Shankar To: libc-stable@sourceware.org Subject: [COMMITTED 2.32] Fix use of __pthread_attr_copy in mq_notify (bug 27896) Message-ID: <20210610131035.GB86427@aloka.lostca.se> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.10.1 (2018-07-13) X-Spam-Status: No, score=-12.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libc-stable@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-stable mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 10 Jun 2021 13:10:40 -0000 __pthread_attr_copy can fail and does not initialize the attribute structure in that case. If __pthread_attr_copy is never called and there is no allocated attribute, pthread_attr_destroy should not be called, otherwise there is a null pointer dereference in rt/tst-mqueue6. Fixes commit 42d359350510506b87101cf77202fefcbfc790cb ("Use __pthread_attr_copy in mq_notify (bug 27896)"). Reviewed-by: Siddhesh Poyarekar (cherry picked from commit 217b6dc298156bdb0d6aea9ea93e7e394a5ff091) --- sysdeps/unix/sysv/linux/mq_notify.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/sysdeps/unix/sysv/linux/mq_notify.c b/sysdeps/unix/sysv/linux/mq_notify.c index f404acfdfe..b5a903c3a2 100644 --- a/sysdeps/unix/sysv/linux/mq_notify.c +++ b/sysdeps/unix/sysv/linux/mq_notify.c @@ -258,7 +258,14 @@ mq_notify (mqd_t mqdes, const struct sigevent *notification) if (data.attr == NULL) return -1; - __pthread_attr_copy (data.attr, notification->sigev_notify_attributes); + int ret = __pthread_attr_copy (data.attr, + notification->sigev_notify_attributes); + if (ret != 0) + { + free (data.attr); + __set_errno (ret); + return -1; + } } /* Construct the new request. */ @@ -271,7 +278,7 @@ mq_notify (mqd_t mqdes, const struct sigevent *notification) int retval = INLINE_SYSCALL (mq_notify, 2, mqdes, &se); /* If it failed, free the allocated memory. */ - if (__glibc_unlikely (retval != 0)) + if (retval != 0 && data.attr != NULL) { pthread_attr_destroy (data.attr); free (data.attr); -- 2.31.1