tvl-depot/third_party/nix
Alyssa Ross bac38f3c49 fix(3p/nix): 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>
(cherry picked from commit c05e20daa1abb3446e378331697938b78af2b3d7)
2020-05-24 00:12:38 +01:00
..
.github Add 'third_party/nix/' from commit 'be66c7a6b24e3c3c6157fd37b86c7203d14acf10' 2020-05-17 15:52:38 +01:00
config Add 'third_party/nix/' from commit 'be66c7a6b24e3c3c6157fd37b86c7203d14acf10' 2020-05-17 15:52:38 +01:00
contrib Add 'third_party/nix/' from commit 'be66c7a6b24e3c3c6157fd37b86c7203d14acf10' 2020-05-17 15:52:38 +01:00
corepkgs chore(3p/nix): Always enable the garbage collector 2020-05-17 22:27:53 +01:00
doc chore(3p/nix): Remove old build system and other miscellanies 2020-05-17 16:43:21 +01:00
maintainers Add 'third_party/nix/' from commit 'be66c7a6b24e3c3c6157fd37b86c7203d14acf10' 2020-05-17 15:52:38 +01:00
misc chore(3p/nix): Remove old build system and other miscellanies 2020-05-17 16:43:21 +01:00
scripts chore(3p/nix): Remove old build system and other miscellanies 2020-05-17 16:43:21 +01:00
src fix(3p/nix): Fix long paths permanently breaking GC 2020-05-24 00:12:38 +01:00
subprojects feat(3p/nix): Add Abseil as a CMAKE subproject to Meson 2020-05-20 03:03:08 +01:00
tests chore(3p/nix/tests): Remove leftover '__overrides' tests 2020-05-23 06:19:49 +01:00
.clang-format style(3p/nix): Change include formatting config for clang-format 2020-05-19 15:55:09 +01:00
.dir-locals.el fix(3p/nix): Set C++ style to "Google" in Emacs locals 2020-05-19 05:13:47 +01:00
.gitignore feat(3p/nix): added meson support 2020-05-17 15:55:13 +01:00
.travis.yml Add 'third_party/nix/' from commit 'be66c7a6b24e3c3c6157fd37b86c7203d14acf10' 2020-05-17 15:52:38 +01:00
.version Add 'third_party/nix/' from commit 'be66c7a6b24e3c3c6157fd37b86c7203d14acf10' 2020-05-17 15:52:38 +01:00
clangd.nix feat(3p/nix): Add a derivation to launch clangd 2020-05-22 23:00:23 +01:00
COPYING Add 'third_party/nix/' from commit 'be66c7a6b24e3c3c6157fd37b86c7203d14acf10' 2020-05-17 15:52:38 +01:00
default.nix style(3p/nix): Rename derivation to 'tazjix' 2020-05-23 23:47:45 +01:00
meson.build refactor(3p/nix/libexpr): Use absl::btree_map for AttrSets 2020-05-21 19:21:55 +01:00
meson_options.txt feat(3p/nix): Add some initial Abseil build targets 2020-05-20 04:02:23 +01:00
README.md Add 'third_party/nix/' from commit 'be66c7a6b24e3c3c6157fd37b86c7203d14acf10' 2020-05-17 15:52:38 +01:00

Open Collective supporters

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 http://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

This product includes software developed by the OpenSSL Project for use in the OpenSSL Toolkit.