Summary
makeBinaryWrapper/makeCWrapper implements --prefix/ --suffix by concatenating the given value onto a search-path environment variable (PATH, LD_LIBRARY_PATH…) without checking whether that value is empty.
When the value is empty (e.g. because the provided value was the result of lib.makeBinPath over an empty list) an empty path segment will be added into the variable. POSIX shells and execvp() will consider the empty path segment as the current working directory.
Impact
An attacker who can place a file with a specific name in a directory the victim later runs an affected tool from (an untrusted git checkout, a downloaded archive…) can get that file silently executed or loaded as a library.
This can result on full code execution or a Denial of Service for some commands when the programming language includes some additional protection (see Go ErrDot for example).
Am I affected?
You are impacted if you are using a package using makeBinaryWrapper with --prefix/--suffix on a path value variable that can be empty during the build.
The nixpkgs security team identified the following impacted packages:
zellijtreefmt.withConfig(limited DoS due to Go restrictions)dockerCLI (limited DoS due to Go restrictions)buildah(only for Darwin and limited DoS due to Go restrictions)lispWithPackagesqt6Packages.fcitx5-with-addonsocelot-desktop(only forx86_64-darwin)
zellij is the most critical one in the packages we identified due to its nature and the absence of other mitigations.
Note the list might not be exhaustive due to the large nixpkgs package set and potential usages outside of nixpkgs.
You can use the following script to identify binaries in your /nix/store that might be impacted by the issue:
#! /usr/bin/env nix-shell
#! nix-shell -i bash --pure
#! nix-shell -p findutils gnugrep gawk binutils
set -uo pipefail
STORE="${1:-/nix/store}"
printf 'BINARY\tFLAG\tENV_VAR\tVALUE\n'
while read -r f; do
grep -qF 'makeCWrapper' "$f" || continue
strings -a -- "$f" | awk -F"'" -v bin="$f" '
/--prefix |--suffix / {
flag = ($0 ~ /--prefix /) ? "--prefix" : "--suffix"
env = $2
sep = $4
val = $6
if (sep == "") next
wrapped_val = sep val sep
doubled = sep sep
if (index(wrapped_val, doubled) > 0) {
printf "%s\t%s\t%s\t[%s]\n", bin, flag, env, val
found = 1
}
}
END { exit (found ? 0 : 1) }
'
done < <(find "$STORE" -type f -executable)
What do I need to do?
Update, you can track the progress of the different pull-requests below.
In the meantime, until patched avoid running any affected tool from a directory with content you do not trust.
Fixes:
makeBinaryWrapper: reject prefix/suffix with an empty path segment- Unstable: makeBinaryWrapper: reject prefix/suffix with an empty path segment by LeSuisse · Pull Request #548442 · NixOS/nixpkgs · GitHub (Progress tracking)
- 26.05: rejection check has not been backported to avoid introducing a change in behavior in the wrapper
zellij:- Unstable: zellij: avoid putting empty path segment into PATH when `extraPackages` is empty by LeSuisse · Pull Request #545564 · NixOS/nixpkgs · GitHub (Progress tracking)
- 26.05: [Backport release-26.05] zellij: avoid putting empty path segment into PATH when `extraPackages` is empty by nixpkgs-ci[bot] · Pull Request #545575 · NixOS/nixpkgs · GitHub (Progress tracking)
treefmt.withConfig- Unstable: treefmt.withConfig: prevent an empty path segment in PATH when `config.runtimeInputs` is empty by LeSuisse · Pull Request #545570 · NixOS/nixpkgs · GitHub (Progress tracking)
- 26.05: [Backport release-26.05] treefmt.withConfig: prevent an empty path segment in PATH when `config.runtimeInputs` is empty by nixpkgs-ci[bot] · Pull Request #547177 · NixOS/nixpkgs · GitHub (Progress tracking)
dockerCLI- Unstable: docker: avoid setting empty path segments into PATH by LeSuisse · Pull Request #545560 · NixOS/nixpkgs · GitHub (Progress tracking)
- 26.05: [Backport release-26.05] docker: avoid setting empty path segments into PATH by nixpkgs-ci[bot] · Pull Request #545611 · NixOS/nixpkgs · GitHub (Progress tracking)
buildahlispWithPackages- Unstable: nix-cl: avoid empty path segments in prefixed env variables by LeSuisse · Pull Request #545580 · NixOS/nixpkgs · GitHub (Progress tracking)
- 26.05: [Backport release-26.05] nix-cl: avoid empty path segments in prefixed env variables by nixpkgs-ci[bot] · Pull Request #549258 · NixOS/nixpkgs · GitHub (Progress tracking)
qt6Packages.fcitx5-with-addons- Unstable: fcitx5-with-addons: avoid empty path segment in `LD_LIBRARY_PATH` by LeSuisse · Pull Request #545592 · NixOS/nixpkgs · GitHub (Progress tracking)
- 26.05: [Backport release-26.05] fcitx5-with-addons: avoid empty path segment in `LD_LIBRARY_PATH` by nixpkgs-ci[bot] · Pull Request #547495 · NixOS/nixpkgs · GitHub (Progress tracking)
ocelot-desktop- Unstable: ocelot-desktop: avoid putting empty segments in PATH and LD_LIBRARY_PATH by LeSuisse · Pull Request #545608 · NixOS/nixpkgs · GitHub (Progress tracking)
- 26.05: [Backport release-26.05] ocelot-desktop: avoid putting empty segments in PATH and LD_LIBRARY_PATH by nixpkgs-ci[bot] · Pull Request #545627 · NixOS/nixpkgs · GitHub (Progress tracking)
Acknowledgement
Thank you to cielavenir for reporting the issue with the docker CLI to the nixpkgs security team.