Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions nixos/doc/manual/release-notes/rl-2405.section.md
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,8 @@ The pre-existing [services.ankisyncd](#opt-services.ankisyncd.enable) has been m

- `stdenv`: The `--replace` flag in `substitute`, `substituteInPlace`, `substituteAll`, `substituteAllStream`, and `substituteStream` is now deprecated if favor of the new `--replace-fail`, `--replace-warn` and `--replace-quiet`. The deprecated `--replace` equates to `--replace-warn`.

- A new hardening flag, `zerocallusedregs` was made available, corresponding to the gcc/clang option `-fzero-call-used-regs=used-gpr`.

- The Yama LSM is now enabled by default in the kernel, which prevents ptracing
non-child processes. This means you will not be able to attach gdb to an
existing process, but will need to start that process from gdb (so it is a
Expand All @@ -212,6 +214,8 @@ The pre-existing [services.ankisyncd](#opt-services.ankisyncd.enable) has been m

- [](#opt-boot.kernel.sysctl._net.core.wmem_max_) changed from a string to an integer because of the addition of a custom merge option (taking the highest value defined to avoid conflicts between 2 services trying to set that value), just as [](#opt-boot.kernel.sysctl._net.core.rmem_max_) since 22.11.

- A new top-level package set, `pkgsExtraHardening` is added. This is a set of packages built with stricter hardening flags - those that have not yet received enough testing to be applied universally, those that are more likely to cause build failures or those that have drawbacks to their use (e.g. performance or required hardware features).

- `services.zfs.zed.enableMail` now uses the global `sendmail` wrapper defined by an email module
(such as msmtp or Postfix). It no longer requires using a special ZFS build with email support.

Expand Down
6 changes: 5 additions & 1 deletion pkgs/build-support/cc-wrapper/add-hardening.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ if [[ -n "${hardeningEnableMap[fortify3]-}" ]]; then
fi

if (( "${NIX_DEBUG:-0}" >= 1 )); then
declare -a allHardeningFlags=(fortify fortify3 stackprotector pie pic strictoverflow format)
declare -a allHardeningFlags=(fortify fortify3 stackprotector pie pic strictoverflow format zerocallusedregs)
declare -A hardeningDisableMap=()

# Determine which flags were effectively disabled so we can report below.
Expand Down Expand Up @@ -110,6 +110,10 @@ for flag in "${!hardeningEnableMap[@]}"; do
if (( "${NIX_DEBUG:-0}" >= 1 )); then echo HARDENING: enabling format >&2; fi
hardeningCFlagsBefore+=('-Wformat' '-Wformat-security' '-Werror=format-security')
;;
zerocallusedregs)
if (( "${NIX_DEBUG:-0}" >= 1 )); then echo HARDENING: enabling zerocallusedregs >&2; fi
hardeningCFlagsBefore+=('-fzero-call-used-regs=used-gpr')
;;
*)
# Ignore unsupported. Checked in Nix that at least *some*
# tool supports each flag.
Expand Down
11 changes: 10 additions & 1 deletion pkgs/build-support/cc-wrapper/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,15 @@ let

defaultHardeningFlags = bintools.defaultHardeningFlags or [];

# if cc.hardeningUnsupportedFlagsByTargetPlatform exists, this is
# called with the targetPlatform as an argument and
# cc.hardeningUnsupportedFlags is completely ignored - the function
# is responsible for including the constant hardeningUnsupportedFlags
# list however it sees fit.
ccHardeningUnsupportedFlags = if cc ? hardeningUnsupportedFlagsByTargetPlatform
then cc.hardeningUnsupportedFlagsByTargetPlatform targetPlatform
else (cc.hardeningUnsupportedFlags or []);

darwinPlatformForCC = optionalString stdenv.targetPlatform.isDarwin (
if (targetPlatform.darwinPlatform == "macos" && isGNU) then "macosx"
else targetPlatform.darwinPlatform
Expand Down Expand Up @@ -584,7 +593,7 @@ stdenv.mkDerivation {
## Hardening support
##
+ ''
export hardening_unsupported_flags="${builtins.concatStringsSep " " (cc.hardeningUnsupportedFlags or [])}"
export hardening_unsupported_flags="${builtins.concatStringsSep " " ccHardeningUnsupportedFlags}"
''

# Machine flags. These are necessary to support
Expand Down
1 change: 1 addition & 0 deletions pkgs/development/compilers/gcc/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,7 @@ lib.pipe ((callFile ./common/builder.nix {}) ({
inherit langC langCC langObjC langObjCpp langAda langFortran langGo langD langJava version;
isGNU = true;
hardeningUnsupportedFlags = lib.optional is48 "stackprotector"
++ lib.optional (!atLeast11) "zerocallusedregs"
++ lib.optional (!atLeast12) "fortify3"
++ lib.optionals (langFortran) [ "fortify" "format" ];
};
Expand Down
2 changes: 1 addition & 1 deletion pkgs/development/compilers/llvm/10/clang/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ let
passthru = {
inherit libllvm;
isClang = true;
hardeningUnsupportedFlags = [ "fortify3" ];
hardeningUnsupportedFlags = [ "fortify3" "zerocallusedregs" ];
};

meta = llvm_meta // {
Expand Down
2 changes: 1 addition & 1 deletion pkgs/development/compilers/llvm/11/clang/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ let
passthru = {
inherit libllvm;
isClang = true;
hardeningUnsupportedFlags = [ "fortify3" ];
hardeningUnsupportedFlags = [ "fortify3" "zerocallusedregs" ];
};

meta = llvm_meta // {
Expand Down
2 changes: 1 addition & 1 deletion pkgs/development/compilers/llvm/12/clang/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ let
passthru = {
inherit libllvm;
isClang = true;
hardeningUnsupportedFlags = [ "fortify3" ];
hardeningUnsupportedFlags = [ "fortify3" "zerocallusedregs" ];
};

meta = llvm_meta // {
Expand Down
2 changes: 1 addition & 1 deletion pkgs/development/compilers/llvm/13/clang/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ let
passthru = {
inherit libllvm;
isClang = true;
hardeningUnsupportedFlags = [ "fortify3" ];
hardeningUnsupportedFlags = [ "fortify3" "zerocallusedregs" ];
};

meta = llvm_meta // {
Expand Down
2 changes: 1 addition & 1 deletion pkgs/development/compilers/llvm/14/clang/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ let
passthru = {
inherit libllvm;
isClang = true;
hardeningUnsupportedFlags = [ "fortify3" ];
hardeningUnsupportedFlags = [ "fortify3" "zerocallusedregs" ];
};

meta = llvm_meta // {
Expand Down
9 changes: 7 additions & 2 deletions pkgs/development/compilers/llvm/15/clang/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
}:

let
self = stdenv.mkDerivation (rec {
self = stdenv.mkDerivation (finalAttrs: rec {
pname = "clang";
inherit version;

Expand Down Expand Up @@ -97,7 +97,12 @@ let
passthru = {
inherit libllvm;
isClang = true;
hardeningUnsupportedFlags = [ "fortify3" ];
hardeningUnsupportedFlags = [
"fortify3"
];
hardeningUnsupportedFlagsByTargetPlatform = targetPlatform:
lib.optional (!(targetPlatform.isx86_64 || targetPlatform.isAarch64)) "zerocallusedregs"
++ (finalAttrs.passthru.hardeningUnsupportedFlags or []);
};

meta = llvm_meta // {
Expand Down
9 changes: 7 additions & 2 deletions pkgs/development/compilers/llvm/16/clang/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
}:

let
self = stdenv.mkDerivation (rec {
self = stdenv.mkDerivation (finalAttrs: rec {
pname = "clang";
inherit version;

Expand Down Expand Up @@ -91,7 +91,12 @@ let
passthru = {
inherit libllvm;
isClang = true;
hardeningUnsupportedFlags = [ "fortify3" ];
hardeningUnsupportedFlags = [
"fortify3"
];
hardeningUnsupportedFlagsByTargetPlatform = targetPlatform:
lib.optional (!(targetPlatform.isx86_64 || targetPlatform.isAarch64)) "zerocallusedregs"
++ (finalAttrs.passthru.hardeningUnsupportedFlags or []);
};

meta = llvm_meta // {
Expand Down
9 changes: 7 additions & 2 deletions pkgs/development/compilers/llvm/17/clang/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
}:

let
self = stdenv.mkDerivation (rec {
self = stdenv.mkDerivation (finalAttrs: rec {
pname = "clang";
inherit version;

Expand Down Expand Up @@ -95,7 +95,12 @@ let
passthru = {
inherit libllvm;
isClang = true;
hardeningUnsupportedFlags = [ "fortify3" ];
hardeningUnsupportedFlags = [
"fortify3"
];
hardeningUnsupportedFlagsByTargetPlatform = targetPlatform:
lib.optional (!(targetPlatform.isx86_64 || targetPlatform.isAarch64)) "zerocallusedregs"
++ (finalAttrs.passthru.hardeningUnsupportedFlags or []);
};

meta = llvm_meta // {
Expand Down
2 changes: 1 addition & 1 deletion pkgs/development/compilers/llvm/8/clang/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ let
passthru = {
inherit libllvm;
isClang = true;
hardeningUnsupportedFlags = [ "fortify3" ];
hardeningUnsupportedFlags = [ "fortify3" "zerocallusedregs" ];
};

meta = llvm_meta // {
Expand Down
2 changes: 1 addition & 1 deletion pkgs/development/compilers/llvm/9/clang/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ let
passthru = {
inherit libllvm;
isClang = true;
hardeningUnsupportedFlags = [ "fortify3" ];
hardeningUnsupportedFlags = [ "fortify3" "zerocallusedregs" ];
};

meta = llvm_meta // {
Expand Down
9 changes: 7 additions & 2 deletions pkgs/development/compilers/llvm/git/clang/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
}:

let
self = stdenv.mkDerivation (rec {
self = stdenv.mkDerivation (finalAttrs: rec {
pname = "clang";
inherit version;

Expand Down Expand Up @@ -95,7 +95,12 @@ let
passthru = {
inherit libllvm;
isClang = true;
hardeningUnsupportedFlags = [ "fortify3" ];
hardeningUnsupportedFlags = [
"fortify3"
];
hardeningUnsupportedFlagsByTargetPlatform = targetPlatform:
lib.optional (!(targetPlatform.isx86_64 || targetPlatform.isAarch64)) "zerocallusedregs"
++ (finalAttrs.passthru.hardeningUnsupportedFlags or []);
};

meta = llvm_meta // {
Expand Down
5 changes: 4 additions & 1 deletion pkgs/stdenv/darwin/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,10 @@ in
ln -s ${bootstrapTools}/lib/clang $out/lib
ln -s ${bootstrapTools}/include $out
'';
passthru.isFromBootstrapFiles = true;
passthru = {
isFromBootstrapFiles = true;
hardeningUnsupportedFlags = [ "fortify3" "zerocallusedregs" ];
};
};
clang-unwrapped = selfTools.libclang;
libllvm = self.stdenv.mkDerivation {
Expand Down
1 change: 1 addition & 0 deletions pkgs/stdenv/generic/make-derivation.nix
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@ let
"relro"
"stackprotector"
"strictoverflow"
"zerocallusedregs"
];
defaultHardeningFlags =
(if stdenv.hasCC then stdenv.cc else {}).defaultHardeningFlags or
Expand Down
2 changes: 1 addition & 1 deletion pkgs/stdenv/linux/bootstrap-tools-musl/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ derivation ({
langC = true;
langCC = true;
isGNU = true;
hardeningUnsupportedFlags = [ "fortify3" ];
hardeningUnsupportedFlags = [ "fortify3" "zerocallusedregs" ];
} // extraAttrs)
2 changes: 1 addition & 1 deletion pkgs/stdenv/linux/bootstrap-tools/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ derivation ({
langC = true;
langCC = true;
isGNU = true;
hardeningUnsupportedFlags = [ "fortify3" ];
hardeningUnsupportedFlags = [ "fortify3" "zerocallusedregs" ];
} // extraAttrs)
1 change: 1 addition & 0 deletions pkgs/top-level/release-attrpaths-superset.nix
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ let
pkgsStatic = true;
pkgsCross = true;
pkgsi686Linux = true;
pkgsExtraHardening = true;
};

# No release package attrname may have any of these at a component
Expand Down
13 changes: 13 additions & 0 deletions pkgs/top-level/stage.nix
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,19 @@ let
gcc.abi = "elfv2";
};
});

pkgsExtraHardening = nixpkgsFun {
overlays = [
(self': super': {
pkgsExtraHardening = super';
stdenv = super'.withDefaultHardeningFlags (
super'.stdenv.cc.defaultHardeningFlags ++ [
"zerocallusedregs"
]
) super'.stdenv;
})
] ++ overlays;
};
};

# The complete chain of package set builders, applied from top to bottom.
Expand Down