Services run files that an update replaced
- Check
host.restart_needed- Severity
- medium
- Runs
- on the server, in the daily run of the collector
- Looks at
- Loaded programs and libraries marked (deleted) in /proc/<pid>/maps, with the package and the systemd unit
What the check looks at
The files that each running program has loaded, from /proc/<pid>/maps. An update writes the new version of a
library or program next to the old one and renames it over the old one. A program that had the old file loaded
keeps it, and the kernel marks the path (deleted) in its maps. The evidence names the programs that hold such
files, their systemd units and the packages the files belong to. Processes of containers are left out: a new
image and a new container replace those.
The check fails when a system service runs a replaced file of an OS package. Login sessions and user services alone, or replaced files outside OS packages (an app deploy that did not restart the app), give a warning.
Risk
The update is installed, and the package manager lists nothing to upgrade, while the service still runs the old code with the vulnerabilities that the update fixed. An OpenSSL update fixes nothing in nginx until nginx restarts. On the dashboard, the findings of the updated package stay open with the status "update installed, restart needed" until the first report after the restart, and their fix is the restart command.
How to fix it
Restart the services that the evidence names:
sudo systemctl restart nginx.service php8.2-fpm.service
systemd itself (init.scope in the evidence) loads the new files with sudo systemctl daemon-reexec. For D-Bus
(dbus.service, dbus-broker.service) and systemd-logind, reboot at a quiet time: a restart on a running
system ends the sessions that depend on them. Login sessions keep the old files until the user logs out and in
again.
Debian and Ubuntu
needrestart lists the services that run replaced files and restarts them:
sudo apt install needrestart
sudo needrestart -r l # list only
sudo needrestart -r a # restart the services it lists
Its apt hook runs it after each package upgrade. In its default mode it asks which services to restart, and
in a run without a terminal, such as unattended-upgrades, it falls back to listing them. To restart them without
asking, put the line in a .conf file of its own in /etc/needrestart/conf.d/, such as restart.conf:
$nrconf{restart} = 'a';
RHEL, Rocky Linux and AlmaLinux
sudo dnf needs-restarting # processes that use replaced files
sudo dnf needs-restarting --services # the systemd services among them
needs-restarting comes with the package dnf-plugins-core (sudo dnf install dnf-plugins-core where dnf
answers "No such command").
Alpine
Alpine does not have such a tool. Restart the OpenRC service that the evidence names:
sudo rc-service nginx restart
How to check the fix
sudo needrestart -r l or sudo dnf needs-restarting --services lists nothing, and the next report passes. To
send a report right away: sudo /usr/local/lib/vulnpocalypse/run.sh send.
When a warning is fine
For a few hours, until a planned restart of a service that does not face the internet. A login session of an administrator that ends today. A service on a public port should restart the same day.
Sources
- needrestart(1) (
-r l,-r a, the fallback to list only without a terminal) and the sample configuration ($nrconf{restart},/etc/needrestart/conf.d/*.conf) - dnf needs-restarting (
--services) - proc_pid_maps(5): the format of
/proc/<pid>/maps
Vulnpocalypse