about summary refs log tree commit diff
path: root/nptl/pthread_mutex_timedlock.c
diff options
context:
space:
mode:
authorAdhemerval Zanella <adhemerval.zanella@linaro.org>2020-10-29 15:34:31 -0300
committerAdhemerval Zanella <adhemerval.zanella@linaro.org>2020-11-25 10:46:22 -0300
commit74f418b29d1e9463028f2ae4cc2a9c74d39aeaab (patch)
treeafc76155ba0a5384bc6d142742441dc2b27cdc6a /nptl/pthread_mutex_timedlock.c
parentb45b1c5ba1df4d0315ffdd00a040ff9bc0597a8d (diff)
downloadglibc-74f418b29d1e9463028f2ae4cc2a9c74d39aeaab.tar.gz
glibc-74f418b29d1e9463028f2ae4cc2a9c74d39aeaab.tar.xz
glibc-74f418b29d1e9463028f2ae4cc2a9c74d39aeaab.zip
nptl: Return EINVAL for pthread_mutex_clocklock/PI with CLOCK_MONOTONIC [BZ #26801]
Linux futex FUTEX_LOCK_PI operation only supports CLOCK_REALTIME,
so pthread_mutex_clocklock operation with priority aware mutexes
may fail depending of the input timeout.

Also, it is not possible to convert a CLOCK_MONOTONIC to a
CLOCK_REALTIME due the possible wall clock time change which might
invalid the requested timeout.

Checked on x86_64-linux-gnu and i686-linux-gnu.

Reviewed-by: Lukasz Majewski <lukma@denx.de>
Diffstat (limited to 'nptl/pthread_mutex_timedlock.c')
-rw-r--r--nptl/pthread_mutex_timedlock.c7
1 files changed, 7 insertions, 0 deletions
diff --git a/nptl/pthread_mutex_timedlock.c b/nptl/pthread_mutex_timedlock.c
index b42862193a..aaaafa21ce 100644
--- a/nptl/pthread_mutex_timedlock.c
+++ b/nptl/pthread_mutex_timedlock.c
@@ -313,6 +313,13 @@ __pthread_mutex_clocklock_common (pthread_mutex_t *mutex,
     case PTHREAD_MUTEX_PI_ROBUST_NORMAL_NP:
     case PTHREAD_MUTEX_PI_ROBUST_ADAPTIVE_NP:
       {
+	/* Currently futex FUTEX_LOCK_PI operation only provides support for
+	   CLOCK_REALTIME and trying to emulate by converting a
+	   CLOCK_MONOTONIC to CLOCK_REALTIME will take in account possible
+	   changes to the wall clock.  */
+	if (__glibc_unlikely (clockid != CLOCK_REALTIME))
+	  return EINVAL;
+
 	int kind, robust;
 	{
 	  /* See concurrency notes regarding __kind in struct __pthread_mutex_s