Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 76624 - net-firewall/shorewall starts after network and other servers
Summary: net-firewall/shorewall starts after network and other servers
Status: RESOLVED FIXED
Alias: None
Product: Gentoo Security
Classification: Unclassified
Component: Default Configs (show other bugs)
Hardware: All All
: High major (vote)
Assignee: Gentoo Security
URL:
Whiteboard: [?]
Keywords:
Depends on:
Blocks:
 
Reported: 2005-01-04 04:58 UTC by Thierry Carrez (RETIRED)
Modified: 2006-11-27 16:47 UTC (History)
6 users (show)

See Also:
Package list:
Runtime testing required: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Thierry Carrez (RETIRED) gentoo-dev 2005-01-04 04:58:44 UTC
/etc/init.d/shorewall has the following depend clause :

depend() {
        need net
        provide firewall
}

so it is started after the network, at the same time as all other network servers depending that have "need net".

This creates an attack window where servers are running and the firewall is not protecting them. On the small-end system I'm building, dropbear, boa and openntpd are all running unprotected for a window that can last 50 seconds (time for the shorewall start script to execute).

The depend clause should have "before net", like recent versions of /etc/init.d/iptables.

Note that you should avoid using "detect" in /etc/shorewall/interfaces since it only works if the network interfaces are already up.
Comment 1 Thierry Carrez (RETIRED) gentoo-dev 2005-01-04 08:14:49 UTC
Hmm looks like it needs a "before net.eth0" to work. Maybe bug 70226 is related.
Comment 2 Thierry Carrez (RETIRED) gentoo-dev 2005-01-12 08:50:31 UTC
Anyone in netmon available for comment ?
Comment 3 Thierry Carrez (RETIRED) gentoo-dev 2005-01-27 07:04:36 UTC
Ramereth/netmon: please comment
Comment 4 John Sivak 2005-01-27 08:21:27 UTC
NOTE: There are some "issues" when starting Shorewall before all interfaces are "up". Notably when using interface names in the /etc/shorewall/masq file.

So you have a mini-dilemma: Start shorewall before net and remove any references in your shorewall config to interfaces that aren't up yet, or start shorewall after all the interfaces are up and have more flexiblity in some of the shorewall configurations.
Comment 5 John Sivak 2005-01-27 08:23:45 UTC
"Note that you should avoid using "detect" in /etc/shorewall/interfaces since it only works if the network interfaces are already up."

.. and I should more carefully read the previous comments.. sorry.
Comment 6 Magnus Kessler 2005-01-30 00:48:53 UTC
What about the following scheme, combining the best of both worlds:

Use a very simple, restrictive initial firewall with iptables. This firewall should only let those packets through that are needed to get dynamically configured interfaces up (such as dhcp packets). The /etc/init.d/iptables script starts before any other network related scripts.

Once the network is up shorewall takes over and (re)defines all firewall rules as desired.
Comment 7 Thierry Carrez (RETIRED) gentoo-dev 2005-01-31 05:13:09 UTC
Magnus: I like it... Want to try to write such a startup script ?
netmon: It could be put as a shorewall DEPEND (triggered by a local use flag if needed)
Comment 8 Magnus Kessler 2005-02-09 01:37:39 UTC
Some more details on how to make a combination of /etc/init.d/iptables
and /etc/init.d/shorewall work with the current scripts. The aim is to get an
initial firewall started before the network is up and to use shorewall with
network interface detection later.

The initial firewall corresponds to the "stop" state of shorewall:

Chain INPUT (policy DROP)
target     prot opt source               destination
ACCEPT     all  --  anywhere             anywhere            state RELATED,ESTABLISHED
ACCEPT     all  --  anywhere             anywhere

Chain FORWARD (policy DROP)
target     prot opt source               destination
ACCEPT     all  --  anywhere             anywhere            state RELATED,ESTABLISHED

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination

This ruleset allows the local machine to establish all connections it needs
to dynamically configure the network interfaces while blocking all
connections initiated from the outside. It is later replaced when shorewall
starts up.

Installation howto:

1. Save the following into /var/lib/iptables/rules-save

