Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp6262928imu; Mon, 21 Jan 2019 06:03:37 -0800 (PST) X-Google-Smtp-Source: ALg8bN6RRM/cA3b2qTR7W0c52ZknOf8hLzi3Mf1T9xpr1EeSMRn4/5F7rs/jkJkn1Jf+0fTxi0CU X-Received: by 2002:a63:d10:: with SMTP id c16mr28394584pgl.382.1548079417896; Mon, 21 Jan 2019 06:03:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548079417; cv=none; d=google.com; s=arc-20160816; b=oRxrmWmETtNmCNPPII8l+WRBNGyowr5nyG5B8mhTmtefZHwI3QxLDz9GgjGfqjZbpl Tg98HZbnpnXyMxUoH8bYxUlhnDduOHF9CAJm9D7HodBp1fIZUGAzuPS1RhqXwJt1a/TZ EorXg4a0ZIryBIkEDH66BZ23K12NLza0Kz9z2znRQ2zsKq1CuSsuEO5WdzGddhYnZCKk SCA+yKHoB6Aup4/iKPuqQhUbem3x/r1SJzZmGWwBu5ZEwuSd9S403+dpiPZX4l6brdme 10iRPLHuYSg98Re1J4h2o5CUTGo8VrgGiTPoAzsHaN9u+sml28C7f+ITlqRMHgcy6f5P 3rzw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=XQEoYuZIZ6B/Z9m8qJ0YCm2NhUOpqggHNjIy8j93U/U=; b=rP1OIKQ6r8rmt6JbXFO16RyIDEQTOT0AA8DuEuR0fIhn7ou7ew7AExC38uG4waTAXQ ZYtfkrPRCEyuuXiNgzcxm23M4rNxD4Xv+SbIF47GoWffpYgcuE6Jqf55fvQF/ubkJBcF 1kACBLE/6t4mLe3BhdbmLDrRE2q/d/ivTofRLatZiScrsY2ujocJCWeyoaSApRazdn0t iqee5eH+J5LOT7VvH2b/id++Ob40s6uCJAGcdrdQHWtCBMQPv8ElLaUbWSxbSacjQxuy fvi3CEfON5S0uR6u/aVrGDt1uocdV1onj1uuU16rjuvqP6MFJgtxpQ2aSR5GOSq9rHWK ZWLg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=CwL29NAL; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i13si12981263pgj.199.2019.01.21.06.03.12; Mon, 21 Jan 2019 06:03:37 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=CwL29NAL; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732315AbfAUOAF (ORCPT + 99 others); Mon, 21 Jan 2019 09:00:05 -0500 Received: from mail.kernel.org ([198.145.29.99]:46392 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732301AbfAUOAD (ORCPT ); Mon, 21 Jan 2019 09:00:03 -0500 Received: from localhost (5356596B.cm-6-7b.dynamic.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 0994D20879; Mon, 21 Jan 2019 14:00:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1548079202; bh=iFLA/yE+pk7cfPYEDCbQJRkxwF+M5Uq9JduBAy4HCv8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=CwL29NAL5vIKo5CMg8op5fDRnTq6IrTc8iXQosIy+8QymSmPdLmvUFfe/SKIWUUk9 /kRRkRTCxVvA4ouqmOdYLF1YeBQLAD6o/K+9jNzQT25mHohjxX2P9+M6RFUKan0a3x k1CH+NKWcTimn7KcslScAf4h3CrxvLVblVa0AH5g= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Shawn Bohrer , Florian Westphal , Pablo Neira Ayuso Subject: [PATCH 4.19 09/99] netfilter: nf_conncount: restart search when nodes have been erased Date: Mon, 21 Jan 2019 14:48:01 +0100 Message-Id: <20190121134914.273684405@linuxfoundation.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190121134913.924726465@linuxfoundation.org> References: <20190121134913.924726465@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review X-Patchwork-Hint: ignore MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.19-stable review patch. If anyone has any objections, please let me know. ------------------ From: Florian Westphal commit e8cfb372b38a1b8979aa7f7631fb5e7b11c3793c upstream. Shawn Bohrer reported a following crash: |RIP: 0010:rb_erase+0xae/0x360 [..] Call Trace: nf_conncount_destroy+0x59/0xc0 [nf_conncount] cleanup_match+0x45/0x70 [ip_tables] ... Shawn tracked this down to bogus 'parent' pointer: Problem is that when we insert a new node, then there is a chance that the 'parent' that we found was also passed to tree_nodes_free() (because that node was empty) for erase+free. Instead of trying to be clever and detect when this happens, restart the search if we have evicted one or more nodes. To prevent frequent restarts, do not perform gc on the second round. Also, unconditionally schedule the gc worker. The condition gc_count > ARRAY_SIZE(gc_nodes)) cannot be true unless tree grows very large, as the height of the tree will be low even with hundreds of nodes present. Fixes: 5c789e131cbb9 ("netfilter: nf_conncount: Add list lock and gc worker, and RCU for init tree search") Reported-by: Shawn Bohrer Reviewed-by: Shawn Bohrer Signed-off-by: Florian Westphal Signed-off-by: Pablo Neira Ayuso Signed-off-by: Greg Kroah-Hartman --- net/netfilter/nf_conncount.c | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) --- a/net/netfilter/nf_conncount.c +++ b/net/netfilter/nf_conncount.c @@ -346,9 +346,10 @@ insert_tree(struct net *net, struct nf_conncount_tuple *conn; unsigned int count = 0, gc_count = 0; bool node_found = false; + bool do_gc = true; spin_lock_bh(&nf_conncount_locks[hash]); - +restart: parent = NULL; rbnode = &(root->rb_node); while (*rbnode) { @@ -381,21 +382,16 @@ insert_tree(struct net *net, if (gc_count >= ARRAY_SIZE(gc_nodes)) continue; - if (nf_conncount_gc_list(net, &rbconn->list)) + if (do_gc && nf_conncount_gc_list(net, &rbconn->list)) gc_nodes[gc_count++] = rbconn; } if (gc_count) { tree_nodes_free(root, gc_nodes, gc_count); - /* tree_node_free before new allocation permits - * allocator to re-use newly free'd object. - * - * This is a rare event; in most cases we will find - * existing node to re-use. (or gc_count is 0). - */ - - if (gc_count >= ARRAY_SIZE(gc_nodes)) - schedule_gc_worker(data, hash); + schedule_gc_worker(data, hash); + gc_count = 0; + do_gc = false; + goto restart; } if (node_found)