Skip to content

Commit

Permalink
lib/list_sort: do not pass bad pointers to cmp callback
Browse files Browse the repository at this point in the history
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 <[email protected]>
Tested-by: Artem Bityutskiy <[email protected]>
Signed-off-by: Artem Bityutskiy <[email protected]>
Cc: <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
dmullis authored and torvalds committed Oct 1, 2010
1 parent 982f7c2 commit f015ac3
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion lib/list_sort.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit f015ac3

Please sign in to comment.