From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-oi1-x233.google.com (mail-oi1-x233.google.com [IPv6:2607:f8b0:4864:20::233]) by sourceware.org (Postfix) with ESMTPS id 7B67039960C8 for ; Wed, 8 Jun 2022 20:22:43 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 7B67039960C8 Received: by mail-oi1-x233.google.com with SMTP id y69so15700115oia.7 for ; Wed, 08 Jun 2022 13:22:43 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=PaiPOdOAWsjH0rvUMOHBs6B8tpJF4CWBrLusuDgGjJ0=; b=33lZmJt0gNyPoAvUo9HY+TjLpdzHmNhsYZ0Hbl/bXzO9oxKf22Z6HQHFJbyzUyMs0W OjXEy9XZ/J87mnJh5SNp/ApugqkommBg2kZLWVb+QvXMsSWWW8nfIPfPkv1bTQgbRalv dkfr268fkkf68F/7up0DRysOq+iDJNr0MVROirbl0kErFdLoAOiW9ksbDpLLVpflfzk+ KU8H7Ggzzi3esvg0l30Dd+4Brnh8AzsmkLasdPxh2hpkue88WUhfj6x2H854NeZ4jRcm 5PckN7vGKQE2e0QvjkF08Rdf0UHDR4YhWv9bEglppwoF8K+fa70AwatPUBg4xK3/TFZB aMZA== X-Gm-Message-State: AOAM531MmvPw0V3BSBpM8PB+rpdlpzZSUiD/ADWqYIXYSKoJnBX/3sK3 EBzwsUQ5Bp5xFopgWJHH6ImQCW4Pa+doaA== X-Google-Smtp-Source: ABdhPJwEKg7WhWM+XPKSi7rJnJwoCNQY2cfijsEj43803TLWHxAmZjNdpZkHEm5wlcOzHbyZ09NWNg== X-Received: by 2002:a05:6808:2289:b0:32e:df85:2ade with SMTP id bo9-20020a056808228900b0032edf852ademr1183024oib.299.1654719762456; Wed, 08 Jun 2022 13:22:42 -0700 (PDT) Received: from birita.. ([2804:431:c7cb:a613:9260:25f7:781e:1ec9]) by smtp.gmail.com with ESMTPSA id f15-20020a9d5e8f000000b0060bea83bc97sm6701367otl.8.2022.06.08.13.22.41 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Jun 2022 13:22:42 -0700 (PDT) From: Adhemerval Zanella To: libc-stable@sourceware.org Subject: [COMMITTED 2.34] nptl: Fix __libc_cleanup_pop_restore asynchronous restore (BZ#29214) Date: Wed, 8 Jun 2022 17:22:38 -0300 Message-Id: <20220608202238.205552-1-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-13.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) 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: Wed, 08 Jun 2022 20:22:45 -0000 This was due a wrong revert done on 404656009b459658. Checked on x86_64-linux-gnu. (cherry picked from commit c7d36dcecc08a29825175f65c4ee873ff3177a23) --- NEWS | 1 + nptl/libc-cleanup.c | 3 +- sysdeps/pthread/Makefile | 1 + sysdeps/pthread/tst-cancel30.c | 82 ++++++++++++++++++++++++++++++++++ 4 files changed, 86 insertions(+), 1 deletion(-) create mode 100644 sysdeps/pthread/tst-cancel30.c diff --git a/NEWS b/NEWS index eed8a134dd..fe37985bc2 100644 --- a/NEWS +++ b/NEWS @@ -109,6 +109,7 @@ The following bugs are resolved with this release: [29210] network: ruserpass is not y2038 aware [29211] libc: __open_catalog is not y2038 aware [29213] libc: gconv_parseconfdir is not y2038 aware + [29214] nptl: pthread_setcanceltype fails to set type Version 2.34 diff --git a/nptl/libc-cleanup.c b/nptl/libc-cleanup.c index fccb1abe69..a37c48ff87 100644 --- a/nptl/libc-cleanup.c +++ b/nptl/libc-cleanup.c @@ -58,7 +58,8 @@ __libc_cleanup_pop_restore (struct _pthread_cleanup_buffer *buffer) THREAD_SETMEM (self, cleanup, buffer->__prev); int cancelhandling = atomic_load_relaxed (&self->cancelhandling); - if (cancelhandling & CANCELTYPE_BITMASK) + if (buffer->__canceltype != PTHREAD_CANCEL_DEFERRED + && (cancelhandling & CANCELTYPE_BITMASK) == 0) { int newval; do diff --git a/sysdeps/pthread/Makefile b/sysdeps/pthread/Makefile index 5147588c13..d99c161c82 100644 --- a/sysdeps/pthread/Makefile +++ b/sysdeps/pthread/Makefile @@ -126,6 +126,7 @@ tests += tst-cnd-basic tst-mtx-trylock tst-cnd-broadcast \ tst-pthread-raise-blocked-self \ tst-pthread_kill-exited \ tst-pthread_kill-exiting \ + tst-cancel30 \ # tests tests-time64 := \ diff --git a/sysdeps/pthread/tst-cancel30.c b/sysdeps/pthread/tst-cancel30.c new file mode 100644 index 0000000000..e08392f968 --- /dev/null +++ b/sysdeps/pthread/tst-cancel30.c @@ -0,0 +1,82 @@ +/* Check if printf like functions does not disable asynchronous cancellation + mode (BZ#29214). + + Copyright (C) 2022 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#include +#include +#include +#include +#include + +static pthread_barrier_t b; + +static void * +tf (void *arg) +{ + int old; + + TEST_COMPARE (pthread_setcanceltype (PTHREAD_CANCEL_ASYNCHRONOUS, NULL), 0); + + TEST_COMPARE (pthread_setcanceltype (PTHREAD_CANCEL_ASYNCHRONOUS, &old), 0); + TEST_COMPARE (old, PTHREAD_CANCEL_ASYNCHRONOUS); + + /* Check if internal lock cleanup routines restore the cancellation type + correctly. */ + printf ("...\n"); + TEST_COMPARE (pthread_setcanceltype (PTHREAD_CANCEL_ASYNCHRONOUS, &old), 0); + TEST_COMPARE (old, PTHREAD_CANCEL_ASYNCHRONOUS); + + xpthread_barrier_wait (&b); + + /* Wait indefinitely for cancellation, which only works if asynchronous + cancellation is enabled. */ +#ifdef SYS_pause + syscall (SYS_pause); +#elif defined SYS_ppoll || defined SYS_ppoll_time64 +# ifndef SYS_ppoll_time64 +# define SYS_ppoll_time64 SYS_ppoll +# endif + syscall (SYS_ppoll_time64, NULL, 0, NULL, NULL); +#else + for (;;); +#endif + + return 0; +} + +static int +do_test (void) +{ + xpthread_barrier_init (&b, NULL, 2); + + pthread_t th = xpthread_create (NULL, tf, NULL); + + xpthread_barrier_wait (&b); + + xpthread_cancel (th); + + void *status = xpthread_join (th); + TEST_VERIFY (status == PTHREAD_CANCELED); + + return 0; +} + +/* There is no need to wait full TIMEOUT if asynchronous is not working. */ +#define TIMEOUT 3 +#include -- 2.34.1