Skip to main content

SKY-D334 · Deployment and infrastructure

Root systemd service runs a program from a user-writable folder

High

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 toward max_high and max_security; the detector never reports CRITICAL.
Finding type
review
Catalog name
Systemd root service executes mutable path
Wrong result? Report itA false positive, a missed case or a confusing message: it goes privately to the founder.

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

camera-uploader.service · INIReported on line 6
[Unit]Description=Jetson camera uploader [Service]User=rootExecStart=/usr/bin/python3 /home/jetson/uploader/main.py --camera /dev/video0Restart=alwaysNoNewPrivileges=trueProtectSystem=strictPrivateTmp=true

What Skylos leaves alone

camera-uploader.service · INI
[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=true

Why 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

  1. Runs with --danger. Reads the same *.service files 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).
  2. Needs the service to run as root: no User= in [Service], or the last User= is empty, 0 or root.
  3. Looks at ExecStart=, ExecStartPre=, ExecStartPost= and ExecReload=, after removing systemd's -, +, ! and @ prefixes.
  4. 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/.
  5. 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.

camera-uploader.service · INI · the fix, against the flagged file
[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=true

When 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/uploads on a root service is reported as "executes /tmp/uploads". A path written as --spool=/tmp/uploads is not.
  • A script path inside quotes is missed: ExecStart=/bin/sh -c "/home/pi/run.sh" is not reported.
  • EnvironmentFile= and WorkingDirectory= under /home are 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.

From the Skylos rule handbook, Skylos 5.8.0 (commit 5b880b0). All rules.