Skip to contentSkip to conversation

Set default policy of chains in filter tables to DROP/ACCEPT

PATCH In review Laszlo Attila Toth 3 participants 5 messages Jan 24, 2008

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Set default policy of chains in filter tables to DROP/ACCEPT

Set the default policy of INPUT/FORWARD/OUTPUT chains of IPv4/IPv6 filter tables to DROP or ACCEPT in kernel configuration. It can be override by a module parameter (defaultdrop for IPv4 and defaultdropv6 for IPv6).

---
 net/ipv4/netfilter/Kconfig           |   11 +++++++++++
 net/ipv4/netfilter/iptable_filter.c  |   23 ++++++++++++++++-------
 net/ipv6/netfilter/Kconfig           |   11 +++++++++++
 net/ipv6/netfilter/ip6table_filter.c |   23 ++++++++++++++++-------
 4 files changed, 54 insertions(+), 14 deletions(-)
net/ipv4/netfilter/Kconfig +11 -0
index 9a077cb..72e0de7 100644
@@ -123,6 +123,17 @@ config IP_NF_FILTER
 
 	  To compile it as a module, choose M here.  If unsure, say N.
 
+config IP_NF_FILTER_DEFAULT_DROP
+	bool "Default policy is drop"
+	depends on IP_NF_FILTER
+	default n
+	help
+	  In server environment the recommended default policy of the chains
+	  of filter table is DROP before any network interface is up. If this
+	  option is set, the policy will be  DROP, otherwise ACCEPT.
+
+	  If unsure, say N.
+
 config IP_NF_TARGET_REJECT
 	tristate "REJECT target support"
 	depends on IP_NF_FILTER
net/ipv4/netfilter/iptable_filter.c +16 -7
index 29bb4f9..01c84f1 100644
@@ -115,21 +115,30 @@ static struct nf_hook_ops ipt_ops[] __read_mostly = {
 	},
 };
 
-/* Default to forward because I got too much mail already. */
-static int forward = NF_ACCEPT;
-module_param(forward, bool, 0000);
+static int defaultdrop
+#ifdef CONFIG_IP_NF_FILTER_DEFAULT_DROP
+			= 1;
+#else
+			= 0;
+#endif
+module_param(defaultdrop, int, 0400);
 
 static int __init iptable_filter_init(void)
 {
 	int ret;
+	int verdict;
 
-	if (forward < 0 || forward > NF_MAX_VERDICT) {
-		printk("iptables forward must be 0 or 1\n");
+	if (defaultdrop < 0 || defaultdrop > 1) {
+		printk("iptables defaultdrop must be 0 or 1\n");
 		return -EINVAL;
 	}
 
-	/* Entry 1 is the FORWARD hook */
-	initial_table.entries[1].target.verdict = -forward - 1;
+	/* Change default rule to ACCEPT if defaultdrop = 0 was given. */
+	verdict = - (defaultdrop ? NF_DROP : NF_ACCEPT) - 1;
+	
+	initial_table.entries[0].target.verdict = verdict;
+	initial_table.entries[1].target.verdict = verdict;
+	initial_table.entries[2].target.verdict = verdict;
 
 	/* Register table */
 	ret = ipt_register_table(&packet_filter, &initial_table.repl);
net/ipv6/netfilter/Kconfig +11 -0
index 4fc0b02..1b3c560 100644
@@ -147,6 +147,17 @@ config IP6_NF_FILTER
 
 	  To compile it as a module, choose M here.  If unsure, say N.
 
+config IP6_NF_FILTER_DEFAULT_DROP
+	bool "Default policy is drop"
+	depends on IP6_NF_FILTER
+	default n
+	help
+	  In server environment the recommended default policy of the chains
+	  of filter table is DROP before any network interface is up. If this
+	  option is set, the policy will be  DROP, otherwise ACCEPT.
+
+	  If unsure, say N.
+
 config IP6_NF_TARGET_LOG
 	tristate "LOG target support"
 	depends on IP6_NF_FILTER
net/ipv6/netfilter/ip6table_filter.c +16 -7
index 87d38d0..9e37920 100644
@@ -114,21 +114,30 @@ static struct nf_hook_ops ip6t_ops[] __read_mostly = {
 	},
 };
 
-/* Default to forward because I got too much mail already. */
-static int forward = NF_ACCEPT;
-module_param(forward, bool, 0000);
+static int defaultdropv6
+#ifdef CONFIG_IP6_NF_FILTER_DEFAULT_DROP
+			= 1;
+#else
+			= 0;
+#endif
+module_param(defaultdropv6, int, 0400);
 
 static int __init ip6table_filter_init(void)
 {
 	int ret;
+	int verdict;
 
-	if (forward < 0 || forward > NF_MAX_VERDICT) {
-		printk("iptables forward must be 0 or 1\n");
+	if (defaultdropv6 < 0 || defaultdropv6 > 1) {
+		printk("iptables defaultdropv6 must be 0 or 1\n");
 		return -EINVAL;
 	}
 
-	/* Entry 1 is the FORWARD hook */
-	initial_table.entries[1].target.verdict = -forward - 1;
+	/* Change default rule to ACCEPT if defaultdrop = 0 was given. */
+	verdict = - (defaultdropv6 ? NF_DROP : NF_ACCEPT) - 1;
+	
+	initial_table.entries[0].target.verdict = verdict;
+	initial_table.entries[1].target.verdict = verdict;
+	initial_table.entries[2].target.verdict = verdict;
 
 	/* Register table */
 	ret = ip6t_register_table(&packet_filter, &initial_table.repl);
Signature · 1 line
1.5.2.5
#1 lore raw
Quoted 3 lines · Laszlo Attila Toth

Set the default policy of INPUT/FORWARD/OUTPUT chains of IPv4/IPv6 filter tables to DROP or ACCEPT in kernel configuration. It can be override by a module parameter (defaultdrop for IPv4 and defaultdropv6 for IPv6).

Whats the point of this? You can simply execute the corresponding iptables commands early during boot ...

#2 lore raw

Patrick McHardy írta:

Quoted 8 lines
Quoted 3 lines · Laszlo Attila Toth

Set the default policy of INPUT/FORWARD/OUTPUT chains of IPv4/IPv6 filter tables to DROP or ACCEPT in kernel configuration. It can be override by a module parameter (defaultdrop for IPv4 and defaultdropv6 for IPv6).

Whats the point of this? You can simply execute the corresponding iptables commands early during boot ...

Yes, that's right. But in case of a security audit unfortunatelly it is not enough, the only acceptable way is to set the policy to DROP. In our kernel the default policy is DROP because of it.

Signature · 5 lines
Attila
-
To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#3 lore raw
Quoted 11 lines · Laszlo Attila Toth

Patrick McHardy írta:

Quoted 8 lines
Quoted 3 lines · Laszlo Attila Toth

Set the default policy of INPUT/FORWARD/OUTPUT chains of IPv4/IPv6 filter tables to DROP or ACCEPT in kernel configuration. It can be override by a module parameter (defaultdrop for IPv4 and defaultdropv6 for IPv6).

Whats the point of this? You can simply execute the corresponding iptables commands early during boot ...

Yes, that's right. But in case of a security audit unfortunatelly it is not enough, the only acceptable way is to set the policy to DROP. In our kernel the default policy is DROP because of it.

Frankly, any "audit" that insists on this while ignoring that the policy can be set before any network interface is up or even drivers loaded deserves to go to the trash. Thats just as stupid as "icmp is bad" dogma and similar crap.

So I'm not going to apply this, sorry.

-
To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#4 lore raw
In reply to Laszlo Attila Toth

Hi,

Quoted 3 lines · Laszlo Attila Toth

Set the default policy of INPUT/FORWARD/OUTPUT chains of IPv4/IPv6 filter tables to DROP or ACCEPT in kernel configuration. It can be override by a module parameter (defaultdrop for IPv4 and defaultdropv6 for IPv6).

The best practice is to load in the rules before bringing up the interfaces. So what would be the real benefit from the patch?

Best regards,
Jozsef
-
E-mail : [email protected], [email protected] PGP key : http://www.kfki.hu/~kadlec/pgp_public_key.txt
Address : KFKI Research Institute for Particle and Nuclear Physics

          H-1525 Budapest 114, POB. 49, Hungary