[v2,14/19] nptl: Use tidlock when accessing TID on pthread_setschedparam

Message ID 20210823195047.543237-15-adhemerval.zanella@linaro.org
State Superseded
Headers
Series Fix various NPTL synchronization issues |

Checks

Context Check Description
dj/TryBot-apply_patch success Patch applied to master at the time it was sent

Commit Message

Adhemerval Zanella Netto Aug. 23, 2021, 7:50 p.m. UTC
  Checked on x86_64-linux-gnu.
---
 nptl/pthread_setschedparam.c | 16 +++++++++++++---
 1 file changed, 13 insertions(+), 3 deletions(-)
  

Comments

Florian Weimer Aug. 26, 2021, 2:35 p.m. UTC | #1
* Adhemerval Zanella:

> Checked on x86_64-linux-gnu.
> ---
>  nptl/pthread_setschedparam.c | 16 +++++++++++++---
>  1 file changed, 13 insertions(+), 3 deletions(-)
>
> diff --git a/nptl/pthread_setschedparam.c b/nptl/pthread_setschedparam.c
> index 70fa8378b8..75c796d9b8 100644
> --- a/nptl/pthread_setschedparam.c
> +++ b/nptl/pthread_setschedparam.c
> @@ -30,12 +30,18 @@ __pthread_setschedparam (pthread_t threadid, int policy,
>    struct pthread *pd = (struct pthread *) threadid;
>  
>    /* Make sure the descriptor is valid.  */
> -  if (INVALID_TD_P (pd))
> -    /* Not a valid thread handle.  */
> -    return ESRCH;
> +  sigset_t oldmask;
> +  __libc_signal_block_all (&oldmask);
> +  lll_lock (pd->tidlock, LLL_PRIVATE);
>  
>    int result = 0;
>  
> +  if (pd->tid == 0)
> +    {
> +      result = ESRCH;
> +      goto out;
> +    }

This case should probably just return 0.

Thanks,
Florian
  

Patch

diff --git a/nptl/pthread_setschedparam.c b/nptl/pthread_setschedparam.c
index 70fa8378b8..75c796d9b8 100644
--- a/nptl/pthread_setschedparam.c
+++ b/nptl/pthread_setschedparam.c
@@ -30,12 +30,18 @@  __pthread_setschedparam (pthread_t threadid, int policy,
   struct pthread *pd = (struct pthread *) threadid;
 
   /* Make sure the descriptor is valid.  */
-  if (INVALID_TD_P (pd))
-    /* Not a valid thread handle.  */
-    return ESRCH;
+  sigset_t oldmask;
+  __libc_signal_block_all (&oldmask);
+  lll_lock (pd->tidlock, LLL_PRIVATE);
 
   int result = 0;
 
+  if (pd->tid == 0)
+    {
+      result = ESRCH;
+      goto out;
+    }
+
   /* See CREATE THREAD NOTES in nptl/pthread_create.c.  */
   lll_lock (pd->lock, LLL_PRIVATE);
 
@@ -67,6 +73,10 @@  __pthread_setschedparam (pthread_t threadid, int policy,
 
   lll_unlock (pd->lock, LLL_PRIVATE);
 
+out:
+  lll_unlock (pd->tidlock, LLL_PRIVATE);
+  __libc_signal_restore_set (&oldmask);
+
   return result;
 }
 strong_alias (__pthread_setschedparam, pthread_setschedparam)