From patchwork Tue Jun 1 08:50:58 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Schwab X-Patchwork-Id: 43644 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id BF70E3839C42; Tue, 1 Jun 2021 08:51:05 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-out.m-online.net (mail-out.m-online.net [212.18.0.9]) by sourceware.org (Postfix) with ESMTPS id AEDF338460A3 for ; Tue, 1 Jun 2021 08:51:01 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org AEDF338460A3 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=linux-m68k.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=whitebox@nefkom.net Received: from frontend01.mail.m-online.net (unknown [192.168.8.182]) by mail-out.m-online.net (Postfix) with ESMTP id 4FvQqS4zrHz1qtd8 for ; Tue, 1 Jun 2021 10:51:00 +0200 (CEST) Received: from localhost (dynscan1.mnet-online.de [192.168.6.70]) by mail.m-online.net (Postfix) with ESMTP id 4FvQqS287tz1qr3V for ; Tue, 1 Jun 2021 10:51:00 +0200 (CEST) X-Virus-Scanned: amavisd-new at mnet-online.de Received: from mail.mnet-online.de ([192.168.8.182]) by localhost (dynscan1.mail.m-online.net [192.168.6.70]) (amavisd-new, port 10024) with ESMTP id TbnG5m1znR2z for ; Tue, 1 Jun 2021 10:50:59 +0200 (CEST) X-Auth-Info: Fc8dHv3D55BFBLfVAb24q7sk3Ur6543ZquzRNNzSVylDjdvaTBDcgTA7lwL8pQtH Received: from igel.home (ppp-46-244-174-25.dynamic.mnet-online.de [46.244.174.25]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.mnet-online.de (Postfix) with ESMTPSA for ; Tue, 1 Jun 2021 10:50:59 +0200 (CEST) Received: by igel.home (Postfix, from userid 1000) id CF4042C333D; Tue, 1 Jun 2021 10:50:58 +0200 (CEST) From: Andreas Schwab To: libc-alpha@sourceware.org Subject: [PATCH] Use __pthread_attr_copy in mq_notify (bug 27896) X-Yow: I have nostalgia for the late Sixties! In 1969 I left my laundry with a hippie!! During an unauthorized Tupperware party it was chopped & diced! Date: Tue, 01 Jun 2021 10:50:58 +0200 Message-ID: <874keiaryl.fsf@igel.home> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux) MIME-Version: 1.0 X-Spam-Status: No, score=-10.2 required=5.0 tests=BAYES_00, GIT_PATCH_0, HEADER_FROM_DIFFERENT_DOMAINS, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, 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-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libc-alpha-bounces@sourceware.org Sender: "Libc-alpha" Make a deep copy of the pthread attribute object to remove a potential use-after-free issue. Reviewed-by: Siddhesh Poyarekar --- NEWS | 4 ++++ sysdeps/unix/sysv/linux/mq_notify.c | 15 ++++++++++----- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/NEWS b/NEWS index 266837bf2d..4460752df7 100644 --- a/NEWS +++ b/NEWS @@ -56,6 +56,10 @@ Security related changes: potentially resulting in degraded service or Denial of Service on the local system. Reported by Chris Schanzle. + CVE-2021-33574: The mq_notify function has a potential use-after-free + issue when using a notification type of SIGEV_THREAD and a thread + attribute with a non-default affinity mask. + The following bugs are resolved with this release: [The release manager will add the list generated by diff --git a/sysdeps/unix/sysv/linux/mq_notify.c b/sysdeps/unix/sysv/linux/mq_notify.c index cc575a0cdd..f7ddfe5a6c 100644 --- a/sysdeps/unix/sysv/linux/mq_notify.c +++ b/sysdeps/unix/sysv/linux/mq_notify.c @@ -133,8 +133,11 @@ helper_thread (void *arg) (void) __pthread_barrier_wait (¬ify_barrier); } else if (data.raw[NOTIFY_COOKIE_LEN - 1] == NOTIFY_REMOVED) - /* The only state we keep is the copy of the thread attributes. */ - free (data.attr); + { + /* The only state we keep is the copy of the thread attributes. */ + pthread_attr_destroy (data.attr); + free (data.attr); + } } return NULL; } @@ -255,8 +258,7 @@ mq_notify (mqd_t mqdes, const struct sigevent *notification) if (data.attr == NULL) return -1; - memcpy (data.attr, notification->sigev_notify_attributes, - sizeof (pthread_attr_t)); + __pthread_attr_copy (data.attr, notification->sigev_notify_attributes); } /* Construct the new request. */ @@ -270,7 +272,10 @@ mq_notify (mqd_t mqdes, const struct sigevent *notification) /* If it failed, free the allocated memory. */ if (__glibc_unlikely (retval != 0)) - free (data.attr); + { + pthread_attr_destroy (data.attr); + free (data.attr); + } return retval; }