SKY-D334 · Deployment and infrastructure
Root systemd service runs a program from a user-writable folder
An edge or device systemd service that runs as root and starts a program or script from a folder ordinary users can write to, such as /home, /tmp or a mounted USB stick. Whoever can change that file decides what root runs.
- Languages
- systemd units
- Quality gate
- counted toward the gate limits (full and diff scans). Reported under security (
danger). It counts towardmax_highandmax_security; the detector never reports CRITICAL. - Finding type
- review
- Catalog name
- Systemd root service executes mutable path
Why it matters
On a device where the default user's home folder holds the code, any process running as that user, or anyone with its SSH key, can edit the script and get root at the next restart.
What Skylos flags
[Unit]Description=Jetson camera uploader [Service]User=rootExecStart=/usr/bin/python3 /home/jetson/uploader/main.py --camera /dev/video0Restart=alwaysNoNewPrivileges=trueProtectSystem=strictPrivateTmp=trueWhat Skylos leaves alone
[Unit]Description=Jetson camera uploader [Service]User=rootWorkingDirectory=/home/jetson/uploaderExecStart=/opt/uploader/venv/bin/python /opt/uploader/main.py --camera /dev/video0Restart=alwaysNoNewPrivileges=trueProtectSystem=strictPrivateTmp=trueWhy Skylos leaves it alone
Only the working folder is under /home. The interpreter and the script both live under /opt, which only root can change, so this rule stays quiet. SKY-D333 still reports the User=root line.
How Skylos decides
- Runs with
--danger. Reads the same*.servicefiles as SKY-D333 and needs the same[Service]section and edge context (a device, camera, GPU or robot word, or a/dev/path, somewhere in the unit). - Needs the service to run as root: no
User=in[Service], or the lastUser=is empty,0orroot. - Looks at
ExecStart=,ExecStartPre=,ExecStartPost=andExecReload=, after removing systemd's-,+,!and@prefixes. - Reports when the program, or any later word in the command that starts with a path, is under
/home/,/tmp/,/var/tmp/,/dev/shm/,/media/,/mnt/or/run/user/. - Reports HIGH on the first such command line and then stops.
How to fix it
Install the code under a root-owned folder such as /opt and run it from there. If the service does not need root, also give it its own user, which clears SKY-D333 as well.
[Unit]Description=Jetson camera uploader [Service]User=rootRemoved: ExecStart=/usr/bin/python3 /home/jetson/uploader/main.py --camera /dev/video0Added: ExecStart=/usr/bin/python3 /opt/uploader/main.py --camera /dev/video0Restart=alwaysNoNewPrivileges=trueProtectSystem=strictPrivateTmp=trueWhen it can be wrong
- Any argument that is a path in one of those folders is read as the program being run, so
--spool /tmp/uploadson a root service is reported as "executes /tmp/uploads". A path written as--spool=/tmp/uploadsis not. - A script path inside quotes is missed:
ExecStart=/bin/sh -c "/home/pi/run.sh"is not reported. EnvironmentFile=andWorkingDirectory=under/homeare not checked, although a root service that reads environment variables from a user-writable file can also be taken over.- Root services with no device context are never checked.
Seeing a case that isn't listed here? Report the wrong result so the rule can be fixed. Don't paste company code: describe the shape of it.
How to silence it
Put the marker on a comment line directly above the reported
Exec…=line. systemd reads#only at the start of a line, so do not append it to the command.INI # skylos: ignore[SKY-D334] /home/jetson is root-owned on this imageExecStart=/usr/bin/python3 /home/jetson/uploader/main.py[tool.skylos] ignore = ["SKY-D334"]turns the rule off for the project.