Received: by 10.192.165.156 with SMTP id m28csp1127755imm; Wed, 11 Apr 2018 12:58:54 -0700 (PDT) X-Google-Smtp-Source: AIpwx4/trvF7IWV2qIj1J26n2bRQTX1Xk1sHpPyrHqr02CsaW/uZMyekPAD3FBORWVUEdrJTSadH X-Received: by 2002:a17:902:784c:: with SMTP id e12-v6mr6580421pln.60.1523476734172; Wed, 11 Apr 2018 12:58:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523476734; cv=none; d=google.com; s=arc-20160816; b=ouqkBXU6dZt823rxmHXhwfPz9ImzeihHuXr9zoxdn3a7FUr9UTEg104AaQ9a2LxaOa 6QE6RaO95rrBY5/h3HojZP8jQwpMaJLEhYIQER96xAL8wiMyFyEnjA5fDCsvrVATU9Cw jHHZJG6FDFLnF0FvJuaGwrblL6vbFWlO+IzYAxF31/d1GkDGx+0WHbqk+KhxQKhZCy2C Yd88QgCr1sXwO17sP2tRhpf5EuFm0h2IAzZFR/0Q/Q+OM5jZAoGCqdSNUTXhTANa+XKg gyb6Gq0WgC5+dbTMA2ywO8V4sdjMWkuwrjSy1RYzVmuSFxY0r5vxKVPt4RG7Td7sm9Q9 BY1g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=bH4/jIF4rRcQpImbxb81G4mgfRQS8kZP+UFRXrjQ+IQ=; b=qEx0KzMnoXlolZWouKMNQgMWAhDhpSKyh1HgxThpYw6yLKq489Ni6aNuriGtKmHFxK TWzcZdZ+dhDrnbmiutPyhx0WATP/oDPNjO16C4y40zvIBsvyqoNnHoyO20+zyopDuwPI 5mbd8hdkZTzRvQi6igkapt2fa8eUtPXS8PX3ZdLS83mcdTIaWk7Glik/4kmHZ+I8gheS 9r7QdAO1sDPxAPmY9p0Vg9sC+kej178LHamOCAv1rg2AV1hQO6nKyphPV758qBbfIY+i E+XDjwxVRlW5O+cu0uUthLAdDD6ZQdMwlJdg7ROCSfWAJWcBCC8EEHQzAJ60lZZ1S3KJ zpDQ== ARC-Authentication-Results: i=1; mx.google.com; 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 o17si1174765pge.787.2018.04.11.12.58.17; Wed, 11 Apr 2018 12:58:54 -0700 (PDT) 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; 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 S1756414AbeDKS51 (ORCPT + 99 others); Wed, 11 Apr 2018 14:57:27 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:36286 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754476AbeDKS5Y (ORCPT ); Wed, 11 Apr 2018 14:57:24 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 179EBD9E; Wed, 11 Apr 2018 18:57:23 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Liping Zhang , Pablo Neira Ayuso , Sasha Levin Subject: [PATCH 4.9 102/310] netfilter: ctnetlink: fix incorrect nf_ct_put during hash resize Date: Wed, 11 Apr 2018 20:34:01 +0200 Message-Id: <20180411183626.613906223@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180411183622.305902791@linuxfoundation.org> References: <20180411183622.305902791@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.9-stable review patch. If anyone has any objections, please let me know. ------------------ From: Liping Zhang [ Upstream commit fefa92679dbe0c613e62b6c27235dcfbe9640ad1 ] If nf_conntrack_htable_size was adjusted by the user during the ct dump operation, we may invoke nf_ct_put twice for the same ct, i.e. the "last" ct. This will cause the ct will be freed but still linked in hash buckets. It's very easy to reproduce the problem by the following commands: # while : ; do echo $RANDOM > /proc/sys/net/netfilter/nf_conntrack_buckets done # while : ; do conntrack -L done # iperf -s 127.0.0.1 & # iperf -c 127.0.0.1 -P 60 -t 36000 After a while, the system will hang like this: NMI watchdog: BUG: soft lockup - CPU#1 stuck for 22s! [bash:20184] NMI watchdog: BUG: soft lockup - CPU#0 stuck for 22s! [iperf:20382] ... So at last if we find cb->args[1] is equal to "last", this means hash resize happened, then we can set cb->args[1] to 0 to fix the above issue. Fixes: d205dc40798d ("[NETFILTER]: ctnetlink: fix deadlock in table dumping") Signed-off-by: Liping Zhang Signed-off-by: Pablo Neira Ayuso Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- net/netfilter/nf_conntrack_netlink.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) --- a/net/netfilter/nf_conntrack_netlink.c +++ b/net/netfilter/nf_conntrack_netlink.c @@ -890,8 +890,13 @@ restart: } out: local_bh_enable(); - if (last) + if (last) { + /* nf ct hash resize happened, now clear the leftover. */ + if ((struct nf_conn *)cb->args[1] == last) + cb->args[1] = 0; + nf_ct_put(last); + } while (i) { i--;