Skip to content

Commit 179c85e

Browse files
arndbLinus Torvalds
authored andcommitted
futex_compat: fix list traversal bugs
The futex list traversal on the compat side appears to have a bug. It's loop termination condition compares: while (compat_ptr(uentry) != &head->list) But that can't be right because "uentry" has the special "pi" indicator bit still potentially set at bit 0. This is cleared by fetch_robust_entry() into the "entry" return value. What this seems to mean is that the list won't terminate when list iteration gets back to the the head. And we'll also process the list head like a normal entry, which could cause all kinds of problems. So we should check for equality with "entry". That pointer is of the non-compat type so we have to do a little casting to keep the compiler and sparse happy. The same problem can in theory occur with the 'pending' variable, although that has not been reported from users so far. Based on the original patch from David Miller. Acked-by: Ingo Molnar <[email protected]> Cc: Thomas Gleixner <[email protected]> Cc: David Miller <[email protected]> Signed-off-by: Arnd Bergmann <[email protected]> Cc: <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent a570ab6 commit 179c85e

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

kernel/futex_compat.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,10 @@ void compat_exit_robust_list(struct task_struct *curr)
6161
if (fetch_robust_entry(&upending, &pending,
6262
&head->list_op_pending, &pip))
6363
return;
64-
if (upending)
64+
if (pending)
6565
handle_futex_death((void __user *)pending + futex_offset, curr, pip);
6666

67-
while (compat_ptr(uentry) != &head->list) {
67+
while (entry != (struct robust_list __user *) &head->list) {
6868
/*
6969
* A pending lock might already be on the list, so
7070
* dont process it twice:

0 commit comments

Comments
 (0)