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

Compile kernel with retpoline GCC support #34383

Closed
clefru opened this issue Jan 29, 2018 · 12 comments
Closed

Compile kernel with retpoline GCC support #34383

clefru opened this issue Jan 29, 2018 · 12 comments
Labels
1.severity: security Issues which raise a security issue, or PRs that fix one
Milestone

Comments

@clefru
Copy link
Contributor

clefru commented Jan 29, 2018

Retpoline is a spectre v2 mitigation technique. GCC 7.3.0 was released last week with support for that. The kernel being the most vulnerable and privileged part should be compiled with retpoline support.

Requirements:

Switching kernel compilation to GCC 7 should get us there. At the moment we use gcc 6.4.0.

@fpletz fpletz added this to the 18.03 milestone Jan 29, 2018
@fpletz fpletz added the 1.severity: security Issues which raise a security issue, or PRs that fix one label Jan 29, 2018
@Baughn
Copy link
Contributor

Baughn commented Jan 29, 2018

Do we have benchmarks on how much this costs, worst-case?

I mean, it should absolutely be enabled by default, but there are workloads for which Spectre mitigation is not absolutely required. If the cost is high enough then a configuration flag (with suitably severe wording) might be warranted.

@clefru
Copy link
Contributor Author

clefru commented Jan 29, 2018

@Baughn: Please see https://www.phoronix.com/scan.php?page=article&item=linux-retpoline-benchmarks&num=1 for performance numbers, thanks to the awesomely hardworking Michael Larabel. The change references in the PR above should be equivalent to switching from the "Retpoline" numbers to the "Retpoline + GCC" numbers. Yes, the impact is significant.

@clefru
Copy link
Contributor Author

clefru commented Jan 29, 2018

Another impact assessment by RedHat.

@Baughn: The compiler upgrade triggers retpoline, and that's a surprise performance regression yes. However users can disable it setting "RETPOLINE n" in their kernelPlatform.kernelExtraConfig. I would not expose more knobs and argue that this sticks to the tradition that no other performance relevant kernel knobs are exposed as extra knobs, see common-config.nix.

On the fact that this is a surprise regression, I'd say that I take that over a surprise vulnerability any day, and that with the mechanisms above versatile users can disable it. The only question is whether we should document CONFIG_RETPOLINE more extensively but also the nixos manual is not making any recommendations on kernel configurations, so I am not sure where to put such any remarks. Release notes for 18.03 seem most appropriate. I have no good suggestion for a 17.09 backport though.

@Baughn
Copy link
Contributor

Baughn commented Jan 29, 2018

All right, fair enough.

I'm not going to argue it. If I were, however, than a counterargument might look like this: There is likely to be mitigations application-side as well as kernel-side, and having a single flag to disable all of them would be useful. On the flip side, I'm having trouble thinking of a single decent reason for doing so in e.g. Chrome.

vcunat added a commit that referenced this issue Feb 11, 2018
See #34383

On master the expressions have changed nontrivially,
so it's going to be separately done work.
(And we expect gcc7 by default for every package on master soon.)
@vcunat
Copy link
Member

vcunat commented Feb 11, 2018

Done in 17.09-small channel; I expect others will follow soon.

vcunat added a commit that referenced this issue Feb 11, 2018
I expect we will revert this after general upgrade to gcc7.
See #34383
@vcunat
Copy link
Member

vcunat commented Feb 11, 2018

Channel unstable-small updated as well. The big ones move slower as usual. Enjoy!

@vcunat vcunat closed this as completed Feb 11, 2018
@dotlambda
Copy link
Member

I rebuilt my system from latest master and spectre-meltdown-checker still reports as vulnerable:

CVE-2017-5715 [branch target injection] aka 'Spectre Variant 2'
* Mitigated according to the /sys interface:  NO  (kernel confirms your system is vulnerable)
* Mitigation 1
  * Kernel is compiled with IBRS/IBPB support:  NO 
  * Currently enabled features
    * IBRS enabled for Kernel space:  NO 
    * IBRS enabled for User space:  NO 
    * IBPB enabled:  NO 
* Mitigation 2
  * Kernel compiled with retpoline option:  YES 
  * Kernel compiled with a retpoline-aware compiler:  NO  (kernel reports minimal retpoline compilation)
  * Retpoline enabled:  NO 
> STATUS:  VULNERABLE  (Vulnerable: Minimal generic ASM retpoline)

Also, gcc6 still seems to be in the kernel closure:

nix-store -qR (nix-instantiate -A linuxPackages_latest.kernel) | grep gcc
warning: you did not specify '--add-root'; the result might be removed by the garbage collector
/nix/store/lpfviz52hzvcxpnqnpcskdlnp4s5zhwg-bootstrap-gcc-wrapper.drv
/nix/store/bdwv7d0f21wd2zy1rdwiy01jhwdrvx1b-bootstrap-gcc-wrapper.drv
/nix/store/3cwx0g5ws3grg6s56njhnzz6hb1gf065-bootstrap-gcc-wrapper.drv
/nix/store/vmvkv585yrm51y6clh2lsk7ha4rn8b26-gcc-6.4.0.tar.xz.drv
/nix/store/56z78wrfrfp9s0h3gg5qbpqywx5mwcki-gcc-6.4.0.drv
/nix/store/xi0z1sm3grbsxxp6jik4dmlj68y3dd9k-gcc-wrapper-6.4.0.drv
/nix/store/zknz7g8vxkrmli3v1six4rxjlmyz6j83-gcc-wrapper-6.4.0.drv
/nix/store/blg28s3z496s2gmmi6466i8kysyl007j-gcc-7.3.0.tar.xz.drv
/nix/store/wklrlabfqc1r2fdf5m67x4n3nxak7j93-gcc-7.3.0.drv
/nix/store/f523zrkm0l0pgmxr2s8ih4ssaxnlb1bi-gcc-wrapper-7.3.0.drv
/nix/store/gccwz3nyglhnjgh1gk6ssri2cbbfb67r-libunistring-0.9.8.tar.gz.drv

I think this is because of

make HOSTCC=${buildPackages.stdenv.cc.targetPrefix}gcc -C . O="$buildRoot" $kernelBaseConfig ARCH=$arch

@titanous
Copy link
Contributor

I also see the same thing:

$ cat /sys/devices/system/cpu/vulnerabilities/spectre_v2
Vulnerable: Minimal generic ASM retpoline

@vcunat
Copy link
Member

vcunat commented Feb 12, 2018

@dotlambda: thanks! The real problem is probably a few lines above what you pointed out. I didn't realize this difference from 17.09.

@vcunat vcunat reopened this Feb 12, 2018
@vcunat
Copy link
Member

vcunat commented Feb 12, 2018

Tested 17.09-small, to be sure:

$ cat /sys/devices/system/cpu/vulnerabilities/spectre_v2
Mitigation: Full generic retpoline

@vcunat
Copy link
Member

vcunat commented Feb 12, 2018

Our cross-compilation fixes got into the way, as kernel needs two compilers in general, due to also running self-compiled stuff during the build.

If you need a fix immediately, use #34882 – I tested it this time :-)

@vcunat
Copy link
Member

vcunat commented Feb 12, 2018

Re-tested the last version (as 17.09 above) and merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
1.severity: security Issues which raise a security issue, or PRs that fix one
Projects
None yet
Development

No branches or pull requests

6 participants