From patchwork Mon Feb 14 18:29:34 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Samuel Thibault X-Patchwork-Id: 51110 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 5420C385803D for ; Mon, 14 Feb 2022 18:29:50 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from hera.aquilenet.fr (hera.aquilenet.fr [185.233.100.1]) by sourceware.org (Postfix) with ESMTPS id D8C40385840D for ; Mon, 14 Feb 2022 18:29:37 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org D8C40385840D Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=ens-lyon.org Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=ens-lyon.org Received: from localhost (localhost [127.0.0.1]) by hera.aquilenet.fr (Postfix) with ESMTP id 04FC23BE; Mon, 14 Feb 2022 19:29:36 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at aquilenet.fr Received: from hera.aquilenet.fr ([127.0.0.1]) by localhost (hera.aquilenet.fr [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 94-VgzLpJU_Y; Mon, 14 Feb 2022 19:29:35 +0100 (CET) Received: from begin (unknown [IPv6:2a01:cb19:956:1b00:de41:a9ff:fe47:ec49]) by hera.aquilenet.fr (Postfix) with ESMTPSA id 94F99388; Mon, 14 Feb 2022 19:29:35 +0100 (CET) Received: from samy by begin with local (Exim 4.95) (envelope-from ) id 1nJg6Q-00CIT1-P6; Mon, 14 Feb 2022 19:29:34 +0100 From: Samuel Thibault To: libc-alpha@sourceware.org Subject: [hurd, commited] htl: Make pthread_[gs]etspecific not check for key validity Date: Mon, 14 Feb 2022 19:29:34 +0100 Message-Id: <20220214182934.2930916-1-samuel.thibault@ens-lyon.org> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Spamd-Bar: ++++ X-Rspamd-Server: hera Authentication-Results: hera.aquilenet.fr; none X-Rspamd-Queue-Id: 04FC23BE X-Spamd-Result: default: False [4.90 / 15.00]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; FROM_HAS_DN(0.00)[]; RCPT_COUNT_THREE(0.00)[3]; TO_DN_SOME(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; MIME_GOOD(-0.10)[text/plain]; R_MISSING_CHARSET(2.50)[]; BROKEN_CONTENT_TYPE(1.50)[]; RCVD_COUNT_THREE(0.00)[3]; MID_CONTAINS_FROM(1.00)[]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; RCVD_TLS_LAST(0.00)[] X-Spam-Status: No, score=-11.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, SPF_HELO_PASS, SPF_NEUTRAL, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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: , Cc: commit-hurd@gnu.org Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" Since __pthread_key_create might be concurrently reallocating the __pthread_key_destructors array, it's not safe to access it without the mutex held. Posix explicitly says we are allowed to prefer performance over error detection. --- sysdeps/htl/pt-getspecific.c | 3 +-- sysdeps/htl/pt-setspecific.c | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/sysdeps/htl/pt-getspecific.c b/sysdeps/htl/pt-getspecific.c index af1161206a..a9dfd8a775 100644 --- a/sysdeps/htl/pt-getspecific.c +++ b/sysdeps/htl/pt-getspecific.c @@ -25,8 +25,7 @@ __pthread_getspecific (pthread_key_t key) { struct __pthread *self; - if (key < 0 || key >= __pthread_key_count - || __pthread_key_destructors[key] == PTHREAD_KEY_INVALID) + if (key < 0 || key >= __pthread_key_count) return NULL; self = _pthread_self (); diff --git a/sysdeps/htl/pt-setspecific.c b/sysdeps/htl/pt-setspecific.c index 982d25d012..d201416d5d 100644 --- a/sysdeps/htl/pt-setspecific.c +++ b/sysdeps/htl/pt-setspecific.c @@ -25,8 +25,7 @@ __pthread_setspecific (pthread_key_t key, const void *value) { struct __pthread *self = _pthread_self (); - if (key < 0 || key >= __pthread_key_count - || __pthread_key_destructors[key] == PTHREAD_KEY_INVALID) + if (key < 0 || key >= __pthread_key_count) return EINVAL; if (key >= self->thread_specifics_size)