Skip to content

Commit

Permalink
spl-mutex: fix race in mutex_exit
Browse files Browse the repository at this point in the history
Prevent race on accessing kmutex_t when the mutex is
embedded in a ref counted structure.

Issue openzfs/zfs#6401

Signed-off-by: Gvozden Neskovic <[email protected]>
  • Loading branch information
ironMann authored and ofaaland committed Aug 3, 2017
1 parent 1f2671b commit a672710
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions include/sys/mutex.h
Original file line number Diff line number Diff line change
Expand Up @@ -183,12 +183,13 @@ spl_mutex_lockdep_on_maybe(kmutex_t *mp) \
*/
#define mutex_exit(mp) \
{ \
spl_mutex_lockdep_off_maybe(mp); \
spin_lock(&(mp)->m_lock); \
spl_mutex_clear_owner(mp); \
spin_lock(&(mp)->m_lock); \
spl_mutex_lockdep_off_maybe(mp); \
mutex_unlock(MUTEX(mp)); \
spin_unlock(&(mp)->m_lock); \
spl_mutex_lockdep_on_maybe(mp); \
spin_unlock(&(mp)->m_lock); \
/* NOTE: do not dereference mp after this point */ \
}

int spl_mutex_init(void);
Expand Down

0 comments on commit a672710

Please sign in to comment.