Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp1821345imm; Mon, 3 Sep 2018 10:17:52 -0700 (PDT) X-Google-Smtp-Source: ANB0VdZYnWJN1vDTrSY05EQjNmvurt/rWEAGgIvLI43ifS0R6lY1Qr8SRkUw9dMxwBa3nug+r65/ X-Received: by 2002:a62:b40c:: with SMTP id h12-v6mr30464906pfn.18.1535995072090; Mon, 03 Sep 2018 10:17:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1535995072; cv=none; d=google.com; s=arc-20160816; b=shhgZoc1ED6jn7OAS3wtSl7pN2XyfyiQY4Y6vo+2WOUB0u2T4nKMQ7V/ktnJcucb6T VIb6EzgkQygB3oIP+P2qBWqZKGoDPrWAQyysRKFlQblrTh/PBaVbKpbD6BlzNjC7udlZ Ih3s3f6d0qE6lGFPwhcNgosdvhTvaA/54GtyQpaaBEuO95+rIY2uBKg1+EP63rOBE4rT DXHVOZKBHS0KEOrjioBs5H6Fy5+g9enB2xGd6I2WaLoGAOlorm2bfH/W/BNKSOuOtpBY +6cqmup7MOSzSEnrCzcnT5TOdjMSi1JII9HSQ/MZOZf2RnxctrvBbOrCfkSiYxL/ndMk VYag== 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=j9SnZsvw70+EywLxoJMhKKcKVNZfnME6ZlBVFDbs3EY=; b=gNKTAKSenVJzABtAkmRnOHc/iDpidhesuEDdX97CSDS1X+0LXf+61hLvz9G+UOKBpv 8j69LlroTOVWTIZydQPfLkRqV6re2+MwrwcGwiGZcuIin7uUB/2P5QtckVZSbdkj3omW 91gZU42DgLt4I84ateYWP3VQYT4Hq4FnD+/dJp6XJZZPPfHVjZDRZyCIx6ZOT9sAEzk/ 4WBrp2NMT/uWOGso+stQXQY2pl8e9TdL5LwvUcVML5RSSyC3umKtQ8cGrW4W+MHqYi5I QPTxCUsfjXVzzFdCeHvoIk5TU8erkthbbxUCyS3ntHDppQym4z7cIC4rB6T8b/EB1Ykn TJbQ== 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 v4-v6si18903010plb.400.2018.09.03.10.17.37; Mon, 03 Sep 2018 10:17:52 -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 S1729942AbeICVhh (ORCPT + 99 others); Mon, 3 Sep 2018 17:37:37 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:42590 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728947AbeICVhg (ORCPT ); Mon, 3 Sep 2018 17:37:36 -0400 Received: from localhost (ip-213-127-74-90.ip.prioritytelecom.net [213.127.74.90]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 8F749D06; Mon, 3 Sep 2018 17:16:31 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Florian Westphal , Pablo Neira Ayuso , Sasha Levin Subject: [PATCH 4.14 029/165] netfilter: nf_tables: fix memory leaks on chain rename Date: Mon, 3 Sep 2018 18:55:15 +0200 Message-Id: <20180903165656.542127492@linuxfoundation.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180903165655.003605184@linuxfoundation.org> References: <20180903165655.003605184@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.14-stable review patch. If anyone has any objections, please let me know. ------------------ From: Florian Westphal [ Upstream commit 9f8aac0be21ed5f99bd5ba0ff315d710737d1794 ] The new name is stored in the transaction metadata, on commit, the pointers to the old and new names are swapped. Therefore in abort and commit case we have to free the pointer in the chain_trans container. In commit case, the pointer can be used by another cpu that is currently dumping the renamed chain, thus kfree needs to happen after waiting for rcu readers to complete. Fixes: b7263e071a ("netfilter: nf_tables: Allow chain name of up to 255 chars") Signed-off-by: Florian Westphal Signed-off-by: Pablo Neira Ayuso Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- net/netfilter/nf_tables_api.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) --- a/net/netfilter/nf_tables_api.c +++ b/net/netfilter/nf_tables_api.c @@ -5043,6 +5043,9 @@ static void nf_tables_commit_release(str case NFT_MSG_DELTABLE: nf_tables_table_destroy(&trans->ctx); break; + case NFT_MSG_NEWCHAIN: + kfree(nft_trans_chain_name(trans)); + break; case NFT_MSG_DELCHAIN: nf_tables_chain_destroy(trans->ctx.chain); break; @@ -5100,13 +5103,15 @@ static int nf_tables_commit(struct net * nf_tables_table_notify(&trans->ctx, NFT_MSG_DELTABLE); break; case NFT_MSG_NEWCHAIN: - if (nft_trans_chain_update(trans)) + if (nft_trans_chain_update(trans)) { nft_chain_commit_update(trans); - else + nf_tables_chain_notify(&trans->ctx, NFT_MSG_NEWCHAIN); + /* trans destroyed after rcu grace period */ + } else { nft_clear(net, trans->ctx.chain); - - nf_tables_chain_notify(&trans->ctx, NFT_MSG_NEWCHAIN); - nft_trans_destroy(trans); + nf_tables_chain_notify(&trans->ctx, NFT_MSG_NEWCHAIN); + nft_trans_destroy(trans); + } break; case NFT_MSG_DELCHAIN: list_del_rcu(&trans->ctx.chain->list); @@ -5246,7 +5251,7 @@ static int nf_tables_abort(struct net *n case NFT_MSG_NEWCHAIN: if (nft_trans_chain_update(trans)) { free_percpu(nft_trans_chain_stats(trans)); - + kfree(nft_trans_chain_name(trans)); nft_trans_destroy(trans); } else { trans->ctx.table->use--;