Skip to content

Mitigate Stack Clash #26750

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

Merged
merged 5 commits into from
Jun 21, 2017
Merged

Conversation

fpletz
Copy link
Member

@fpletz fpletz commented Jun 21, 2017

This fixes the Stack Clash issue rediscovered by Qualys. See https://www.qualys.com/2017/06/19/stack-clash/stack-clash.txt for more information on the topic, specifically section III.

We don't have the proposed kernel mitigation available because it is a Grsecurity feature which we don't support anymore. Other distributions like Gentoo Hardened and Arch already have -fstack-check enabled by default.

See the Gentoo page on Stack Clash for more information on this solution: https://wiki.gentoo.org/wiki/Hardened/Gentoo_Hardened_and_Stack_Clash

This unfortunately doesn't apply to clang because -fstack-check is a noop there. Note that the GCC implementation also has problems that could be exploited to circumvent these checks but it is still better than keeping it disabled.

This PR also includes fixes for stack clash related problems in the Linux kernel, glibc and exim which were identified by Qualys.

Status of this PR

I'm in the process of recompiling and testing a few packages. As this is a security-sensitive issue and a mass rebuild, I opened the PR as soon as possible to let others provide feedback on this change.

This will be merged to staging. Everything except the cc-wrapper changes will be cherry-picked to release-17.03.

@fpletz fpletz added 1.severity: mass-rebuild This PR causes a large number of packages to rebuild 1.severity: security Issues which raise a security issue, or PRs that fix one 2.status: work-in-progress This PR isn't done labels Jun 21, 2017
@@ -50,7 +50,11 @@ if [[ ! $hardeningDisable =~ "all" ]]; then
if [[ -n "$NIX_DEBUG" ]]; then echo HARDENING: enabling bindnow >&2; fi
hardeningLDFlags+=('-z' 'now')
;;
*)
stackcheck)
if [[ -n "$NIX_DEBUG" ]]; then echo HARDENING: enabling bindnow >&2; fi
Copy link
Contributor

Choose a reason for hiding this comment

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

"enabling bindnow" is copied from above, I guess?

@fpletz fpletz force-pushed the fix/stack-clash-hardening branch 2 times, most recently from aed00a5 to 4bedc3e Compare June 21, 2017 19:32
@fpletz fpletz changed the title cc-wrapper: add stackcheck hardening (Stack Clash) Mitigate Stack Clash Jun 21, 2017
@fpletz
Copy link
Member Author

fpletz commented Jun 21, 2017

I added patches to mitigate Stack Clash in the kernel, exim & glibc. This is what Debian is doing in unstable and stable. The cc-wrapper change should IMHO be tested on master first and released with 17.09.

cc @grahamc @domenkozar @globin

@grahamc
Copy link
Member

grahamc commented Jun 21, 2017

I'm surprised you're saying the cc-wrapper won't be picked. Why not?

@fpletz
Copy link
Member Author

fpletz commented Jun 21, 2017

@volth The patch does not apply cleanly on 4.4. I decided to only patch the default kernels for 17.03 and master for now. You can take a shot at it if you want. :)

@grahamc The stackcheck hardening could potentially break software. Debian only updated the 3 mentioned packages. The fix in the kernel also mitigates the problem for all userspace applications without stackcheck hardening. Debian doesn't add -fstack-check to their build flags so this should be safe for 17.03 for the time being. If you feel we should backport this, I'm not strictly against it. Just thought it would make sense. :)

fpletz added 2 commits June 22, 2017 00:41
This fixes the Stack Clash issue rediscovered by Qualys. See
https://www.qualys.com/2017/06/19/stack-clash/stack-clash.txt
for more information on the topic, specifically section III.

We don't have the kernel mitigation available because it is a Grsecurity
feature which we don't support anymore. Other distributions like Gentoo
Hardened and Arch already have `-fstack-check` enabled by default.

See the Gentoo page on Stack Clash for more information on this solution:
https://wiki.gentoo.org/wiki/Hardened/Gentoo_Hardened_and_Stack_Clash

This unfortunately doesn't apply to clang because `-fstack-check` is a
noop there. Note that the GCC implementation also has problems that could
be exploited to circumvent these checks but it is still better than
keeping it disabled.
@fpletz fpletz force-pushed the fix/stack-clash-hardening branch from 1d3fb84 to ed22de0 Compare June 21, 2017 22:42
@fpletz fpletz changed the base branch from master to staging June 21, 2017 22:42
@fpletz fpletz force-pushed the fix/stack-clash-hardening branch from ed22de0 to 2296bf3 Compare June 21, 2017 22:44
@fpletz
Copy link
Member Author

fpletz commented Jun 21, 2017

Merged master into staging and rebased this PR to staging. My preliminary tests look good and I'd like to merge this to staging in a few hours.

@fpletz fpletz removed the 2.status: work-in-progress This PR isn't done label Jun 21, 2017
@fpletz
Copy link
Member Author

fpletz commented Jun 21, 2017

Did another rebuild with the changes on staging. All green. Let's do this. :)

@fpletz fpletz merged commit 196bf8b into NixOS:staging Jun 21, 2017
@fpletz fpletz deleted the fix/stack-clash-hardening branch June 21, 2017 23:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
1.severity: mass-rebuild This PR causes a large number of packages to rebuild 1.severity: security Issues which raise a security issue, or PRs that fix one
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants