Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp2412808imm; Thu, 7 Jun 2018 10:09:22 -0700 (PDT) X-Google-Smtp-Source: ADUXVKJy1fFfYHLN+RW5yZgqZrOnFjPdFDVHPfs5AVxkgm6VPl/jrFeyzS/REpOVe2V81j4UD+Ex X-Received: by 2002:a17:902:683:: with SMTP id 3-v6mr2873671plh.291.1528391362524; Thu, 07 Jun 2018 10:09:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528391362; cv=none; d=google.com; s=arc-20160816; b=LicuH6mTi/wCcHUqPD4L14bZGsCHEQsNb/Pe5sV93B2gaOn5cqzWpH0fBB75aeQCJA fHRHSvBNGJ1HWLL73Czq+WUX8M36BUa0c8yPvlnJzhHpVvtaqU8BwW/NCrTRVkM4JDbN Mfg/JBjdMteK1Qo+7o/1QCPZNAS55nq7wg4T7SY0F6uSDpkpua+PM5GV/8INE8RQcLy2 t85BO6QwWb8rJPE4MkEZrrt3HqVQMACuwcFvoxPhFSV10TE/DOqJIx9BoCSwtRsK5rya mX9JwnPmwdOcmg9BB7aaqhzfV55Y5fFS/7/gXB35yLkb7aF42q2jybzkbwZQm1Tj9eh9 yfQg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:subject:message-id:date:cc:to :from:mime-version:content-transfer-encoding:content-disposition :arc-authentication-results; bh=an+RSUcRTf9hx/WHc6kd0j+3JSKNlpUKfAVolfLWKtI=; b=zwFn7NBtFCp8Aocxr9+6QMutrEV3IK8CSjU6cgR+15Us4bQQC4ADcdCfUjNZKSIUZN Zokzq6ei4mik0wpzyvTpOVwk8ul5MGPUJeEg9K9njxushdI5sZLjX+4N3YIxNlC8PQ2g Q6CSghFMYg9K77elMZT5f5Ks1+r7YD/6IBdVEK5Pjcca+HZgau3V/7FIostvse2t9uAh appF5KzEK8TF4y3zeskdY1jUpJURnxB2bYpNo6Q19yxQsruKf0GQgktVEZlwWrmE0AmM iGFjSg/eWtkDWnpaS8H26ZNupFoK2uYmNBXKVnEBbvPOtVMB61gndPygu8/0fIym25dp wH2A== 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 m37-v6si54638284pla.148.2018.06.07.10.08.29; Thu, 07 Jun 2018 10:09:22 -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 S933667AbeFGOaU (ORCPT + 99 others); Thu, 7 Jun 2018 10:30:20 -0400 Received: from shadbolt.e.decadent.org.uk ([88.96.1.126]:39420 "EHLO shadbolt.e.decadent.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933065AbeFGOJK (ORCPT ); Thu, 7 Jun 2018 10:09:10 -0400 Received: from [148.252.241.226] (helo=deadeye) by shadbolt.decadent.org.uk with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1fQvbA-0005a0-JT; Thu, 07 Jun 2018 15:09:08 +0100 Received: from ben by deadeye with local (Exim 4.91) (envelope-from ) id 1fQvb7-00033S-G5; Thu, 07 Jun 2018 15:09:05 +0100 Content-Type: text/plain; charset="UTF-8" Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 From: Ben Hutchings To: linux-kernel@vger.kernel.org, stable@vger.kernel.org CC: akpm@linux-foundation.org, "Cong Wang" , "Pablo Neira Ayuso" , "Florian Westphal" , "Eric Dumazet" Date: Thu, 07 Jun 2018 15:05:21 +0100 Message-ID: X-Mailer: LinuxStableQueue (scripts by bwh) Subject: [PATCH 3.16 235/410] netfilter: ipt_CLUSTERIP: fix a refcount bug in clusterip_config_find_get() In-Reply-To: X-SA-Exim-Connect-IP: 148.252.241.226 X-SA-Exim-Mail-From: ben@decadent.org.uk X-SA-Exim-Scanned: No (on shadbolt.decadent.org.uk); SAEximRunCond expanded to false Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 3.16.57-rc1 review patch. If anyone has any objections, please let me know. ------------------ From: Cong Wang commit db93a3632b0f8773a3899e04a3a3e0aa7a26eb46 upstream. In clusterip_config_find_get() we hold RCU read lock so it could run concurrently with clusterip_config_entry_put(), as a result, the refcnt could go back to 1 from 0, which leads to a double list_del()... Just replace refcount_inc() with refcount_inc_not_zero(), as for c->refcount. Fixes: d73f33b16883 ("netfilter: CLUSTERIP: RCU conversion") Cc: Eric Dumazet Cc: Pablo Neira Ayuso Cc: Florian Westphal Signed-off-by: Cong Wang Reviewed-by: Florian Westphal Signed-off-by: Pablo Neira Ayuso [bwh: Backported to 3.16: s/refcount/atomic/] Signed-off-by: Ben Hutchings --- net/ipv4/netfilter/ipt_CLUSTERIP.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) --- a/net/ipv4/netfilter/ipt_CLUSTERIP.c +++ b/net/ipv4/netfilter/ipt_CLUSTERIP.c @@ -147,8 +147,12 @@ clusterip_config_find_get(struct net *ne if (c) { if (unlikely(!atomic_inc_not_zero(&c->refcount))) c = NULL; - else if (entry) - atomic_inc(&c->entries); + else if (entry) { + if (unlikely(!atomic_inc_not_zero(&c->entries))) { + clusterip_config_put(c); + c = NULL; + } + } } rcu_read_unlock_bh();