From f05383bb3447f7fbd44c9051c4e273caeb33352f Mon Sep 17 00:00:00 2001 From: Calvin Morrison Date: Wed, 19 Aug 2026 10:41:03 -0400 Subject: fw: a dead firewall leaves the network down, and can be restarted into it Two things can happen when a firewall dies: the traffic it was filtering carries on unfiltered, or it stops. Only the second is defensible. A machine briefly off the network is a machine somebody notices and fixes; a machine briefly on the network with no rules is the thing the firewall was installed to prevent, and nobody notices it at all. fw already does the second, in all three modes, and by mechanism rather than by care. Measured rather than assumed: before fw device: /net/ether1 addr: 10.9.9.1 route: 10.9.9.254 fw running device: pkt0 addr: 10.9.9.1 route: 10.9.9.254 fw killed device: addr: route: pktmedium is unbindonclose, so the interface and the address go when fw's fds close, and the card is left bound to nothing with nothing reading it. In a namespace it is harder still: /net answers "i/o on hungup channel" and bind -a '#I' /net answers "mount/attach disallowed", because the device mask was dropped before the program started. So todo item 1 -- "a dead fw takes the network with it", open since the first commit -- was the requirement written down as a defect. It is now design.md and a FAILURE section in fw(8), and the tests assert it, which is the point: this is exactly the property a later helpful change reverses without meaning to. putback() was that change, written and never run; deleting it removed a fail-open path, not just dead code. What was actually broken is recovery, and in a way nobody had reached: a fw that dies leaves its control filesystem mounted, and a corpse of a mount fails everything asked of it -- including the access() check fw makes before touching a card, which then refuses the restart: fw: /tmp/rdbg/ctl: clone failed; not touching /net/ether1 until it exists That check exists so fw does not take a card it cannot then serve, and it was keeping fw from ever coming back. Now the dead mount is cleared first, the same way reclaim() clears the pkt interface the same dead fw left behind: both are its own wreckage. With that and -a/-g in the service file -- so a restart does not need the address it just lost -- the whole cycle works and never passes through open: crash, network down, restart, network up and filtered. Ten checks, three of which fail against the previous fw.c. 87 pass. Co-Authored-By: Claude Opus 5 --- fw/src/fw.c | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) (limited to 'fw/src/fw.c') diff --git a/fw/src/fw.c b/fw/src/fw.c index bb97960..800e004 100644 --- a/fw/src/fw.c +++ b/fw/src/fw.c @@ -1463,9 +1463,26 @@ threadmain(int argc, char **argv) * that has no card behind it and no network at all, which * is a bad way to discover a typo in -m. */ - if(access(mtpt, AEXIST) < 0) - sysfatal("%s: %r; not touching %s until it exists", - mtpt, etherdev); + if(access(mtpt, AEXIST) < 0){ + /* + * A fw that died left its control filesystem mounted + * here and what remains is a corpse: the name is + * there and every operation on it fails, including + * the check above. So the restart after a crash was + * refused by the very test meant to keep fw from + * taking a card it could not then serve. Clear it, + * the same way reclaim() clears the pkt interface the + * same dead fw left behind; both are its wreckage, + * and a firewall that cannot restart into its own + * wreckage stays down for good. + */ + unmount(nil, mtpt); + if(access(mtpt, AEXIST) < 0) + sysfatal("%s: %r; not touching %s until it exists", + mtpt, etherdev); + fprint(2, "fw: cleared %s, left mounted by an earlier fw\n", + mtpt); + } fprint(2, "fw: filtering packets on %s\n", etherdev); syslog(0, "fw", "started, filtering %s for %s", etherdev, etheraddr); -- cgit v1.2.3