cc-wrapper: add zerocallusedregs hardening flag, add pkgsExtraHardening package set#274089
cc-wrapper: add zerocallusedregs hardening flag, add pkgsExtraHardening package set#274089risicle merged 3 commits intoNixOS:stagingfrom
zerocallusedregs hardening flag, add pkgsExtraHardening package set#274089Conversation
ea132b5 to
ac79e6b
Compare
|
Two questions:
Other than that, I love that feature! |
Nope.
Good question. Find out. (Would be good for more people than just me to have tried this...) But seeing as this looks destined for being enabled by default in the kernel (at some point), I would have expected to hear more noise about it if there were a significant impact. This is just the first of several new hardening flags I want to introduce in this release cycle, but am going to try and concentrate on one at a time. |
ac79e6b to
f8340db
Compare
|
Ok, I've nerd-sniped myself into implementing the per-platform I've explained more in the commit message, but this adds a new passthru attr, Tested successful bootstrap of |
RaitoBezarius
left a comment
There was a problem hiding this comment.
The internals look fairly reasonable, but I'm not expert on those parts (but I went through those rabbit holes quite often).
I would like the stdenv (IIRC) documentation to be updated though with the new per-platform flag.
|
Speaking of which #273840 could still do with a review. |
ee5e212 to
588a77a
Compare
|
@ofborg eval |
|
This pull request has been mentioned on NixOS Discourse. There might be relevant details there: https://discourse.nixos.org/t/prs-ready-for-review/3032/3151 |
|
@ofborg eval |
|
As mentioned on matrix: ofborg is failing because:
It seems like the only way to get around this is to open a new PR that isn't burdened by the hundreds of commit statuses that GitHub's API takes issue with :/ |
588a77a to
30d5312
Compare
|
@cole-h oh, could this be ofborg trying to extend its evaluation into |
30d5312 to
6eb44d4
Compare
6eb44d4 to
e79388d
Compare
this uses the value `used-gpr` which seems to be a commonly chosen value for general use
e79388d to
0c3f41a
Compare
|
Added some release notes (and rebased again in the vain hope of pleasing ofborg) |
|
I think you'll need to add EDIT: Yeah, that let ofborg continue to do its thing on my test PR: #282387 |
this package set can be used to trial new hardening flags or enable those which are still known to cause some problems
…lusedregs this allows a compiler derivation to provide a hardeningUnsupportedFlagsByTargetPlatform passthru attr that will be called with the targetPlatform to determine the unsupported hardening flags for that platform. we can do this because even though a clang compiler is multi-target by nature, cc-wrapper effectively fixes the target platform at wrapping time. otherwise we'd have to sniff the intended target at runtime, which wouldn't be fun at all. the advantage of using a new attribute instead of allowing hardeningUnsupportedFlags to optionally be a function is that hardeningUnsupportedFlags retains its simple overriding pattern for simple cases (i.e. `(prev.hardeningUnsupportedFlags or []) ++ [ "foo" ]` ) which will continue to work as long as the bottom-most function of hardeningUnsupportedFlagsByTargetPlatform falls back to hardeningUnsupportedFlags.
0c3f41a to
506ec38
Compare
Description of changes
More information on
-fzero-call-used-regs: https://www.jerkeby.se/newsletter/posts/rop-reduction-zero-call-user-regs/Short version: this hardening flag (available in gcc >= 11) reduces the number of ROP gadgets present in code by inserting instructions zeroing registers on function returns. The choice of
used-gpras a setting for regular use comes from the conclusions of the above article noting other projects making this choice.This flag is also available in clang >= 15 but only for x86_64 & aarch64, and our
hardeningUnsupportedFlagsmechanism isn't sophisticated enough to manage variation by target platform(we could trivially varyNot such a problem after all, implemented, see comment below 👇hardeningUnsupportedFlagsbased onstdenv.targetPlatform, but that might produce the wrong result when called as a cross-compiler). So for now I've had to disable it for clang. (PerhapshardeningUnsupportedFlagscould accept a function taking a platform? let's not get too diverted..)The more visible change in this PR is adding a new package set,
pkgsExtraHardening, which I'd like to use as a testing ground for new hardening flags or flags which are still known to cause some problems. Users of other "hardened" features may be interested in using this package set. The name is a little clunky - I was also consideringpkgsHarder(pkgsMeHarder? maybe not..)Have tested bootstrapping
pkgsExtraHardeningon macos 12 x86_64, nixos x86_64 (+pkgsi686Linux,pkgsLLVM,pkgsCross.aarch64-multiplatform...). A couple of months ago I built quite a lot of nixos x86_64 with this flag set and struggled to find anything that had a problem with it.Things done
nix.conf? (See Nix manual)sandbox = relaxedsandbox = truenix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD". Note: all changes have to be committed, also see nixpkgs-review usage./result/bin/)Add a 👍 reaction to pull requests you find important.