################### initial firewall start ###########################
*filter
:INPUT DROP [0:0]
:FORWARD DROP [0:0]
:OUTPUT ACCEPT [308:28160]
[308:28160] -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
[0:0] -A INPUT -i lo -j ACCEPT
[0:0] -A FORWARD -m state --state RELATED,ESTABLISHED -j ACCEPT
COMMIT
#################### initial firewall end ############################

Note: you can also run "shorewall stop" and then save the output of
iptables-save into the file. The above is a slightly cleaned up
version of this procedure.

2. activate iptables startup script: 

    rc-update add iptables boot

3. add shorewall to the default run level

    rc-update add shorewall default
Comment 9 Daniel Black (RETIRED) gentoo-dev 2005-02-09 01:49:18 UTC
my though was for the initscript to look for "detect" in the shorewall files and start before or after depending on that.

pros: simple for the user to use shorewall how they want.
will optimise for the best security if no detect is used
will always work
can warn user if it is started after

cons:
needs the dependancy cache to be updated if the config changes state (from "detect" to interface. - depscan.sh (add note to config file)
parsing config files a bit difficult. (just do it)
Comment 10 Magnus Kessler 2005-02-09 01:57:47 UTC
Daniel:

If the shorewall script contains "detect" and is then only started after the
network is up it still leaves Koon's problem. A number of services are
potentially unprotected if they are run before shorewall is up. Better to
start an initial firewall unconditionally and let shorewall take over from
there.
Comment 11 Thierry Carrez (RETIRED) gentoo-dev 2005-02-09 05:01:22 UTC
Magnus: I like your solution. I'll test it right now... Maybe the default iptables configuration should include your rules-save and SAVE_ON_STOP="no" (otherwise the default script would get overwritten when iptables is stopped).
Comment 12 Magnus Kessler 2005-02-09 13:45:17 UTC
SAVE_ON_STOP="no" would be an option, but if shorewall goes down before
iptables, it sets itself into the stop state anyway and that state is then
saved by iptables-save.

It might be safer, though, to use SAVE_ON_STOP="no" to have a guaranteed
state from which it is always started. 
Comment 13 Thierry Carrez (RETIRED) gentoo-dev 2005-03-08 07:59:39 UTC
Pulling aliz and base-system as net-firewall/iptables is noherd.

We are trying to solve the vulnerability window between network start and firewall start, which can be observed at least with shorewall, and probably with other firewall scripts.

There are solutions to manually solve this, but it would be a good idea to find a way of doing this by default (i.e. emerge shorewall should not fetch a vulnerable by default configuration). Hence the security bug.

Magnus Kessler has a good manual solution (comment #6 and comment #8) but I can't see how this can be automated to be a default config.

aliz/base/netmon: Your opinion on this ?
Comment 14 Thierry Carrez (RETIRED) gentoo-dev 2005-04-10 10:04:00 UTC
netmon/base: *bump*
Comment 15 Marcelo Goes (RETIRED) gentoo-dev 2005-04-10 10:14:45 UTC
I personally like the solution from comment #6.

Maybe an independent script can be added to protect the system during boot-up using iptables, whose rules shorewall flushes before putting its own.
Comment 16 SpanKY gentoo-dev 2005-04-21 08:29:15 UTC
not a base system issue
Comment 17 Ralf Glauberman 2005-12-02 09:28:12 UTC
Perhaps there would be an other way of fixing this. Why not start shorewall
directly after all interfaces are up but before any network service is started
by considdering the metaservice net only running if not only all the interfaces
are up but also shorewall is started. While this would not stop incomming
traffic it could do no harm as nothing is listening to it. 
Comment 18 Markus Ullmann (RETIRED) gentoo-dev 2006-10-08 06:46:11 UTC
(In reply to comment #15)
> I personally like the solution from comment #6.
> 
> Maybe an independent script can be added to protect the system during boot-up using iptables, whose rules shorewall flushes before putting its own.

I agree with this one and as iptables comes up properly now with baselayout 1.12.x, I think this issue is resolved...
Comment 19 Markus Ullmann (RETIRED) gentoo-dev 2006-11-27 16:47:15 UTC
As we saw no objections and after a short talk to security -> marking as FIXED