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

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