Am I affected?

type your mix version to check

Description

Insecure Temporary File vulnerability in Mix deps.partition in Elixir allows a local user to execute code as another user via a swapped partition config file. Partitioned dependency compilation passes the project configuration to each partition VM through a file in a fixed-name directory under the shared system temporary directory, and the partition trusts what it reads back. Another local user on the same host can exploit this during a mix deps.compile run that uses partitioned compilation.

Mix.Tasks.Deps.Partition.server/4 in lib/mix/lib/mix/tasks/deps.partition.ex creates the directory with File.mkdir_p/1, which accepts an existing directory without checking its owner, so a user who created it first can replace the file before client/0 reads it.

This issue affects mix: from 1.20.0-rc.4 before 1.20.5.

Technical analysis

1. Payload written to a shared location

Mix.Tasks.Deps.Partition.server/4 in lib/mix/lib/mix/tasks/deps.partition.ex encodes Mix.ProjectStack.peek() with :erlang.term_to_binary/1 and Base64, calls File.mkdir_p/1 on Path.join(System.tmp_dir(), "mix_deps_partition"), and writes the payload to a file with a random name inside it. The directory name is fixed, carries no user id, and File.mkdir_p/1 succeeds on a directory that already exists, whoever owns it. The file is created with the default mode, so it is readable by other users in a shared temporary directory.

2. Partition VMs trust the file

Each partition is a fresh elixir VM started with --config-file <path>. Mix.Tasks.Deps.Partition.client/0 reads the file with File.read!/1, decodes it with :erlang.binary_to_term/1, and pushes the decoded entry (project name, config and mix.exs path) with Mix.ProjectStack.push/3. Nothing verifies that the file still holds what the parent wrote.

3. Attacker control

A local user who created mix_deps_partition before the victim's build owns it and may replace or rewrite any file inside, so they swap the payload between the parent's write and the client's read. The client then compiles the attacker's deps list, and a dependency's compile: option is a shell command Mix executes in the victim's build. On the development branch the payload also carries code_path and compiler_options, which the client applies with :code.set_path/1 and Code.compiler_options/1, so there the attacker also controls the client VM's code path.

Proof of concept

  1. On a multi-user Linux host where System.tmp_dir() resolves to /tmp, the attacker creates /tmp/mix_deps_partition as their own directory and watches it for new files.
  2. The victim runs mix deps.compile (directly, or through mix compile or mix test) with MIX_OS_DEPS_COMPILE_PARTITION_COUNT=2 on a project with at least two non-local dependencies. File.mkdir_p/1 succeeds on the existing directory and the config file is written into it.
  3. Before the partition VMs boot and read the file, the attacker decodes it, adds a compile: shell command to every dependency in config[:deps], re-encodes it and writes it back.
  4. Each partition decodes the attacker's term and deps.compile runs the injected command as the victim user.

Weaknesses & attack patterns

Weakness

CWE-377 · Insecure Temporary File in catalog → MITRE ↗

Attack patterns

CAPEC-26 · Leveraging Race Conditions MITRE ↗

A local user on a shared host who creates the partition directory before the victim's build replaces the serialized configuration and runs arbitrary shell commands as the developer or CI user whose mix deps.compile uses partitioned compilation.

CAPEC-155 · Screen Temporary Files for Sensitive Information MITRE ↗

Even without pre-creating the directory, the world-readable partition file discloses the project configuration, including Mix.install compile-time config, to other local users while the build runs.

Affected — Elixir / mix Repository ↗

≥ 1.20.0-rc.4 < 1.20.5 affected
every other version: unaffected
cpe cpe:2.3:a:elixir-lang:elixir:*:*:*:*:*:*:*:*
version type semver
modules · source files · routines
modules 'Elixir.Mix.Tasks.Deps.Partition'
source files lib/mix/tasks/deps.partition.ex
routines 'Elixir.Mix.Tasks.Deps.Partition':server/3 · 'Elixir.Mix.Tasks.Deps.Partition':server/4 · 'Elixir.Mix.Tasks.Deps.Partition':client/0

Affected — GitHub / elixir-lang/elixir Repository ↗

≥ 7f3d95b and up affected
→ 55eb912 not affected
→ 9adbe95 not affected
every other version: unaffected
cpe cpe:2.3:a:elixir-lang:elixir:*:*:*:*:*:*:*:*
version type git
modules · source files · routines
modules 'Elixir.Mix.Tasks.Deps.Partition'
source files lib/mix/lib/mix/tasks/deps.partition.ex
routines 'Elixir.Mix.Tasks.Deps.Partition':server/3 · 'Elixir.Mix.Tasks.Deps.Partition':server/4 · 'Elixir.Mix.Tasks.Deps.Partition':client/0

Workarounds

On a multi-user host, set TMPDIR to a private per-user directory with mode 0700 before running Mix, so that System.tmp_dir/0 resolves to a location other users cannot pre-create or read. Alternatively, keep partitioned compilation disabled by leaving MIX_OS_DEPS_COMPILE_PARTITION_COUNT unset or at 1, which keeps the configuration inside the parent process.

Configurations

The attack requires partitioned dependency compilation, which is off by default and enabled by setting MIX_OS_DEPS_COMPILE_PARTITION_COUNT to a value greater than one, a mix deps.compile run that compiles at least two non-local dependencies, and a system temporary directory shared with other local users, which is the default on Linux when TMPDIR is unset. Platforms with per-user temporary directories, such as macOS and Windows by default, are not affected unless TMPDIR points at a shared location.

References

Credits

Quinn Wilton Finder Reporter
José Valim Remediation developer
Jonatan Männchen / EEF Coordinator

CVSS breakdown

CVSS:4.0/AV:L/AC:L/AT:P/PR:L/UI:P/VC:H/VI:H/VA:H/SC:N/SI:N/SA:N
« All CVEs