Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cc-wrapper: disable incompatible hardening options in cpu bit size cross #335023

Open
wants to merge 2 commits into
base: staging
Choose a base branch
from

Conversation

RossComputerGuy
Copy link
Member

@RossComputerGuy RossComputerGuy commented Aug 16, 2024

Description of changes

As the title says, this disables incompatible hardening options when cross compiling between the same ISA but different bit size. This prevents the issue of the zerocallregs hardening option from being used when using clang to build Linux and Linux is building for aarch64 but builds vdso32.

@K900 initially suggested the idea that we prevent that behavior inside of the cc-wrapper instead of hardcoding derivations to disable the zerocallregs hardening option altogether inside of the Linux kernel derivation.

Can be tested by building pkgsLLVM.linux on aarch64-linux.

Things done

  • Built on platform(s)
    • x86_64-linux
    • aarch64-linux
    • x86_64-darwin
    • aarch64-darwin
  • For non-Linux: Is sandboxing enabled in nix.conf? (See Nix manual)
    • sandbox = relaxed
    • sandbox = true
  • Tested, as applicable:
  • Tested compilation of all packages that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD". Note: all changes have to be committed, also see nixpkgs-review usage
  • Tested basic functionality of all binary files (usually in ./result/bin/)
  • 24.11 Release Notes (or backporting 23.11 and 24.05 Release notes)
    • (Package updates) Added a release notes entry if the change is major or breaking
    • (Module updates) Added a release notes entry if the change is significant
    • (Module addition) Added a release notes entry if adding a new NixOS module
  • Fits CONTRIBUTING.md.

Add a 👍 reaction to pull requests you find important.

@ofborg ofborg bot added the 6.topic: cross-compilation Building packages on a different platform than they will be used on label Aug 16, 2024
@github-actions github-actions bot added the 6.topic: lib The Nixpkgs function library label Aug 16, 2024
@RossComputerGuy RossComputerGuy force-pushed the feat/cc-wrapper/no-32bit-hardending branch from 0344866 to 32cd5ee Compare August 16, 2024 05:04
@RossComputerGuy
Copy link
Member Author

@ofborg eval

@RossComputerGuy RossComputerGuy force-pushed the feat/cc-wrapper/no-32bit-hardending branch from 32cd5ee to 15546e4 Compare August 16, 2024 06:28
@RossComputerGuy
Copy link
Member Author

@ofborg eval

@RossComputerGuy RossComputerGuy force-pushed the feat/cc-wrapper/no-32bit-hardending branch 4 times, most recently from c32e6ae to 11284d6 Compare August 16, 2024 19:41
@RossComputerGuy RossComputerGuy marked this pull request as ready for review August 16, 2024 22:45
@RossComputerGuy RossComputerGuy force-pushed the feat/cc-wrapper/no-32bit-hardending branch from 11284d6 to 388a28d Compare August 16, 2024 23:57
@emilazy
Copy link
Member

emilazy commented Aug 25, 2024

Nice! Would this let us drop some of the various hardeningDisable = [ "zerocallusedregs" ] instances that have popped up across the tree? (e.g. Rust, systemd)

@RossComputerGuy
Copy link
Member Author

Likely, it'll probably a more reasonable change to use hardeningUnsupportedFlagsByTargetPlatform in more cases because of nuisances between different packages.

@alyssais
Copy link
Member

I think it's important @Ericson2314 has a look at the lib changes before this goes in. I'm not sure myself whether it makes sense to try to map between 64-bit and 32-bit triples, because there could be multiple sensible options.

@RossComputerGuy
Copy link
Member Author

Yeah, the problem here is we have to detect when clang is using the 32 bit or 64 bit triple. I figured it was easier to use lib.systems to help with that and then pulling only the arch out and matching based on that inside cc-wrapper. More feedback on this implementation would be great.

@RossComputerGuy RossComputerGuy force-pushed the feat/cc-wrapper/no-32bit-hardending branch from 388a28d to a10ec98 Compare August 26, 2024 04:13
@tomberek
Copy link
Contributor

Currently blocked on review. (@Ericson2314 , can you take a look?)

@RossComputerGuy RossComputerGuy force-pushed the feat/cc-wrapper/no-32bit-hardending branch from a10ec98 to 547ffcb Compare October 12, 2024 00:43
@FliegendeWurst FliegendeWurst added the needs_reviewer (old Marvin label, do not use) label Nov 12, 2024
Copy link
Member

@emilazy emilazy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After further discussion on Matrix, I don’t believe this is the right approach to the problem. The fundamental issue is that we are setting default hardening flags for a different host platform than we’re compiling for. This is essentially a cross‐compilation scenario and so #354622 would be a step in the right direction. In this case, it wouldn’t fix it, because we’re using the same wrapped compiler to build for two different architectures. Unfortunately, that is fundamentally broken right now in general. Maintaining a mapping between 64‐ and 32‐bit architectures is also not really something that can make sense in general. I believe the appropriate ways forward are:

  • Use an unwrapped compiler to compile the VDSO32 for now; this would work with Clang since it’s natively multi‐target, and with GCC since it’s effectively “dual‐target”. I think this is the most expedient short‐term fix.

  • Make it easier to re‐wrap our compilers for different architectures, and use a re‐wrapped compiler.

  • Rework our wrappers to work natively multi‐target. This would be the best option but would be a large undertaking.

@wegank wegank added the 2.status: merge conflict This PR has merge conflicts with the target branch label Dec 10, 2024
@SigmaSquadron SigmaSquadron removed the needs_reviewer (old Marvin label, do not use) label Jan 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
2.status: merge conflict This PR has merge conflicts with the target branch 6.topic: cross-compilation Building packages on a different platform than they will be used on 6.topic: lib The Nixpkgs function library 10.rebuild-darwin: 501+ 10.rebuild-darwin: 5001+ 10.rebuild-darwin-stdenv This PR causes stdenv to rebuild 10.rebuild-linux: 501+ 10.rebuild-linux: 5001+ 10.rebuild-linux-stdenv This PR causes stdenv to rebuild
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants