nix-super/src
Jade Lovelace 7b6622d733 language: cleanly ban integer overflows
This also bans various sneaking of negative numbers from the language
into unsuspecting builtins as was exposed while auditing the
consequences of changing the Nix language integer type to a newtype.

It's unlikely that this change comprehensively ensures correctness when
passing integers out of the Nix language and we should probably add a
checked-narrowing function or something similar, but that's out of scope
for the immediate change.

During the development of this I found a few fun facts about the
language:
- You could overflow integers by converting from unsigned JSON values.
- You could overflow unsigned integers by converting negative numbers
  into them when going into Nix config, into fetchTree, and into flake
  inputs.

  The flake inputs and Nix config cannot actually be tested properly
  since they both ban thunks, however, we put in checks anyway because
  it's possible these could somehow be used to do such shenanigans some
  other way.

Note that Lix has banned Nix language integer overflows since the very
first public beta, but threw a SIGILL about them because we run with
-fsanitize=signed-overflow -fsanitize-undefined-trap-on-error in
production builds. Since the Nix language uses signed integers, overflow
was simply undefined behaviour, and since we defined that to trap, it
did.

Trapping on it was a bad UX, but we didn't even entirely notice
that we had done this at all until it was reported as a bug a couple of
months later (which is, to be fair, that flag working as intended), and
it's got enough production time that, aside from code that is IMHO buggy
(and which is, in any case, not in nixpkgs) such as
https://git.lix.systems/lix-project/lix/issues/445, we don't think
anyone doing anything reasonable actually depends on wrapping overflow.

Even for weird use cases such as doing funny bit crimes, it doesn't make
sense IMO to have wrapping behaviour, since two's complement arithmetic
overflow behaviour is so *aggressively* not what you want for *any* kind
of mathematics/algorithms. The Nix language exists for package
management, a domain where bit crimes are already only dubiously in
scope to begin with, and it makes a lot more sense for that domain for
the integers to never lose precision, either by throwing errors if they
would, or by being arbitrary-precision.

Fixes: https://github.com/NixOS/nix/issues/10968
Original-CL: https://gerrit.lix.systems/c/lix/+/1596

Change-Id: I51f253840c4af2ea5422b8a420aa5fafbf8fae75
2024-07-30 18:13:05 -07:00
..
build-remote build-remote: only allocate storeUri once 2024-07-25 14:04:03 +02:00
external-api-docs Deduplicate our many package.nix a bit (#11175) 2024-07-25 03:12:39 +00:00
internal-api-docs Deduplicate our many package.nix a bit (#11175) 2024-07-25 03:12:39 +00:00
libcmd language: cleanly ban integer overflows 2024-07-30 18:13:05 -07:00
libexpr language: cleanly ban integer overflows 2024-07-30 18:13:05 -07:00
libexpr-c language: cleanly ban integer overflows 2024-07-30 18:13:05 -07:00
libfetchers Merge pull request #11195 from DeterminateSystems/tarball-roots 2024-07-29 16:58:59 +02:00
libflake language: cleanly ban integer overflows 2024-07-30 18:13:05 -07:00
libmain Merge pull request #11167 from NixOS/repl-test-rejiggle 2024-07-27 00:55:57 +02:00
libmain-c Deduplicate our many package.nix a bit (#11175) 2024-07-25 03:12:39 +00:00
libstore language: cleanly ban integer overflows 2024-07-30 18:13:05 -07:00
libstore-c Deduplicate our many package.nix a bit (#11175) 2024-07-25 03:12:39 +00:00
libutil libutil: add checked arithmetic tools 2024-07-30 18:13:05 -07:00
libutil-c Merge pull request #11127 from NixOS/issue-10635-c-api-error-enum 2024-07-29 16:00:58 +02:00
nix diff-closures: remove gratuitous copy 2024-07-25 21:41:31 +02:00
nix-build Merge pull request #11058 from hercules-ci/more-nix-shell 2024-07-17 21:52:34 +02:00
nix-channel downloadFile(): Remove the "locked" (aka "immutable") flag 2024-04-08 15:56:16 +02:00
nix-collect-garbage inline the usage of nix::readDirectory 2024-05-12 17:42:18 +05:30
nix-copy-closure Restrict some code to StoreDirConfig 2023-11-04 19:05:36 -04:00
nix-env Use std::strong_ordering for version comparison 2024-07-30 18:13:05 -07:00
nix-instantiate No global settings in libnixfetchers and libnixflake 2024-07-12 08:50:28 -04:00
nix-store Make abort() call sites log first 2024-07-24 16:52:04 +02:00
perl add werror=suggest-override 2024-07-25 07:41:12 +02:00
nix-expr-test-support Put back files for now 2024-07-02 09:26:22 -04:00
nix-expr-tests Put back files for now 2024-07-02 09:26:22 -04:00
nix-fetchers-tests Put back files for now 2024-07-02 09:26:22 -04:00
nix-flake-tests Put back files for now 2024-07-02 09:26:22 -04:00
nix-store-test-support Put back files for now 2024-07-02 09:26:22 -04:00
nix-store-tests Put back files for now 2024-07-02 09:26:22 -04:00
nix-util-test-support Put back files for now 2024-07-02 09:26:22 -04:00
nix-util-tests Put back files for now 2024-07-02 09:26:22 -04:00