[lkml]   [2015]   [Feb]   [18]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
Messages in this thread
Patch in this message
Subject[tip:locking/core] locking/rtmutex: Avoid a NULL pointer dereference on deadlock
Commit-ID:  8d1e5a1a1ccf5ae9d8a5a0ee7960202ccb0c5429
Author: Sebastian Andrzej Siewior <>
AuthorDate: Tue, 17 Feb 2015 16:43:43 +0100
Committer: Ingo Molnar <>
CommitDate: Wed, 18 Feb 2015 10:20:32 +0100

locking/rtmutex: Avoid a NULL pointer dereference on deadlock

With task_blocks_on_rt_mutex() returning early -EDEADLK we never
add the waiter to the waitqueue. Later, we try to remove it via
remove_waiter() and go boom in rt_mutex_top_waiter() because
rb_entry() gives a NULL pointer.

( Tested on v3.18-RT where rtmutex is used for regular mutex and I
tried to get one twice in a row. )

Not sure when this started but I guess 397335f004f4 ("rtmutex: Fix
deadlock detector for real") or commit 3d5c9340d194 ("rtmutex:
Handle deadlock detection smarter").

Signed-off-by: Sebastian Andrzej Siewior <>
Acked-by: Peter Zijlstra <>
Cc: Thomas Gleixner <>
Cc: <> # for v3.16 and later kernels
Signed-off-by: Ingo Molnar <>
kernel/locking/rtmutex.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/kernel/locking/rtmutex.c b/kernel/locking/rtmutex.c
index 3059bc2f..e16e554 100644
--- a/kernel/locking/rtmutex.c
+++ b/kernel/locking/rtmutex.c
@@ -1193,7 +1193,8 @@ rt_mutex_slowlock(struct rt_mutex *lock, int state,
ret = __rt_mutex_slowlock(lock, state, timeout, &waiter);

if (unlikely(ret)) {
- remove_waiter(lock, &waiter);
+ if (rt_mutex_has_waiters(lock))
+ remove_waiter(lock, &waiter);
rt_mutex_handle_deadlock(ret, chwalk, &waiter);

 \ /
  Last update: 2015-02-18 18:41    [W:0.028 / U:1.328 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site