Commit f015ac3e authored by Don Mullis's avatar Don Mullis Committed by Linus Torvalds

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

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: default avatarDon Mullis <don.mullis@gmail.com>
Tested-by: default avatarArtem Bityutskiy <Artem.Bityutskiy@nokia.com>
Signed-off-by: default avatarArtem Bityutskiy <Artem.Bityutskiy@nokia.com>
Cc: <stable@kernel.org>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 982f7c2b
...@@ -70,7 +70,7 @@ static void merge_and_restore_back_links(void *priv, ...@@ -70,7 +70,7 @@ static void merge_and_restore_back_links(void *priv,
* element comparison is needed, so the client's cmp() * element comparison is needed, so the client's cmp()
* routine can invoke cond_resched() periodically. * routine can invoke cond_resched() periodically.
*/ */
(*cmp)(priv, tail, tail); (*cmp)(priv, tail->next, tail->next);
tail->next->prev = tail; tail->next->prev = tail;
tail = tail->next; tail = tail->next;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment