From patchwork Thu Jun 17 12:52:41 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 43880 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 513D63855015 for ; Thu, 17 Jun 2021 12:53:09 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 513D63855015 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1623934389; bh=zfHKTv5XGhMRzHMoAKq4E3Diuk0Nb3mc3rFvrvLFfTU=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=bwLHAeoLyx4PQdjXyKGEMDBNrYD5Sok7BK9a1jKGe+J/bl5R0R9o2OkpzAXVntYRn pHo8h96OFtbbCfFwniYzBdvo0Bmb0jar2ZCSZ0HghjJYzVO2KgXuICEobJuT3Og8Gw gKVm6uYafdrS4uCgIpWWfAikeXA/wdkY0NTYK1Nc= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-qt1-x82d.google.com (mail-qt1-x82d.google.com [IPv6:2607:f8b0:4864:20::82d]) by sourceware.org (Postfix) with ESMTPS id 32AA83857431 for ; Thu, 17 Jun 2021 12:52:47 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 32AA83857431 Received: by mail-qt1-x82d.google.com with SMTP id l2so1806842qtq.10 for ; Thu, 17 Jun 2021 05:52:47 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=zfHKTv5XGhMRzHMoAKq4E3Diuk0Nb3mc3rFvrvLFfTU=; b=nRllGWbgVSdhD07FqTWO3WmFOpHhpZJN3suViIGfg0n3Nhc3bjHLzcnxnFd8GDEDgN a5B24XqgSNS7AGUdYcyITiXWuWjXV1LXTuvi97K0IR47r9j2dH+/or/a/5ux6WOf1Sx0 hBM7zPd/JA7lKPr20CuyAhhIvaNeSLUxNi2De7t+ZkgxgYGNskSuAFvLj+HucGIt8oV6 9weBVQa1xytFrxI8LrBzxhb6lHolUHnOSAKs4RXCIRm5E04zO1Lq061BsTtLhVMWjMiU /mnHShQc3O+dhcR5eLYqSslH+sabkSCYyZ4lwKY2J3rp3PFem5SivJxPhcCz9WMHnjz9 WewA== X-Gm-Message-State: AOAM531xyj21S0JQTot/kNfKdA9sq1r3nGjLbhLWjSq+vm/VtBW2lsnj IEvoSQghYrwVPmzixvuu7sPTRvXbF7iTmg== X-Google-Smtp-Source: ABdhPJyWGspUhcYZhGyO31FqXdntM94Xl3/+PJTm9pdND0qca6OVkpTAXy2bQC1eXmut4XpU9qAUsA== X-Received: by 2002:ac8:7c44:: with SMTP id o4mr4940708qtv.317.1623934366258; Thu, 17 Jun 2021 05:52:46 -0700 (PDT) Received: from birita.. ([177.194.59.218]) by smtp.googlemail.com with ESMTPSA id z13sm1024620qtn.4.2021.06.17.05.52.45 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Jun 2021 05:52:46 -0700 (PDT) To: libc-alpha@sourceware.org Subject: [PATCH] nptl: Use SA_RESTART for SIGCANCEL handler Date: Thu, 17 Jun 2021 09:52:41 -0300 Message-Id: <20210617125241.1415287-1-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 X-Spam-Status: No, score=-12.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, 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: , X-Patchwork-Original-From: Adhemerval Zanella via Libc-alpha From: Adhemerval Zanella Netto Reply-To: Adhemerval Zanella Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" The usage of signals to implementation pthread cancellation is an implementation detail and should not be visible through cancellation entrypoints. However now that pthread_cancel always send the SIGCANCEL, some entrypoint might be interruptable and return EINTR to the caller (for instance on sem_wait). Using SA_RESTART hides this, since the cancellation handler should either act uppon cancellation (if asynchronous cancellation is enable) or ignore the cancellation internal signal. Checked on x86_64-linux-gnu and i686-linux-gnu. --- nptl/pthread_cancel.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/nptl/pthread_cancel.c b/nptl/pthread_cancel.c index 0698cd2046..cc25ff21f3 100644 --- a/nptl/pthread_cancel.c +++ b/nptl/pthread_cancel.c @@ -72,7 +72,11 @@ __pthread_cancel (pthread_t th) { struct sigaction sa; sa.sa_sigaction = sigcancel_handler; - sa.sa_flags = SA_SIGINFO; + /* The signal handle should be non-interruptible to avoid the risk of + spurious EINTR caused by SIGCANCEL sent to process or if + pthread_cancel() is called while cancellation is disabled in the + target thread. */ + sa.sa_flags = SA_SIGINFO | SA_RESTART; __sigemptyset (&sa.sa_mask); __libc_sigaction (SIGCANCEL, &sa, NULL); atomic_store_relaxed (&init_sigcancel, 1);