Contents
needrestart is the tool that asks “restart these services?” at the end of apt upgrade on Ubuntu and Debian. Canonical says it is installed by default on Ubuntu Server images since 21.04. It runs as root, and apt invokes it after every dpkg transaction that unpacks a package. CVE-2026-124757, disclosed on November 17 by Armaan Sandhu, let any local user turn that run into a root shell command. The trigger is the administrator’s next routine upgrade.
Fixed packages now exist for every supported Debian and Ubuntu release. The part worth keeping after you patch is the mechanism: needrestart decided who owned a process by reading its cgroup path, and systemd gives every logged-in user write access to part of that path.
How needrestart sorts processes
After an upgrade, needrestart finds processes still mapping replaced binaries or libraries and groups them. System services are offered for restart. Processes in user login sessions are reported, and needrestart runs the scripts in /etc/needrestart/notify.d/ to tell those users to log in again.
To tell a user process from a service, it reads the unified-hierarchy line of /proc/PID/cgroup and matches it against systemd’s naming layout. This is the session match from upstream 3.6, the version in Debian 12 and Ubuntu 24.04:
if($value =~ m@/user-(\d+)\.slice/session-(\d+)\.scope@) {
There is no ^. The uid and session number come from wherever that text appears in the path.
The part of the path the user owns
A normal login session lives at /user.slice/user-1000.slice/session-3.scope. The same user’s systemd user manager lives under /user.slice/user-1000.slice/user@1000.service/. That unit is the problem. systemd’s stock user@.service declares:
User=%i
Delegate=pids memory cpu
systemd’s delegation documentation spells out what that means: when a delegated unit uses User=, the subtree “will be chown()ed to the indicated user so that it can correctly create cgroups below it.” That is intentional. It is how rootless containers and per-app scopes work.
So user 1000 can create this directory and move one of their own processes into it:
/user.slice/user-1000.slice/user@1000.service/app.slice/x/user-0.slice/session-1.scope
The unanchored regex finds /user-0.slice/session-1.scope at the end and files the process under uid 0, session 1. The checks for user@UID.service, which would have attributed it correctly, come after the session match and never run.
From misclassification to root
Misfiling a process is harmless on its own. The damage comes from the notify hook. For a forged root session, needrestart runs 400-notify-send with NR_USERNAME=root, and in 3.6 that hook ends with:
su -p -s /bin/sh -c "$NSEND -a needrestart -u critical -i dialog-warning \"$MSGTITLE\" \"$MSGBODY\"" "$NR_USERNAME"
$MSGBODY contains the list of affected process names, interpolated into a string that a shell then parses. A process sets its own name with prctl(PR_SET_NAME). Fifteen bytes is enough to close the double quote and add a command. The hook does check for DISPLAY first, but it reads DISPLAY from the environment of the attacker’s own process, so that check passes too.
The attacker needs a login (so that user@UID.service exists), a process that needrestart will list, and patience. Any long-running process qualifies once a library it maps gets upgraded. The command then runs as root during the next apt or dpkg transaction.
Who was actually exposed
The reporter confirmed root on Debian 12 (3.6-4+deb12u3) and Ubuntu 24.04 (3.6-7ubuntu4.5). On Debian 13 (3.11-1) the session forgery worked but command execution was not reproduced. Upstream’s 3.11 hook builds the same su -c string, so don’t read that result as safe.
The root-shell path also requires /usr/bin/notify-send. The hook exits immediately without it, so a minimal server that doesn’t have libnotify-bin installed gets the misclassification but not the command. Check with dpkg -s libnotify-bin. The hosts that matter most are the ones with several human accounts and a root who runs apt: shared build boxes, bastions, lab machines, developer workstations used by more than one person, and self-hosted CI runners where jobs get a real login.
Configuration management doesn’t avoid the problem by skipping interactive apt. The upstream maintainer notes that the hook runs whenever needrestart runs, including from monitoring or automation.
What to install
| Release | Fixed version | Advisory |
|---|---|---|
| Debian 12 bookworm | 3.6-4+deb12u4 | DLA-4921-1, Nov 20 |
| Debian 13 trixie | 3.11-1.1~deb13u1 | DSA-6637-1 |
| Ubuntu 22.04 | 3.5-5ubuntu2.6 | USN-9151-1, Nov 18 |
| Ubuntu 24.04 | 3.6-7ubuntu4.6 | USN-9151-1 |
| Ubuntu 26.04 / 26.10 | 3.11-1ubuntu2.26.04.1 / 3.11-1ubuntu2.26.10.1 | USN-9151-1 |
| Upstream | 3.11.1 | tagged Nov 17 |
Debian 12 is in LTS now, so its fix is a DLA rather than a DSA. It ships from the same security.debian.org suite, but it came three days after Ubuntu’s. Some write-ups from November 19 still say bookworm is unfixed. That stopped being true on November 20.
Installing the fix is safe. apt’s DPkg::Post-Invoke hook calls needrestart after dpkg has finished, so the run triggered by the upgrade uses the new code.
If you can’t upgrade a host yet but need to run apt on it, upstream’s own notify.conf has the switch. Add this to /etc/needrestart/notify.conf:
NR_NOTIFYD_DISABLE_NOTIFY_SEND='1'
Or turn off user notifications entirely with $nrconf{sendnotify} = 0; in a file under /etc/needrestart/conf.d/. For a single transaction, NEEDRESTART_SUSPEND=1 in apt’s environment makes the apt hook skip needrestart. That variable is already in the apt hook in upstream 3.4, so it is available on every release in the table.
One packaging detail: the hook lives in /etc, so dpkg treats it as a conffile. If someone edited 400-notify-send locally and your automation upgrades with --force-confold, the old hook stays in place. The anchored regex in /usr/sbin/needrestart still blocks the forged root session, but run dpkg --verify needrestart to see which of its files differ from the package.
What the fix does, and what it doesn’t
The three upstream commits do three separate things. One passes the notification text to su through exported environment variables, so the inner shell expands it as data. One anchors the cgroup matches:
m@^(?:/[^/]+\.slice)*/user-(\d+)\.slice/session-(\d+)\.scope@
The prefix now accepts only .slice components before the user slice. A path under user@1000.service can’t match, because that component isn’t a slice. The third replaces every byte outside printable ASCII in process names with ?, which also closes terminal-escape injection into the admin’s own terminal.
The commit message for the anchoring change is candid about its boundary: it was “tested against systemd layouts only,” and hosts with a different cgroup prefix, “such as some container setups, may classify those processes differently.” The regex is now correct for systemd’s layout. It is still pattern matching on a string that is partly user-controlled.
The lesson for code you own
This is needrestart’s second local root in two years from the same kind of trust. CVE-2024-48990 came from reading PYTHONPATH out of an unprivileged process’s environment and then running a Python interpreter as root with it. This time it was the cgroup path, plus DISPLAY from that same environment file. In both cases a root process inspected an unprivileged one and treated what it found in /proc as describing that process truthfully.
Plenty of software parses /proc/PID/cgroup: monitoring agents pull container IDs from it, log shippers tag processes with unit names, and in-house cleanup scripts decide what to kill. On a systemd host, everything below user@UID.service is writable by that user, and rootless container setups depend on delegated subtrees in the same way. A path like that is a claim made by the process. If your code acts on it as root, anchor the match at the root of the hierarchy, compare the uid you parsed with the real uid in /proc/PID/status and treat a mismatch as a reason to distrust the path, and never let any of it reach a shell string. Pass values as arguments or environment variables, the same fix needrestart ended up with.
Sources
- oss-security: needrestart local privilege escalation (CVE-2026-124757)
- Upstream fix commits b1996a1, 7874c08, e8ae1f2 (needrestart 3.11.1)
- Debian security tracker: CVE-2026-124757
- Debian LTS: DLA-4921-1 needrestart security update
- Ubuntu USN-9151-1 via OSV
- systemd: Control Group APIs and Delegation
- systemd
user@.serviceunit template - Corgea: CVE-2026-124757 analysis
- Canonical: needrestart local privilege escalation (2024)
- NVD: CVE-2024-48990