From patchwork Tue Mar 10 21:39:34 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Duyck X-Patchwork-Id: 448725 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id AD7AD140146 for ; Wed, 11 Mar 2015 08:39:44 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752848AbbCJVjk (ORCPT ); Tue, 10 Mar 2015 17:39:40 -0400 Received: from mx1.redhat.com ([209.132.183.28]:54659 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752129AbbCJVjj (ORCPT ); Tue, 10 Mar 2015 17:39:39 -0400 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id t2ALdZq5013393 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Tue, 10 Mar 2015 17:39:35 -0400 Received: from [192.168.122.173] (ovpn-112-78.phx2.redhat.com [10.3.112.78]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t2ALdYlU031920; Tue, 10 Mar 2015 17:39:35 -0400 Subject: [net-next PATCH] fib_trie: Address possible NULL pointer dereference in resize From: Alexander Duyck To: netdev@vger.kernel.org Cc: davem@davemloft.net, dan.carpenter@oracle.com Date: Tue, 10 Mar 2015 14:39:34 -0700 Message-ID: <20150310213929.2235.18452.stgit@ahduyck-vm-fedora20> User-Agent: StGit/0.17-dirty MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org If the inflate call failed it would return NULL. As a result tp would be set to NULL and cause use to trigger a NULL pointer dereference in should_halve if the inflate failed on the first attempt. In order to prevent this we should decrement max_work before we actually attempt to inflate as this will force us to exit before attempting to halve a node we should have inflated. In order to keep things symmetric between inflate and halve I went ahead and also moved the decrement of max_work for the halve case as well so we take care of that before we actually attempt to halve the tnode. Fixes: 88bae714 ("fib_trie: Add key vector to root, return parent key_vector in resize") Reported-by: Dan Carpenter Signed-off-by: Alexander Duyck --- net/ipv4/fib_trie.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) -- To unsubscribe from this list: send the line "unsubscribe netdev" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/net/ipv4/fib_trie.c b/net/ipv4/fib_trie.c index 44cab1d..83290be 100644 --- a/net/ipv4/fib_trie.c +++ b/net/ipv4/fib_trie.c @@ -830,7 +830,7 @@ static struct key_vector *resize(struct trie *t, struct key_vector *tn) /* Double as long as the resulting node has a number of * nonempty nodes that are above the threshold. */ - while (should_inflate(tp, tn) && max_work) { + while (should_inflate(tp, tn) && max_work--) { tp = inflate(t, tn); if (!tp) { #ifdef CONFIG_IP_FIB_TRIE_STATS @@ -839,7 +839,6 @@ static struct key_vector *resize(struct trie *t, struct key_vector *tn) break; } - max_work--; tn = get_child(tp, cindex); } @@ -850,7 +849,7 @@ static struct key_vector *resize(struct trie *t, struct key_vector *tn) /* Halve as long as the number of empty children in this * node is above threshold. */ - while (should_halve(tp, tn) && max_work) { + while (should_halve(tp, tn) && max_work--) { tp = halve(t, tn); if (!tp) { #ifdef CONFIG_IP_FIB_TRIE_STATS @@ -859,7 +858,6 @@ static struct key_vector *resize(struct trie *t, struct key_vector *tn) break; } - max_work--; tn = get_child(tp, cindex); }