Skip to content

--mpi-command is passed through strconv.Quote, so any command with arguments becomes one argv word (and $ still expands) #660

Closed

Description

@scttfrdmn

https://github.com/spore-host/spawn/blob/528e038/pkg/userdata/mpi.go#L107 renders mpirun ... -hostfile /tmp/mpi-hostfile {{.MPICommand | shellEscape}}, and security.ShellEscape is strconv.Quote (https://github.com/spore-host/spawn/blob/528e038/pkg/security/shell.go#L12).

Effect: --mpi-command "./gchp --flag x" becomes mpirun ... "./gchp --flag x", a single argument, so mpirun looks for an executable literally named ./gchp --flag x. Only argument-free commands work.

Also, strconv.Quote produces Go/C escaping inside double quotes, which is not shell escaping: $VAR, $(...) and backticks still expand on the instance. So it neither preserves argv nor neutralizes shell metacharacters.

Suggested: treat --mpi-command as a shell command line (it is user-authored, same trust as --command) and emit it unquoted into a generated script, e.g. write it to /etc/spawn/mpi-command and run mpirun ... bash /etc/spawn/mpi-command, or accept repeatable --mpi-arg. If injection safety is the goal, single-quote with '\'' escaping.

Related: the same template prepends /usr/lib64/openmpi/bin to PATH even with --skip-mpi-install; harmless, but documenting that a custom MPI must be set up by the user's command would help.

Workaround: put the launch in a script and pass its path.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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