From patchwork Thu Sep 30 20:00:49 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella X-Patchwork-Id: 45635 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 289813857C5B for ; Thu, 30 Sep 2021 20:10:46 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 289813857C5B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1633032646; bh=jfBLO0Wz+nvbhfmpRBFGKAjWsAlJSjHasZZZF/rtW90=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=cBznD9n/F/Lh43WE3dmnRphHU/MgpjaujqCaaMTGyKiQvl1+g2vH2paGYlGyQTct9 oug70Ksa32kWdkAbcUN4sDzh47+od5V/0ja8LhPwZnQexImLjNRNAi734uV67i4vHc YZJzgDxet7zRVXPRhgwMBksEswo+COi4+4SlVwww= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-qt1-x832.google.com (mail-qt1-x832.google.com [IPv6:2607:f8b0:4864:20::832]) by sourceware.org (Postfix) with ESMTPS id 980C43857C5B for ; Thu, 30 Sep 2021 20:01:11 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 980C43857C5B Received: by mail-qt1-x832.google.com with SMTP id t2so6874525qtx.8 for ; Thu, 30 Sep 2021 13:01:11 -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:in-reply-to :references:mime-version:content-transfer-encoding; bh=jfBLO0Wz+nvbhfmpRBFGKAjWsAlJSjHasZZZF/rtW90=; b=At+Q+4ZQV3wCrBJVatDAu8DC4NDBFZk5AC3CEN/j2/waYiC3178eWS2+xbyGyo9pxG oh1Il/+RGWO16jsGW1LbIrOlYKfcZrU+PslA1gk27P3uxi6xhaB97DlsC8Uhj59laQhW XiJyqLtBA1FYdjoTfuMw2AT5j/d6z4ceDvtdOsHfrBdpQoAcc/Zz5kax4la0UFiBuXPy PEbQtt8yZPbrMcz6GzcYvhmjqJ8MTSoW11HxsGrhRS8pwaHLcbUmOh3/aIGSt691YSLg vOPXyFIEwPpLWPo5XlCz5YYkFWaC2o3ajAU4wF/fDBN4TnI71Yrv+P3tcnhtQW6Ht1fa 0vRg== X-Gm-Message-State: AOAM532l8/p/O4DePJinpPOwD+o8IijyuxZi2x39w/iOeElcuP5r3rYT W6Aq63atOOZs3GeaTWZLozacUObo1KH1sA== X-Google-Smtp-Source: ABdhPJz2JluHfrZnleIjcnXKUh0euJZgIw1sYrdkOK5ugLRr680V6QdIxws6Z+wLlS1Y3gqvn7ybfg== X-Received: by 2002:ac8:7519:: with SMTP id u25mr8758390qtq.151.1633032071027; Thu, 30 Sep 2021 13:01:11 -0700 (PDT) Received: from birita.. ([2804:431:c7cb:b338:b20e:53f8:8b5:1bb2]) by smtp.gmail.com with ESMTPSA id r196sm1910203qka.119.2021.09.30.13.01.10 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Sep 2021 13:01:10 -0700 (PDT) To: libc-alpha@sourceware.org Subject: [PATCH 13/15] nptl: Use exit_lock when accessing TID on pthread_sigqueue Date: Thu, 30 Sep 2021 17:00:49 -0300 Message-Id: <20210930200051.1017457-14-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210930200051.1017457-1-adhemerval.zanella@linaro.org> References: <20210930200051.1017457-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-12.6 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 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: , X-Patchwork-Original-From: Adhemerval Zanella via Libc-alpha From: Adhemerval Zanella Reply-To: Adhemerval Zanella Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" Checked on x86_64-linux-gnu. --- nptl/pthread_sigqueue.c | 56 ++++++++++++++-------------- sysdeps/pthread/tst-pthread-exited.c | 6 +++ 2 files changed, 34 insertions(+), 28 deletions(-) diff --git a/nptl/pthread_sigqueue.c b/nptl/pthread_sigqueue.c index edc18bf4c0..c4a1e0a04d 100644 --- a/nptl/pthread_sigqueue.c +++ b/nptl/pthread_sigqueue.c @@ -16,6 +16,7 @@ . */ #include +#include #include #include #include @@ -27,41 +28,40 @@ int __pthread_sigqueue (pthread_t threadid, int signo, const union sigval value) { -#ifdef __NR_rt_tgsigqueueinfo - struct pthread *pd = (struct pthread *) threadid; - - /* Force load of pd->tid into local variable or register. Otherwise - if a thread exits between ESRCH test and tgkill, we might return - EINVAL, because pd->tid would be cleared by the kernel. */ - pid_t tid = atomic_forced_read (pd->tid); - if (__glibc_unlikely (tid <= 0)) - /* Not a valid thread handle. */ - return ESRCH; - /* Disallow sending the signal we use for cancellation, timers, for the setxid implementation. */ if (signo == SIGCANCEL || signo == SIGTIMER || signo == SIGSETXID) return EINVAL; - pid_t pid = getpid (); + struct pthread *pd = (struct pthread *) threadid; - /* Set up the siginfo_t structure. */ - siginfo_t info; - memset (&info, '\0', sizeof (siginfo_t)); - info.si_signo = signo; - info.si_code = SI_QUEUE; - info.si_pid = pid; - info.si_uid = __getuid (); - info.si_value = value; + /* Block all signals, as required by pd->exit_lock. */ + sigset_t old_mask; + __libc_signal_block_all (&old_mask); + __libc_lock_lock (pd->exit_lock); - /* We have a special syscall to do the work. */ - int val = INTERNAL_SYSCALL_CALL (rt_tgsigqueueinfo, pid, tid, signo, - &info); - return (INTERNAL_SYSCALL_ERROR_P (val) - ? INTERNAL_SYSCALL_ERRNO (val) : 0); -#else - return ENOSYS; -#endif + int res; + if (pd->tid != 0) + { + pid_t pid = getpid (); + + siginfo_t info = { 0 }; + info.si_signo = signo; + info.si_code = SI_QUEUE; + info.si_pid = pid; + info.si_uid = __getuid (); + info.si_value = value; + + res = -INTERNAL_SYSCALL_CALL (rt_tgsigqueueinfo, pid, pd->tid, signo, + &info); + } + else + res = ESRCH; + + __libc_lock_unlock (pd->exit_lock); + __libc_signal_restore_set (&old_mask); + + return res; } versioned_symbol (libc, __pthread_sigqueue, pthread_sigqueue, GLIBC_2_34); diff --git a/sysdeps/pthread/tst-pthread-exited.c b/sysdeps/pthread/tst-pthread-exited.c index eaaf00a9b4..bfb3870cb6 100644 --- a/sysdeps/pthread/tst-pthread-exited.c +++ b/sysdeps/pthread/tst-pthread-exited.c @@ -82,6 +82,12 @@ do_test (void) TEST_COMPARE (r, ESRCH); } + { + union sigval value = { 0 }; + int r = pthread_sigqueue (thr, SIGUSR1, value); + TEST_COMPARE (r, ESRCH); + } + xpthread_join (thr); return 0;