Received: by 10.213.65.68 with SMTP id h4csp244987imn; Fri, 23 Mar 2018 03:48:41 -0700 (PDT) X-Google-Smtp-Source: AG47ELs080tZ3ON373EOBpsoBskE7//na1Kyt+62+cOocxA2LH4t5fblybIuP6+pW68XDOwwqxw0 X-Received: by 2002:a17:902:5793:: with SMTP id l19-v6mr10744097pli.386.1521802121121; Fri, 23 Mar 2018 03:48:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521802121; cv=none; d=google.com; s=arc-20160816; b=DgHbCmtduNfMo+ujvqv6VNHozjElc4KKqTfT7mkqveT/Zxlh+eZ9jg0wYKeMci4fam 2RPSNk94kPO9l782jAjNoCMu7om8P9/W9uyUjvvqrprI+HAKg6ZGS/HxHaqBv2UgjuD9 HKSnwOgAJsAQ11t5HPAXbNSJyDya2mwdkWU5160uixkHFUWrtDYzaz55+B7+lcfKDd5H dG/CfJ5iR+oBsHwBM7p4PyqPMK7Bg1gkR1rSoQoHOQyXCraJe0HZkMq/nr83YkjcE63B QZKRAJZAZZbig47LCZTZ6Mj3xjN5gE6jSUj6Ohh79Hdo0enleqO1R5X1YkKfV5/tK32/ ZNAQ== 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=EnoQP+ni2v24iiECeokEjwHfYEvWQtLHyYeVtXPBAb4=; b=bL+DCwUAoXxlszOUd9V6Z6RIzXg9KJCHfR3HjhX3uj67pzO9eAb9G5BdiV+ouXzBqI v1RByJt/XHhAD4td28cF+WPDDWFSakQg44Q2WV3XwGABfuh45w5GX/tZCgeQ8J+e1+zv lyd1v1SwSFHvMuesI06zjgVBVHm/s2Mj4mlwnHPCaR+BRKa6urljcPZkJdBpCVA+33nx js3P7pOIsu3GiuNT6k0+sFPtMgBEhgbweuSIy7nL4GRcrvDYCyfaCcIPkufBoQQ4PByG kmbromsFMYoc5M/P1pKWqglkri+42U9zoDgGCe4hDUtrA/CRX6kl+FunY1vrtvSsTDio 60XA== 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 37-v6si8300655plq.451.2018.03.23.03.48.26; Fri, 23 Mar 2018 03:48:41 -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 S1755502AbeCWKrh (ORCPT + 99 others); Fri, 23 Mar 2018 06:47:37 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:45528 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933420AbeCWKPM (ORCPT ); Fri, 23 Mar 2018 06:15:12 -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 E40B71275; Fri, 23 Mar 2018 10:15:11 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Gao Feng , Liping Zhang , Pablo Neira Ayuso , Sasha Levin Subject: [PATCH 4.4 38/97] netfilter: xt_CT: fix refcnt leak on error path Date: Fri, 23 Mar 2018 10:54:25 +0100 Message-Id: <20180323094159.781131756@linuxfoundation.org> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180323094157.535925724@linuxfoundation.org> References: <20180323094157.535925724@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.4-stable review patch. If anyone has any objections, please let me know. ------------------ From: Gao Feng [ Upstream commit 470acf55a021713869b9bcc967268ac90c8a0fac ] There are two cases which causes refcnt leak. 1. When nf_ct_timeout_ext_add failed in xt_ct_set_timeout, it should free the timeout refcnt. Now goto the err_put_timeout error handler instead of going ahead. 2. When the time policy is not found, we should call module_put. Otherwise, the related cthelper module cannot be removed anymore. It is easy to reproduce by typing the following command: # iptables -t raw -A OUTPUT -p tcp -j CT --helper ftp --timeout xxx Signed-off-by: Gao Feng Signed-off-by: Liping Zhang Signed-off-by: Pablo Neira Ayuso Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- net/netfilter/xt_CT.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) --- a/net/netfilter/xt_CT.c +++ b/net/netfilter/xt_CT.c @@ -168,8 +168,10 @@ xt_ct_set_timeout(struct nf_conn *ct, co goto err_put_timeout; } timeout_ext = nf_ct_timeout_ext_add(ct, timeout, GFP_ATOMIC); - if (timeout_ext == NULL) + if (!timeout_ext) { ret = -ENOMEM; + goto err_put_timeout; + } rcu_read_unlock(); return ret; @@ -201,6 +203,7 @@ static int xt_ct_tg_check(const struct x struct xt_ct_target_info_v1 *info) { struct nf_conntrack_zone zone; + struct nf_conn_help *help; struct nf_conn *ct; int ret = -EOPNOTSUPP; @@ -249,7 +252,7 @@ static int xt_ct_tg_check(const struct x if (info->timeout[0]) { ret = xt_ct_set_timeout(ct, par, info->timeout); if (ret < 0) - goto err3; + goto err4; } __set_bit(IPS_CONFIRMED_BIT, &ct->status); nf_conntrack_get(&ct->ct_general); @@ -257,6 +260,10 @@ out: info->ct = ct; return 0; +err4: + help = nfct_help(ct); + if (help) + module_put(help->helper->me); err3: nf_ct_tmpl_free(ct); err2: