[BZ,19944] nptl/pthread_mutex*lock: don't ignore unknown error codes

Message ID 1460576781-12017-1-git-send-email-bigeasy@linutronix.de
State New, archived
Headers

Commit Message

Sebastian Andrzej Siewior April 13, 2016, 7:46 p.m. UTC
  pthread_mutex_lock(), pthread_mutex_trylock() and pthread_mutex_unlock()
ignore the return code from the futex syscall unless it is something
the function expects.
This patch forwards the error code to the user instead of simply
ignoring it.

2016-04-13  Sebastian Andrzej Siewior  <bigeasy@linutronix.de>
	[BZ #19944]
	* nptl/pthread_mutex_lock.c: return unhandled sys_futex error.
	* nptl/pthread_mutex_trylock.c: return unhandled sys_futex
	error.
	* nptl/pthread_mutex_unlock.c: return unhandled sys_futex error.
---
 nptl/pthread_mutex_lock.c    | 3 ++-
 nptl/pthread_mutex_trylock.c | 2 ++
 nptl/pthread_mutex_unlock.c  | 5 ++++-
 3 files changed, 8 insertions(+), 2 deletions(-)
  

Comments

Roland McGrath April 13, 2016, 8:15 p.m. UTC | #1
I won't bother with the several style problems in your patch.  Please see
previous discussions about the futex error cases.  Torvald was leading the
charge on converting things to use the new internal layers that handle
futex error checking.  The only changes we want are in that direction.


Thanks,
Roland
  
Sebastian Andrzej Siewior April 13, 2016, 8:52 p.m. UTC | #2
On 2016-04-13 13:15:14 [-0700], Roland McGrath wrote:
> I won't bother with the several style problems in your patch.  Please see
> previous discussions about the futex error cases.  Torvald was leading the
> charge on converting things to use the new internal layers that handle
> futex error checking.  The only changes we want are in that direction.

Are we talking about this thread:
  https://sourceware.org/ml/libc-alpha/2014-09/msg00381.html

Subject: Futex error handling
Date: Tue, 16 Sep 2014 17:36:25 +0200

> Thanks,
> Roland

Sebastian
  
Torvald Riegel April 14, 2016, 2:36 p.m. UTC | #3
On Wed, 2016-04-13 at 22:52 +0200, Sebastian Andrzej Siewior wrote:
> On 2016-04-13 13:15:14 [-0700], Roland McGrath wrote:
> > I won't bother with the several style problems in your patch.  Please see
> > previous discussions about the futex error cases.  Torvald was leading the
> > charge on converting things to use the new internal layers that handle
> > futex error checking.  The only changes we want are in that direction.
> 
> Are we talking about this thread:
>   https://sourceware.org/ml/libc-alpha/2014-09/msg00381.html
> 
> Subject: Futex error handling
> Date: Tue, 16 Sep 2014 17:36:25 +0200

That is the start of it.  The result is that we have a new
glibc-internal futex interface that does error checking, see
sysdeps/unix/sysv/linux/futex-internal.h and
sysdeps/nptl/futex-internal.h for details.

The way we handle futex errors should be consistent with what we do in
there; if you spot missing errors we do not test for explicitly (ie,
which are listed in the updated futex manpage but not part of the glibc
code), please fix this in the wrappers.

Regarding the mutex changes, what we should do there eventually is use
the new futex interface.  We cannot just forward errors to the callers
of POSIX functions because POSIX might not specify the same error codes
as futexes do.
  

Patch

diff --git a/nptl/pthread_mutex_lock.c b/nptl/pthread_mutex_lock.c
index bdfa529f639b..f1b9aa1b9f84 100644
--- a/nptl/pthread_mutex_lock.c
+++ b/nptl/pthread_mutex_lock.c
@@ -354,7 +354,8 @@  __pthread_mutex_lock_full (pthread_mutex_t *mutex)
 		/* Delay the thread indefinitely.  */
 		while (1)
 		  pause_not_cancel ();
-	      }
+	      } else if (INTERNAL_SYSCALL_ERROR_P (e, __err))
+		      return INTERNAL_SYSCALL_ERRNO (e, __err);
 
 	    oldval = mutex->__data.__lock;
 
diff --git a/nptl/pthread_mutex_trylock.c b/nptl/pthread_mutex_trylock.c
index 48c7865702ba..45c416b75cf2 100644
--- a/nptl/pthread_mutex_trylock.c
+++ b/nptl/pthread_mutex_trylock.c
@@ -265,6 +265,8 @@  __pthread_mutex_trylock (pthread_mutex_t *mutex)
 		THREAD_SETMEM (THREAD_SELF, robust_head.list_op_pending, NULL);
 
 		return EBUSY;
+	      } else if (INTERNAL_SYSCALL_ERROR_P (e, __err)) {
+		      return INTERNAL_SYSCALL_ERRNO (e, __err);
 	      }
 
 	    oldval = mutex->__data.__lock;
diff --git a/nptl/pthread_mutex_unlock.c b/nptl/pthread_mutex_unlock.c
index 334ce383420e..787fb3017c44 100644
--- a/nptl/pthread_mutex_unlock.c
+++ b/nptl/pthread_mutex_unlock.c
@@ -243,8 +243,11 @@  __pthread_mutex_unlock_full (pthread_mutex_t *mutex, int decr)
 								  tid)))
 	{
 	  INTERNAL_SYSCALL_DECL (__err);
-	  INTERNAL_SYSCALL (futex, __err, 2, &mutex->__data.__lock,
+	  int e = INTERNAL_SYSCALL (futex, __err, 2, &mutex->__data.__lock,
 			    __lll_private_flag (FUTEX_UNLOCK_PI, private));
+
+	  if (INTERNAL_SYSCALL_ERROR_P (e, __err))
+		  return INTERNAL_SYSCALL_ERRNO (e, __err);
 	}
 
       THREAD_SETMEM (THREAD_SELF, robust_head.list_op_pending, NULL);