From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from aloka.lostca.se (aloka.lostca.se [178.63.46.202]) by sourceware.org (Postfix) with ESMTPS id DCBFD3858034 for ; Thu, 10 Jun 2021 13:13:47 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org DCBFD3858034 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 828D41EB58 for ; Thu, 10 Jun 2021 13:13:46 +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=xjS9 IIMuo9O/+GvPCBN5Wo7hSXU=; b=2rncBY/JTF+of+K/8sKF4iJ4DQX9rlDYj7dj d4RWBv7aRZAN7NOjtdiDbm5D6agAdZUdFx6kTO/eW1KEWBgq/2qCXIVFKcmd3BCW EzutSV3qrqjohB6F5VcLc7/UG3joK8G2DnULg7pfDiElJKWbjhLBQfHy76tsSabP 74WQ34Q= 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 4C7521EB56 for ; Thu, 10 Jun 2021 13:13:46 +0000 (UTC) Date: Thu, 10 Jun 2021 13:13:46 +0000 From: Arjun Shankar To: libc-stable@sourceware.org Subject: [COMMITTED 2.33] Fix use of __pthread_attr_copy in mq_notify (bug 27896) Message-ID: <20210610131344.GB86500@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.1 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:13:51 -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 f7ddfe5a6c..6f46d29d1d 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