{"id":809404,"url":"http://patchwork.ozlabs.org/api/1.2/patches/809404/?format=json","web_url":"http://patchwork.ozlabs.org/project/netfilter-devel/patch/1504477667-12130-7-git-send-email-pablo@netfilter.org/","project":{"id":26,"url":"http://patchwork.ozlabs.org/api/1.2/projects/26/?format=json","name":"Netfilter Development","link_name":"netfilter-devel","list_id":"netfilter-devel.vger.kernel.org","list_email":"netfilter-devel@vger.kernel.org","web_url":null,"scm_url":null,"webscm_url":null,"list_archive_url":"","list_archive_url_format":"","commit_url_format":""},"msgid":"<1504477667-12130-7-git-send-email-pablo@netfilter.org>","list_archive_url":null,"date":"2017-09-03T22:27:16","name":"[16/47] netfilter: nf_tables: Allow chain name of up to 255 chars","commit_ref":null,"pull_url":null,"state":"accepted","archived":false,"hash":"eec7109d30b85b73971bf3e2b59ba2291a3f5185","submitter":{"id":1315,"url":"http://patchwork.ozlabs.org/api/1.2/people/1315/?format=json","name":"Pablo Neira Ayuso","email":"pablo@netfilter.org"},"delegate":{"id":6139,"url":"http://patchwork.ozlabs.org/api/1.2/users/6139/?format=json","username":"pablo","first_name":"Pablo","last_name":"Neira","email":"pablo@netfilter.org"},"mbox":"http://patchwork.ozlabs.org/project/netfilter-devel/patch/1504477667-12130-7-git-send-email-pablo@netfilter.org/mbox/","series":[{"id":1280,"url":"http://patchwork.ozlabs.org/api/1.2/series/1280/?format=json","web_url":"http://patchwork.ozlabs.org/project/netfilter-devel/list/?series=1280","date":"2017-09-03T22:25:42","name":"[01/47] netfilter: expect: add to hash table after expect init","version":1,"mbox":"http://patchwork.ozlabs.org/series/1280/mbox/"}],"comments":"http://patchwork.ozlabs.org/api/patches/809404/comments/","check":"pending","checks":"http://patchwork.ozlabs.org/api/patches/809404/checks/","tags":{},"related":[],"headers":{"Return-Path":"<netfilter-devel-owner@vger.kernel.org>","X-Original-To":"incoming@patchwork.ozlabs.org","Delivered-To":"patchwork-incoming@bilbo.ozlabs.org","Authentication-Results":"ozlabs.org;\n\tspf=none (mailfrom) smtp.mailfrom=vger.kernel.org\n\t(client-ip=209.132.180.67; helo=vger.kernel.org;\n\tenvelope-from=netfilter-devel-owner@vger.kernel.org;\n\treceiver=<UNKNOWN>)","Received":["from vger.kernel.org (vger.kernel.org [209.132.180.67])\n\tby ozlabs.org (Postfix) with ESMTP id 3xlngw5yM2z9s8J\n\tfor <incoming@patchwork.ozlabs.org>;\n\tMon,  4 Sep 2017 08:28:44 +1000 (AEST)","(majordomo@vger.kernel.org) by vger.kernel.org via listexpand\n\tid S1753289AbdICW2k (ORCPT <rfc822;incoming@patchwork.ozlabs.org>);\n\tSun, 3 Sep 2017 18:28:40 -0400","from mail.us.es ([193.147.175.20]:51194 \"EHLO mail.us.es\"\n\trhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP\n\tid S1753261AbdICW2O (ORCPT <rfc822; netfilter-devel@vger.kernel.org>);\n\tSun, 3 Sep 2017 18:28:14 -0400","from antivirus1-rhel7.int (unknown [192.168.2.11])\n\tby mail.us.es (Postfix) with ESMTP id 6C531190F68\n\tfor <netfilter-devel@vger.kernel.org>;\n\tMon,  4 Sep 2017 00:27:47 +0200 (CEST)","from antivirus1-rhel7.int (localhost [127.0.0.1])\n\tby antivirus1-rhel7.int (Postfix) with ESMTP id 5767FB503F\n\tfor <netfilter-devel@vger.kernel.org>;\n\tMon,  4 Sep 2017 00:27:47 +0200 (CEST)","by antivirus1-rhel7.int (Postfix, from userid 99)\n\tid 56D38B5030; Mon,  4 Sep 2017 00:27:47 +0200 (CEST)","from antivirus1-rhel7.int (localhost [127.0.0.1])\n\tby antivirus1-rhel7.int (Postfix) with ESMTP id 25DA8B502A;\n\tMon,  4 Sep 2017 00:27:45 +0200 (CEST)","from 192.168.1.97 (192.168.1.97) by antivirus1-rhel7.int\n\t(F-Secure/fsigk_smtp/550/antivirus1-rhel7.int); \n\tMon, 04 Sep 2017 00:27:45 +0200 (CEST)","from salvia.here (unknown [31.4.193.113])\n\t(Authenticated sender: pneira@us.es)\n\tby entrada.int (Postfix) with ESMTPA id C8B0E4265A20;\n\tMon,  4 Sep 2017 00:27:44 +0200 (CEST)"],"X-Spam-Checker-Version":"SpamAssassin 3.4.1 (2015-04-28) on\n\tantivirus1-rhel7.int","X-Spam-Level":"","X-Spam-Status":"No, score=-108.2 required=7.5 tests=ALL_TRUSTED,BAYES_50,\n\tSMTPAUTH_US2,USER_IN_WHITELIST autolearn=disabled version=3.4.1","X-Virus-Status":"clean(F-Secure/fsigk_smtp/550/antivirus1-rhel7.int)","X-SMTPAUTHUS":"auth mail.us.es","From":"Pablo Neira Ayuso <pablo@netfilter.org>","To":"netfilter-devel@vger.kernel.org","Cc":"davem@davemloft.net, netdev@vger.kernel.org","Subject":"[PATCH 16/47] netfilter: nf_tables: Allow chain name of up to 255\n\tchars","Date":"Mon,  4 Sep 2017 00:27:16 +0200","Message-Id":"<1504477667-12130-7-git-send-email-pablo@netfilter.org>","X-Mailer":"git-send-email 2.1.4","In-Reply-To":"<1504477667-12130-1-git-send-email-pablo@netfilter.org>","References":"<1504477667-12130-1-git-send-email-pablo@netfilter.org>","X-Virus-Scanned":"ClamAV using ClamSMTP","Sender":"netfilter-devel-owner@vger.kernel.org","Precedence":"bulk","List-ID":"<netfilter-devel.vger.kernel.org>","X-Mailing-List":"netfilter-devel@vger.kernel.org"},"content":"From: Phil Sutter <phil@nwl.cc>\n\nSame conversion as for table names, use NFT_NAME_MAXLEN as upper\nboundary as well.\n\nSigned-off-by: Phil Sutter <phil@nwl.cc>\nSigned-off-by: Pablo Neira Ayuso <pablo@netfilter.org>\n---\n include/net/netfilter/nf_tables.h        |  4 ++--\n include/uapi/linux/netfilter/nf_tables.h |  2 +-\n net/netfilter/nf_tables_api.c            | 34 ++++++++++++++++++++++++--------\n net/netfilter/nf_tables_trace.c          | 27 +++++++++++++++++++++++--\n 4 files changed, 54 insertions(+), 13 deletions(-)","diff":"diff --git a/include/net/netfilter/nf_tables.h b/include/net/netfilter/nf_tables.h\nindex 05ecf78ec078..be1610162ee0 100644\n--- a/include/net/netfilter/nf_tables.h\n+++ b/include/net/netfilter/nf_tables.h\n@@ -859,7 +859,7 @@ struct nft_chain {\n \tu16\t\t\t\tlevel;\n \tu8\t\t\t\tflags:6,\n \t\t\t\t\tgenmask:2;\n-\tchar\t\t\t\tname[NFT_CHAIN_MAXNAMELEN];\n+\tchar\t\t\t\t*name;\n };\n \n enum nft_chain_type {\n@@ -1272,7 +1272,7 @@ struct nft_trans_set {\n \n struct nft_trans_chain {\n \tbool\t\t\t\tupdate;\n-\tchar\t\t\t\tname[NFT_CHAIN_MAXNAMELEN];\n+\tchar\t\t\t\t*name;\n \tstruct nft_stats __percpu\t*stats;\n \tu8\t\t\t\tpolicy;\n };\ndiff --git a/include/uapi/linux/netfilter/nf_tables.h b/include/uapi/linux/netfilter/nf_tables.h\nindex 0b94e572ef16..d9c03a8608ee 100644\n--- a/include/uapi/linux/netfilter/nf_tables.h\n+++ b/include/uapi/linux/netfilter/nf_tables.h\n@@ -3,7 +3,7 @@\n \n #define NFT_NAME_MAXLEN\t\t256\n #define NFT_TABLE_MAXNAMELEN\tNFT_NAME_MAXLEN\n-#define NFT_CHAIN_MAXNAMELEN\t32\n+#define NFT_CHAIN_MAXNAMELEN\tNFT_NAME_MAXLEN\n #define NFT_SET_MAXNAMELEN\t32\n #define NFT_OBJ_MAXNAMELEN\t32\n #define NFT_USERDATA_MAXLEN\t256\ndiff --git a/net/netfilter/nf_tables_api.c b/net/netfilter/nf_tables_api.c\nindex c2e392d5e512..747499039709 100644\n--- a/net/netfilter/nf_tables_api.c\n+++ b/net/netfilter/nf_tables_api.c\n@@ -1250,8 +1250,10 @@ static void nf_tables_chain_destroy(struct nft_chain *chain)\n \t\t\tstatic_branch_dec(&nft_counters_enabled);\n \t\tif (basechain->ops[0].dev != NULL)\n \t\t\tdev_put(basechain->ops[0].dev);\n+\t\tkfree(chain->name);\n \t\tkfree(basechain);\n \t} else {\n+\t\tkfree(chain->name);\n \t\tkfree(chain);\n \t}\n }\n@@ -1476,8 +1478,13 @@ static int nf_tables_newchain(struct net *net, struct sock *nlsk,\n \t\t\tnft_trans_chain_policy(trans) = -1;\n \n \t\tif (nla[NFTA_CHAIN_HANDLE] && name) {\n-\t\t\tnla_strlcpy(nft_trans_chain_name(trans), name,\n-\t\t\t\t    NFT_CHAIN_MAXNAMELEN);\n+\t\t\tnft_trans_chain_name(trans) =\n+\t\t\t\tnla_strdup(name, GFP_KERNEL);\n+\t\t\tif (!nft_trans_chain_name(trans)) {\n+\t\t\t\tkfree(trans);\n+\t\t\t\tfree_percpu(stats);\n+\t\t\t\treturn -ENOMEM;\n+\t\t\t}\n \t\t}\n \t\tlist_add_tail(&trans->list, &net->nft.commit_list);\n \t\treturn 0;\n@@ -1544,7 +1551,11 @@ static int nf_tables_newchain(struct net *net, struct sock *nlsk,\n \tINIT_LIST_HEAD(&chain->rules);\n \tchain->handle = nf_tables_alloc_handle(table);\n \tchain->table = table;\n-\tnla_strlcpy(chain->name, name, NFT_CHAIN_MAXNAMELEN);\n+\tchain->name = nla_strdup(name, GFP_KERNEL);\n+\tif (!chain->name) {\n+\t\terr = -ENOMEM;\n+\t\tgoto err1;\n+\t}\n \n \terr = nf_tables_register_hooks(net, table, chain, afi->nops);\n \tif (err < 0)\n@@ -1979,7 +1990,7 @@ static void nf_tables_rule_notify(const struct nft_ctx *ctx,\n \n struct nft_rule_dump_ctx {\n \tchar *table;\n-\tchar chain[NFT_CHAIN_MAXNAMELEN];\n+\tchar *chain;\n };\n \n static int nf_tables_dump_rules(struct sk_buff *skb,\n@@ -2047,6 +2058,7 @@ static int nf_tables_dump_rules_done(struct netlink_callback *cb)\n \n \tif (ctx) {\n \t\tkfree(ctx->table);\n+\t\tkfree(ctx->chain);\n \t\tkfree(ctx);\n \t}\n \treturn 0;\n@@ -2088,9 +2100,15 @@ static int nf_tables_getrule(struct net *net, struct sock *nlsk,\n \t\t\t\t\treturn -ENOMEM;\n \t\t\t\t}\n \t\t\t}\n-\t\t\tif (nla[NFTA_RULE_CHAIN])\n-\t\t\t\tnla_strlcpy(ctx->chain, nla[NFTA_RULE_CHAIN],\n-\t\t\t\t\t    sizeof(ctx->chain));\n+\t\t\tif (nla[NFTA_RULE_CHAIN]) {\n+\t\t\t\tctx->chain = nla_strdup(nla[NFTA_RULE_CHAIN],\n+\t\t\t\t\t\t\tGFP_KERNEL);\n+\t\t\t\tif (!ctx->chain) {\n+\t\t\t\t\tkfree(ctx->table);\n+\t\t\t\t\tkfree(ctx);\n+\t\t\t\t\treturn -ENOMEM;\n+\t\t\t\t}\n+\t\t\t}\n \t\t\tc.data = ctx;\n \t\t}\n \n@@ -4863,7 +4881,7 @@ static void nft_chain_commit_update(struct nft_trans *trans)\n {\n \tstruct nft_base_chain *basechain;\n \n-\tif (nft_trans_chain_name(trans)[0])\n+\tif (nft_trans_chain_name(trans))\n \t\tstrcpy(trans->ctx.chain->name, nft_trans_chain_name(trans));\n \n \tif (!nft_is_base_chain(trans->ctx.chain))\ndiff --git a/net/netfilter/nf_tables_trace.c b/net/netfilter/nf_tables_trace.c\nindex 62787d985e9d..e1dc527a493b 100644\n--- a/net/netfilter/nf_tables_trace.c\n+++ b/net/netfilter/nf_tables_trace.c\n@@ -162,6 +162,27 @@ static int nf_trace_fill_rule_info(struct sk_buff *nlskb,\n \t\t\t    NFTA_TRACE_PAD);\n }\n \n+static bool nft_trace_have_verdict_chain(struct nft_traceinfo *info)\n+{\n+\tswitch (info->type) {\n+\tcase NFT_TRACETYPE_RETURN:\n+\tcase NFT_TRACETYPE_RULE:\n+\t\tbreak;\n+\tdefault:\n+\t\treturn false;\n+\t}\n+\n+\tswitch (info->verdict->code) {\n+\tcase NFT_JUMP:\n+\tcase NFT_GOTO:\n+\t\tbreak;\n+\tdefault:\n+\t\treturn false;\n+\t}\n+\n+\treturn true;\n+}\n+\n void nft_trace_notify(struct nft_traceinfo *info)\n {\n \tconst struct nft_pktinfo *pkt = info->pkt;\n@@ -176,12 +197,11 @@ void nft_trace_notify(struct nft_traceinfo *info)\n \n \tsize = nlmsg_total_size(sizeof(struct nfgenmsg)) +\n \t\tnla_total_size(strlen(info->chain->table->name)) +\n-\t\tnla_total_size(NFT_CHAIN_MAXNAMELEN) +\n+\t\tnla_total_size(strlen(info->chain->name)) +\n \t\tnla_total_size_64bit(sizeof(__be64)) +\t/* rule handle */\n \t\tnla_total_size(sizeof(__be32)) +\t/* trace type */\n \t\tnla_total_size(0) +\t\t\t/* VERDICT, nested */\n \t\t\tnla_total_size(sizeof(u32)) +\t/* verdict code */\n-\t\t\tnla_total_size(NFT_CHAIN_MAXNAMELEN) + /* jump target */\n \t\tnla_total_size(sizeof(u32)) +\t\t/* id */\n \t\tnla_total_size(NFT_TRACETYPE_LL_HSIZE) +\n \t\tnla_total_size(NFT_TRACETYPE_NETWORK_HSIZE) +\n@@ -194,6 +214,9 @@ void nft_trace_notify(struct nft_traceinfo *info)\n \t\tnla_total_size(sizeof(u32)) +\t\t/* nfproto */\n \t\tnla_total_size(sizeof(u32));\t\t/* policy */\n \n+\tif (nft_trace_have_verdict_chain(info))\n+\t\tsize += nla_total_size(strlen(info->verdict->chain->name)); /* jump target */\n+\n \tskb = nlmsg_new(size, GFP_ATOMIC);\n \tif (!skb)\n \t\treturn;\n","prefixes":["16/47"]}