Browse files

lib/list_sort: do not pass bad pointers to cmp callback

commit f015ac3 upstream.

If the original list is a POT in length, the first callback from line 73
will pass a==b both pointing to the original list_head.  This is dangerous
because the 'list_sort()' user can use 'container_of()' and accesses the
"containing" object, which does not necessary exist for the list head.  So
the user can access RAM which does not belong to him.  If this is a write
access, we can end up with memory corruption.

Signed-off-by: Don Mullis <>
Tested-by: Artem Bityutskiy <>
Signed-off-by: Artem Bityutskiy <>
Signed-off-by: Andrew Morton <>
Signed-off-by: Linus Torvalds <>
Signed-off-by: Greg Kroah-Hartman <>
  • Loading branch information...
1 parent 51793ad commit a7b048db83992dba877da7b85d8b1236324f9763 @dmullis dmullis committed with gregkh Sep 30, 2010
Showing with 1 addition and 1 deletion.
  1. +1 −1 lib/list_sort.c
@@ -70,7 +70,7 @@ static void merge_and_restore_back_links(void *priv,
* element comparison is needed, so the client's cmp()
* routine can invoke cond_resched() periodically.
- (*cmp)(priv, tail, tail);
+ (*cmp)(priv, tail->next, tail->next);
tail->next->prev = tail;
tail = tail->next;

0 comments on commit a7b048d

Please sign in to comment.