Skip to content

Commit

Permalink
[PATCH] Fix semundo lock leakage
Browse files Browse the repository at this point in the history
semundo->lock can leak if semundo->refcount goes from 2 to 1 while
another thread has it locked.  This causes major problems for PREEMPT
kernels.

The simplest fix for now is to undo the single-thread optimization.

This bug was found via relentless testing by Dominik Karall.

Signed-off-by: Ingo Molnar <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
Ingo Molnar authored and Linus Torvalds committed Aug 5, 2005
1 parent ba02508 commit 00a5dfd
Showing 1 changed file with 3 additions and 7 deletions.
10 changes: 3 additions & 7 deletions ipc/sem.c
Original file line number Diff line number Diff line change
Expand Up @@ -895,7 +895,7 @@ static inline void lock_semundo(void)
struct sem_undo_list *undo_list;

undo_list = current->sysvsem.undo_list;
if ((undo_list != NULL) && (atomic_read(&undo_list->refcnt) != 1))
if (undo_list)
spin_lock(&undo_list->lock);
}

Expand All @@ -915,7 +915,7 @@ static inline void unlock_semundo(void)
struct sem_undo_list *undo_list;

undo_list = current->sysvsem.undo_list;
if ((undo_list != NULL) && (atomic_read(&undo_list->refcnt) != 1))
if (undo_list)
spin_unlock(&undo_list->lock);
}

Expand Down Expand Up @@ -943,9 +943,7 @@ static inline int get_undo_list(struct sem_undo_list **undo_listp)
if (undo_list == NULL)
return -ENOMEM;
memset(undo_list, 0, size);
/* don't initialize unodhd->lock here. It's done
* in copy_semundo() instead.
*/
spin_lock_init(&undo_list->lock);
atomic_set(&undo_list->refcnt, 1);
current->sysvsem.undo_list = undo_list;
}
Expand Down Expand Up @@ -1231,8 +1229,6 @@ int copy_semundo(unsigned long clone_flags, struct task_struct *tsk)
error = get_undo_list(&undo_list);
if (error)
return error;
if (atomic_read(&undo_list->refcnt) == 1)
spin_lock_init(&undo_list->lock);
atomic_inc(&undo_list->refcnt);
tsk->sysvsem.undo_list = undo_list;
} else
Expand Down

0 comments on commit 00a5dfd

Please sign in to comment.