Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752634AbaLEWrT (ORCPT ); Fri, 5 Dec 2014 17:47:19 -0500 Received: from mail.linuxfoundation.org ([140.211.169.12]:53755 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752430AbaLEWqU (ORCPT ); Fri, 5 Dec 2014 17:46:20 -0500 From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Kevin Hilman , Rob Herring , Gaurav Minocha Subject: [PATCH 3.17 076/122] of/selftest: Fix off-by-one error in removal path Date: Fri, 5 Dec 2014 14:44:10 -0800 Message-Id: <20141205223317.227994267@linuxfoundation.org> X-Mailer: git-send-email 2.1.3 In-Reply-To: <20141205223305.514276242@linuxfoundation.org> References: <20141205223305.514276242@linuxfoundation.org> User-Agent: quilt/0.63-1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 3.17-stable review patch. If anyone has any objections, please let me know. ------------------ From: Grant Likely commit c1a2086e2d8c4eb4e8630ba752e911ec180dec67 upstream. The removal path for selftest data has an off by one error that causes the code to dereference beyond the end of the nodes[] array on the first pass through. The old code only worked by chance on a lot of platforms, but the bug was recently exposed on aarch64. The fix is simple. Decrement the node count before dereferencing, not after. Reported-by: Kevin Hilman Cc: Rob Herring Cc: Gaurav Minocha --- drivers/of/selftest.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) --- a/drivers/of/selftest.c +++ b/drivers/of/selftest.c @@ -799,7 +799,7 @@ static void selftest_data_remove(void) return; } - while (last_node_index >= 0) { + while (last_node_index-- > 0) { if (nodes[last_node_index]) { np = of_find_node_by_path(nodes[last_node_index]->full_name); if (strcmp(np->full_name, "/aliases") != 0) { @@ -812,7 +812,6 @@ static void selftest_data_remove(void) } } } - last_node_index--; } } -- 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/