Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751852Ab0HUKI0 (ORCPT ); Sat, 21 Aug 2010 06:08:26 -0400 Received: from mgw-sa02.nokia.com ([147.243.1.48]:38372 "EHLO mgw-sa02.nokia.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751718Ab0HUKIX (ORCPT ); Sat, 21 Aug 2010 06:08:23 -0400 Subject: [PATCH] lib/list_sort: do not pass bad pointers to cmp callback From: Artem Bityutskiy Reply-To: dedekind1@gmail.com To: Don Mullis Cc: linux-kernel@vger.kernel.org, David Airlie , Dave Chinner In-Reply-To: References: <1281168645-18413-1-git-send-email-dedekind1@gmail.com> <1281261789.2384.11.camel@localhost> Content-Type: text/plain; charset="UTF-8" Date: Sat, 21 Aug 2010 13:06:22 +0300 Message-ID: <1282385182.2358.41.camel@localhost> Mime-Version: 1.0 X-Mailer: Evolution 2.30.2 (2.30.2-4.fc13) Content-Transfer-Encoding: 8bit X-Nokia-AV: Clean Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1512 Lines: 43 From: Don Mullis 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. This patch fixes the issue. Signed-off-by: Don Mullis Tested-by: Artem Bityutskiy Signed-off-by: Artem Bityutskiy Cc: stable@kernel.org --- lib/list_sort.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/lib/list_sort.c b/lib/list_sort.c index 4b5cb79..a7616fa 100644 --- a/lib/list_sort.c +++ b/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; -- 1.7.1.1 -- Best Regards, Artem Bityutskiy (Артём Битюцкий) -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/