A modern, delicious implementation of the Nix package manager, focused on correctness, usability, and growth — and committed to doing right by its community
Find a file
Alyssa Ross c05e20daa1
Fix long paths permanently breaking GC
Suppose I have a path /nix/store/[hash]-[name]/a/a/a/a/a/[...]/a,
long enough that everything after "/nix/store/" is longer than 4096
(MAX_PATH) bytes.

Nix will happily allow such a path to be inserted into the store,
because it doesn't look at all the nested structure.  It just cares
about the /nix/store/[hash]-[name] part.  But, when the path is deleted,
we encounter a problem.  Nix will move the path to /nix/store/trash, but
then when it's trying to recursively delete the trash directory, it will
at some point try to unlink
/nix/store/trash/[hash]-[name]/a/a/a/a/a/[...]/a.  This will fail,
because the path is too long.  After this has failed, any store deletion
operation will never work again, because Nix needs to delete the trash
directory before recreating it to move new things to it.  (I assume this
is because otherwise a path being deleted could already exist in the
trash, and then moving it would fail.)

This means that if I can trick somebody into just fetching a tarball
containing a path of the right length, they won't be able to delete
store paths or garbage collect ever again, until the offending path is
manually removed from /nix/store/trash.  (And even fixing this manually
is quite difficult if you don't understand the issue, because the
absolute path that Nix says it failed to remove is also too long for
rm(1).)

This patch fixes the issue by making Nix's recursive delete operation
use unlinkat(2).  This function takes a relative path and a directory
file descriptor.  We ensure that the relative path is always just the
name of the directory entry, and therefore its length will never exceed
255 bytes.  This means that it will never even come close to AX_PATH,
and Nix will therefore be able to handle removing arbitrarily deep
directory hierachies.

Since the directory file descriptor is used for recursion after being
used in readDirectory, I made a variant of readDirectory that takes an
already open directory stream, to avoid the directory being opened
multiple times.  As we have seen from this issue, the less we have to
interact with paths, the better, and so it's good to reuse file
descriptors where possible.

I left _deletePath as succeeding even if the parent directory doesn't
exist, even though that feels wrong to me, because without that early
return, the linux-sandbox test failed.

Reported-by: Alyssa Ross <hi@alyssa.is>
Thanks-to: Puck Meerburg <puck@puckipedia.com>
Tested-by: Puck Meerburg <puck@puckipedia.com>
Reviewed-by: Puck Meerburg <puck@puckipedia.com>
2020-04-27 20:50:17 +00:00
.github Remove build and binaryTarball since they're included in installerScript 2020-03-13 15:56:25 +01:00
config update config/config.{sub,guess} 2018-08-13 20:00:17 +00:00
contrib function-trace: always show the trace 2019-09-18 23:23:21 +02:00
corepkgs Move some corepkgs into the nix binary 2020-03-11 16:57:48 +01:00
doc/manual add NIX_USER_CONF_FILES 2020-04-14 18:45:06 +02:00
m4 autoconf: Fix C++17 detection not working on Ubuntu 16.04. 2019-07-03 04:32:25 +02:00
maintainers Update release script 2020-04-10 17:27:35 +02:00
misc Make nix-daemon.plist less fragile on macOS 2019-10-09 12:52:01 +01:00
mk Remove global -I flags 2020-03-30 15:30:19 +02:00
nix-rust Remove macro_use 2020-02-10 09:03:24 +01:00
perl nix-perl: Fix segfault in queryPathInfo) 2020-03-10 11:00:17 +01:00
scripts installer: Fix terminal colors. 2020-03-24 21:15:01 -07:00
src Fix long paths permanently breaking GC 2020-04-27 20:50:17 +00:00
tests Merge pull request #3458 from zimbatm/nix-user-conf-dir 2020-04-15 13:00:28 +02:00
.dir-locals.el .dir-locals.el: Set additional lambda indentation to zero 2020-02-20 07:56:35 +01:00
.editorconfig Add .editorconfig 2017-06-05 22:57:28 +01:00
.gitignore ignore error-demo 2020-04-06 12:05:17 -06:00
.version Bump version 2019-09-04 15:59:33 +02:00
bootstrap.sh bootstrap: Simplify & make more robust. 2011-09-06 12:11:05 +00:00
configure.ac Merge branch 'libarchive' of https://github.com/yorickvP/nix 2019-12-19 14:47:18 +01:00
COPYING * Change this to LGPL to keep the government happy. 2006-04-25 16:41:06 +00:00
local.mk Remove global -I flags 2020-03-30 15:30:19 +02:00
Makefile Don't install error-demo 2020-04-22 15:29:22 +02:00
Makefile.config.in Misc changes from the flakes branch 2020-03-24 14:34:47 +01:00
precompiled-headers.h Fix macOS build 2019-11-07 11:53:28 +01:00
README.md README: add github actions badge 2020-04-09 15:04:51 +02:00
release-common.nix Remove the tarball job 2020-03-13 18:05:22 +01:00
release.nix Publish a tarball containing the crates we depend on 2020-04-03 20:14:34 +02:00
shell.nix Remove the tarball job 2020-03-13 18:05:22 +01:00

Open Collective supporters Test

Nix, the purely functional package manager

Nix is a new take on package management that is fairly unique. Because of its purity aspects, a lot of issues found in traditional package managers don't appear with Nix.

To find out more about the tool, usage and installation instructions, please read the manual, which is available on the Nix website at https://nixos.org/nix/manual.

Contributing

Take a look at the Hacking Section of the manual. It helps you to get started with building Nix from source.

License

Nix is released under the LGPL v2.1