Skip to content

Commit 00a5dfd

Browse files
Ingo MolnarLinus Torvalds
authored andcommitted
[PATCH] Fix semundo lock leakage
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 <mingo@elte.hu> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
1 parent ba02508 commit 00a5dfd

1 file changed

Lines changed: 3 additions & 7 deletions

File tree

‎ipc/sem.c‎

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -895,7 +895,7 @@ static inline void lock_semundo(void)
895895
struct sem_undo_list *undo_list;
896896

897897
undo_list = current->sysvsem.undo_list;
898-
if ((undo_list != NULL) && (atomic_read(&undo_list->refcnt) != 1))
898+
if (undo_list)
899899
spin_lock(&undo_list->lock);
900900
}
901901

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

917917
undo_list = current->sysvsem.undo_list;
918-
if ((undo_list != NULL) && (atomic_read(&undo_list->refcnt) != 1))
918+
if (undo_list)
919919
spin_unlock(&undo_list->lock);
920920
}
921921

@@ -943,9 +943,7 @@ static inline int get_undo_list(struct sem_undo_list **undo_listp)
943943
if (undo_list == NULL)
944944
return -ENOMEM;
945945
memset(undo_list, 0, size);
946-
/* don't initialize unodhd->lock here. It's done
947-
* in copy_semundo() instead.
948-
*/
946+
spin_lock_init(&undo_list->lock);
949947
atomic_set(&undo_list->refcnt, 1);
950948
current->sysvsem.undo_list = undo_list;
951949
}
@@ -1231,8 +1229,6 @@ int copy_semundo(unsigned long clone_flags, struct task_struct *tsk)
12311229
error = get_undo_list(&undo_list);
12321230
if (error)
12331231
return error;
1234-
if (atomic_read(&undo_list->refcnt) == 1)
1235-
spin_lock_init(&undo_list->lock);
12361232
atomic_inc(&undo_list->refcnt);
12371233
tsk->sysvsem.undo_list = undo_list;
12381234
} else

0 commit comments

Comments
 (0)