From patchwork Mon Aug 23 19:50:45 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella X-Patchwork-Id: 44761 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 3D4A83857810 for ; Mon, 23 Aug 2021 20:03:26 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3D4A83857810 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1629749006; bh=hO+dSvOVzoTesdi5RzXcUUWZDljd0oDk+/t3ne4TWHU=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=gYN+fimZO391Dqge8YgEXYvc5YDR1G3saDDwdQCZheox29JDRRS8HHzDC+iztVCGb A8t+i/W+G5afwB8k/15DraEJmL7Q50PMyIyYEt1kBqFLLMQ9qeo/DOv+Ed2KMmciPd RXt9gocWOyabi9d8Hn1axlpxsGrHGD4jOV7kztxI= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-qk1-x731.google.com (mail-qk1-x731.google.com [IPv6:2607:f8b0:4864:20::731]) by sourceware.org (Postfix) with ESMTPS id 30A3E3857818 for ; Mon, 23 Aug 2021 19:52:21 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 30A3E3857818 Received: by mail-qk1-x731.google.com with SMTP id t4so6145643qkb.9 for ; Mon, 23 Aug 2021 12:52:21 -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:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=hO+dSvOVzoTesdi5RzXcUUWZDljd0oDk+/t3ne4TWHU=; b=qyanI0j+uAUmDYkEvKYgoitIcadkLZaP/+V5X+Nc3XJ9oqavoota+HkubGGZPeLrm4 aMUFoIiH1Gm/sZ3aaiPv/dthbqi8gXo/n2CGXLsx3z0K5lHP7WNdyPCSHKgY5QABz/MV rb7TwQPO8GS1fLczmeXQJyar2tYRmpFXXUwvClps4XwfvSU8U3v8TUX+l9dicEL0Rd4S sOrptI0odqx1hTMtiJ7sJnJRHdywjxQm83KwnDgOExl1pV9XBUwqgh9BGorXwEeI5qtO bOH7VVUJs77GCLwDChHW6J8w1DewD0z65QuETcenp0seQI2RG46gtP4bTbLMnBCRpFpF I55w== X-Gm-Message-State: AOAM530SahaJXvf5lk1eGFgyjtT3Qu3QUtXQzVaFCPRZbvOU6nFNm8TU 97Pk+oPQSzMUhb4PMfyxzRXdzd+No4OoOg== X-Google-Smtp-Source: ABdhPJzVNM6vVOz3fftazAHngmU0+jeD/UV79PofotVnVMkx0Z0N16KDxDxDUy98znnpOxUyxMs56Q== X-Received: by 2002:a05:620a:2f1:: with SMTP id a17mr23490072qko.122.1629748340709; Mon, 23 Aug 2021 12:52:20 -0700 (PDT) Received: from birita.. ([2804:431:c7ca:cd83:c38b:b50d:5d9a:43d4]) by smtp.gmail.com with ESMTPSA id s10sm9210935qko.134.2021.08.23.12.52.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Aug 2021 12:52:20 -0700 (PDT) To: libc-alpha@sourceware.org Subject: [PATCH v2 17/19] nptl: Use tidlock when accessing TID on pthread_sigqueue Date: Mon, 23 Aug 2021 16:50:45 -0300 Message-Id: <20210823195047.543237-18-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210823195047.543237-1-adhemerval.zanella@linaro.org> References: <20210823195047.543237-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-12.8 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.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 Cc: Florian Weimer Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" Checked on x86_64-linux-gnu. --- nptl/pthread_sigqueue.c | 52 +++++++++++++++++++++-------------------- 1 file changed, 27 insertions(+), 25 deletions(-) diff --git a/nptl/pthread_sigqueue.c b/nptl/pthread_sigqueue.c index 2a0467ad7a..731e83884d 100644 --- a/nptl/pthread_sigqueue.c +++ b/nptl/pthread_sigqueue.c @@ -28,41 +28,43 @@ 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 (); + /* Block all signal, since the lock is recursive and used on pthread_cancel + (which should be async-signal-safe). */ + sigset_t oldmask; + __libc_signal_block_all (&oldmask); + lll_lock (pd->tidlock, LLL_PRIVATE); + + int res; + if (pd->tid == 0) + { + pid_t pid = getpid (); - /* 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; + /* 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; - /* We have a special syscall to do the work. */ - int val = INTERNAL_SYSCALL_CALL (rt_tgsigqueueinfo, pid, tid, signo, + res = INTERNAL_SYSCALL_CALL (rt_tgsigqueueinfo, pid, pd->tid, signo, &info); - return (INTERNAL_SYSCALL_ERROR_P (val) - ? INTERNAL_SYSCALL_ERRNO (val) : 0); -#else - return ENOSYS; -#endif + } + else + res = -ESRCH; + + lll_unlock (pd->tidlock, LLL_PRIVATE); + __libc_signal_restore_set (&oldmask); + + return -res; } versioned_symbol (libc, __pthread_sigqueue, pthread_sigqueue, GLIBC_2_34);