From 0e444785a16b0cb278dfd5aaa4d04b7730a269d8 Mon Sep 17 00:00:00 2001 From: Profpatsch Date: Sun, 26 Jun 2022 18:45:32 +0200 Subject: [PATCH] installer/tools/get-version-suffix: set --git-dir MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The `nixos-rebuild` tool calls `get-version-suffix` to figure out the git revision of the nixpkgs directory if there is a .git. https://nvd.nist.gov/vuln/detail/CVE-2022-24765 made git throw an error if the .git search logic is not turned off and a user tries to access a `.git` directory they don’t own (otherwise a different user could trick them into setting arbitrary git config). So from now on we should always explicitely set `--git-dir`, which turns this search logic (and thus the security check) off. --- nixos/modules/installer/tools/get-version-suffix | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/nixos/modules/installer/tools/get-version-suffix b/nixos/modules/installer/tools/get-version-suffix index b8972cd57d22..8d72905cdcb4 100644 --- a/nixos/modules/installer/tools/get-version-suffix +++ b/nixos/modules/installer/tools/get-version-suffix @@ -1,14 +1,15 @@ getVersion() { local dir="$1" rev= - if [ -e "$dir/.git" ]; then + gitDir="$dir/.git" + if [ -e "$gitDir" ]; then if [ -z "$(type -P git)" ]; then echo "warning: Git not found; cannot figure out revision of $dir" >&2 return fi cd "$dir" - rev=$(git rev-parse --short HEAD) - if git describe --always --dirty | grep -q dirty; then + rev=$(git --git-dir="$gitDir" rev-parse --short HEAD) + if git --git-dir="$gitDir" describe --always --dirty | grep -q dirty; then rev+=M fi fi