Blame SOURCES/0067-nft-Reject-standard-targets-as-chain-names-when-rest.patch

df4535
From 257c18bf4fbcc7e5f4fb3c9cadab699986a9bd41 Mon Sep 17 00:00:00 2001
df4535
From: Phil Sutter <phil@nwl.cc>
df4535
Date: Wed, 16 Mar 2022 17:14:07 +0100
df4535
Subject: [PATCH] nft: Reject standard targets as chain names when restoring
df4535
df4535
Reuse parse_chain() called from do_parse() for '-N' and rename it for a
df4535
better description of what it does.
df4535
df4535
Note that by itself, this patch will likely kill iptables-restore
df4535
performance for big rulesets due to the extra extension lookup for chain
df4535
lines. A following patch announcing those chains to libxtables will
df4535
alleviate that.
df4535
df4535
Signed-off-by: Phil Sutter <phil@nwl.cc>
df4535
Reviewed-by: Florian Westphal <fw@strlen.de>
df4535
(cherry picked from commit b1aee6b2238794446feba41778f88703784560f7)
df4535
df4535
Conflicts:
df4535
	iptables/xshared.c
df4535
-> Parts manually applied due to unmerged do_parse() function.
df4535
---
df4535
 iptables/ip6tables.c       | 2 +-
df4535
 iptables/iptables.c        | 2 +-
df4535
 iptables/xshared.c         | 2 +-
df4535
 iptables/xshared.h         | 2 +-
df4535
 iptables/xtables-restore.c | 5 +----
df4535
 iptables/xtables.c         | 2 +-
df4535
 6 files changed, 6 insertions(+), 9 deletions(-)
df4535
df4535
diff --git a/iptables/ip6tables.c b/iptables/ip6tables.c
df4535
index 614d1e249c06d..b96dc033e7ebb 100644
df4535
--- a/iptables/ip6tables.c
df4535
+++ b/iptables/ip6tables.c
df4535
@@ -1247,7 +1247,7 @@ int do_command6(int argc, char *argv[], char **table,
df4535
 			break;
df4535
 
df4535
 		case 'N':
df4535
-			parse_chain(optarg);
df4535
+			assert_valid_chain_name(optarg);
df4535
 			add_command(&command, CMD_NEW_CHAIN, CMD_NONE,
df4535
 				    cs.invert);
df4535
 			chain = optarg;
df4535
diff --git a/iptables/iptables.c b/iptables/iptables.c
df4535
index 3b395981cc8ea..6e2946f5660de 100644
df4535
--- a/iptables/iptables.c
df4535
+++ b/iptables/iptables.c
df4535
@@ -1243,7 +1243,7 @@ int do_command4(int argc, char *argv[], char **table,
df4535
 			break;
df4535
 
df4535
 		case 'N':
df4535
-			parse_chain(optarg);
df4535
+			assert_valid_chain_name(optarg);
df4535
 			add_command(&command, CMD_NEW_CHAIN, CMD_NONE,
df4535
 				    cs.invert);
df4535
 			chain = optarg;
df4535
diff --git a/iptables/xshared.c b/iptables/xshared.c
df4535
index de8326b6c7b05..0c232ca2ae8d5 100644
df4535
--- a/iptables/xshared.c
df4535
+++ b/iptables/xshared.c
df4535
@@ -776,7 +776,7 @@ int parse_rulenumber(const char *rule)
df4535
 	return rulenum;
df4535
 }
df4535
 
df4535
-void parse_chain(const char *chainname)
df4535
+void assert_valid_chain_name(const char *chainname)
df4535
 {
df4535
 	const char *ptr;
df4535
 
df4535
diff --git a/iptables/xshared.h b/iptables/xshared.h
df4535
index f5d2f8d0a2bc5..095a574d85879 100644
df4535
--- a/iptables/xshared.h
df4535
+++ b/iptables/xshared.h
df4535
@@ -217,6 +217,6 @@ char cmd2char(int option);
df4535
 void add_command(unsigned int *cmd, const int newcmd,
df4535
 		 const int othercmds, int invert);
df4535
 int parse_rulenumber(const char *rule);
df4535
-void parse_chain(const char *chainname);
df4535
+void assert_valid_chain_name(const char *chainname);
df4535
 
df4535
 #endif /* IPTABLES_XSHARED_H */
df4535
diff --git a/iptables/xtables-restore.c b/iptables/xtables-restore.c
df4535
index c472ac9bf651b..a078da32045dc 100644
df4535
--- a/iptables/xtables-restore.c
df4535
+++ b/iptables/xtables-restore.c
df4535
@@ -150,10 +150,7 @@ static void xtables_restore_parse_line(struct nft_handle *h,
df4535
 				   "%s: line %u chain name invalid\n",
df4535
 				   xt_params->program_name, line);
df4535
 
df4535
-		if (strlen(chain) >= XT_EXTENSION_MAXNAMELEN)
df4535
-			xtables_error(PARAMETER_PROBLEM,
df4535
-				   "Invalid chain name `%s' (%u chars max)",
df4535
-				   chain, XT_EXTENSION_MAXNAMELEN - 1);
df4535
+		assert_valid_chain_name(chain);
df4535
 
df4535
 		policy = strtok(NULL, " \t\n");
df4535
 		DEBUGP("line %u, policy '%s'\n", line, policy);
df4535
diff --git a/iptables/xtables.c b/iptables/xtables.c
df4535
index 3ea293ee7c411..9006962472c58 100644
df4535
--- a/iptables/xtables.c
df4535
+++ b/iptables/xtables.c
df4535
@@ -668,7 +668,7 @@ void do_parse(struct nft_handle *h, int argc, char *argv[],
df4535
 			break;
df4535
 
df4535
 		case 'N':
df4535
-			parse_chain(optarg);
df4535
+			assert_valid_chain_name(optarg);
df4535
 			add_command(&p->command, CMD_NEW_CHAIN, CMD_NONE,
df4535
 				    cs->invert);
df4535
 			p->chain = optarg;
df4535
-- 
df4535
2.34.1
df4535