When a policy install runs small firewalls out of memory
A routine policy install on a fleet of small Check Point Quantum Spark gateways. The install reported success. Traffic kept flowing. And yet, on dozens of gateways, something was clearly wrong.
What happened
These are small appliances with about 2 GB of memory. The policy had grown over time, and this install pushed it over the edge: while the gateway loaded the new policy, the kernel ran out of memory. The OOM killer picked a victim, and it picked sfwd, the process that does much of the work on a Spark.
The watchdog (cpwd) normally restarts a dead process. Not this time: it marked sfwd as terminated and left it there.
text[Expert@gw:0]# cpwd_admin list
APP PID STAT #START START_TIME
SFWD 0 T 1 [12:34:56] <- T = terminated (simplified output)
And in the kernel log, the cause:
text[Expert@gw:0]# dmesg | grep -i -E "out of memory|oom"
Out of memory: Killed process ... (sfwd)
Three cpinfo files later, the pattern was the same on every gateway: an OOM during the policy load, sfwd killed, cpwd giving up.
Why rebooting is not the fix
The obvious move is to reboot them all. That's also the trap. After a reboot the gateway loads the same policy again, runs out of memory again, and sfwd dies again, about six minutes after the boot. Long enough to look fixed when you check right after the reboot.
So the order matters:
- Make the policy fit first. Together with Check Point TAC the policy was made smaller (in this case by turning a blade off) and installed again.
- Test on one gateway, and watch it for at least ten minutes, not one.
- Only then reboot the rest, in batches.
Script 1: check, don't guess
The first script logs in to every gateway over SSH, reads cpwd_admin list and dmesg, and writes a report: which gateways are fine, which have sfwd terminated, which were offline. Its second output is a CSV with only the failed gateways, which is exactly the input for the next step.
bashpython3 sfwd_check.py gateways.csv --check-only
That turns "I think about fifty" into a list with names.
Script 2: reboot in batches, and verify
The second script does the reboots, and it's careful on purpose:
- Dry run first. Log in, show uptime,
sfwdstate and OOM kills, reboot nothing. - A test batch of one. After it, the script always stops and asks before going on.
- Skip what you can't reach. A gateway without ping or SSH is skipped, never rebooted blind.
- Prove it really rebooted. It has to go down, come back on ping and SSH, and report an uptime shorter than the time since the reboot command.
- Wait for the six minutes. Only after eight minutes of uptime does it check
sfwdand look for new OOM kills. A gateway that looks fine at minute two isn't counted as fine. - Stop on problems. After every batch with a failure it asks before the next one. Pressing Enter means stop, not continue.
bashpython3 batch_reboot.py gateways.csv --dry-run
python3 batch_reboot.py gateways.csv --batch-size 5
python3 batch_reboot.py failed-reboot-<time>.csv # retry only the ones that didn't end OK
Each gateway in a batch gets its own line on screen, updated in place: checking, rebooting, going down, waiting for ping, waiting for SSH, checking sfwd at 8:00, OK. At the end there's a report and a CSV of whatever still needs attention.
Script 3: what is the state now?
A third, read-only script runs a status round over the fleet: is the blade really off, is sfwd running and since when, how many times has it started, which policy is installed and when. It quickly showed the gateways that needed a human: a few offline, one where the policy fetch failed (don't reboot that one without a way back), one where the blade was still on.
Lessons
- "Install succeeded" is not "the gateway is healthy". Check the processes after a policy install, not just the install result. Especially on small appliances.
- Watch memory before it bites. A policy that grows a bit every month will one day not fit. On small boxes, keep an eye on the size of what you push.
- A reboot that hides the problem for six minutes is worse than no reboot. Build the waiting into the tool, so nobody has to remember it at 23:00.
- Install in batches. If the first gateway falls over, you want to find out on one gateway, not on all of them at once.