Skip to content

Commit a186eb2

Browse files
committed
Auto merge of #30859 - aliclark:musl-nx-issue, r=brson
This explicitly adds an option telling the linker on these platforms to make the stack and heap non-executable (should already be the case for Windows, and likely OS X). Without this option there is some risk of accidentally losing NX protection, as the linker will not enable NX if any of the binary's constituent objects don't contain the .note.GNU-stack header. We're not aware of any users who would want a binary with executable stack or heap, but in future this could be made possible by passing a flag to disable the protection, which would also help document the fact to the crate's users. Edit: older discussion of previous quickfix to add a .note.GNU-stack header to libunwind's assembly: Short term solution for issue #30824 to ensure that object files generated from assembler contain the .note.GNU-stack header. When this header is not present in any constituent object files, the linker refrains from making the stack NX in the final executable. Further actions: I'll try to get this change merged in with upstream too, and then update these instructions to just compile the fixed version. It seems a good idea to use issue #30824 or some other issue to add a test that similar security regressions can be automatically caught in future.
2 parents b694d1b + 8e36b3a commit a186eb2

File tree

5 files changed

+16
-0
lines changed

5 files changed

+16
-0
lines changed

src/librustc_back/target/dragonfly_base.rs

+3
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ pub fn opts() -> TargetOptions {
2424
// libraries which follow this flag. Thus, use it before
2525
// specifying libraries to link to.
2626
"-Wl,--as-needed".to_string(),
27+
28+
// Always enable NX protection when it is available
29+
"-Wl,-z,noexecstack".to_string(),
2730
),
2831
position_independent_executables: true,
2932
archive_format: "gnu".to_string(),

src/librustc_back/target/freebsd_base.rs

+4
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ pub fn opts() -> TargetOptions {
1717
dynamic_linking: true,
1818
executables: true,
1919
has_rpath: true,
20+
pre_link_args: vec![
21+
// Always enable NX protection when it is available
22+
"-Wl,-z,noexecstack".to_string(),
23+
],
2024
archive_format: "gnu".to_string(),
2125
exe_allocation_crate: super::maybe_jemalloc(),
2226

src/librustc_back/target/linux_base.rs

+3
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ pub fn opts() -> TargetOptions {
2626
// following libraries so we're sure to pass it as one of the first
2727
// arguments.
2828
"-Wl,--as-needed".to_string(),
29+
30+
// Always enable NX protection when it is available
31+
"-Wl,-z,noexecstack".to_string(),
2932
],
3033
position_independent_executables: true,
3134
archive_format: "gnu".to_string(),

src/librustc_back/target/netbsd_base.rs

+3
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ pub fn opts() -> TargetOptions {
2424
// libraries which follow this flag. Thus, use it before
2525
// specifying libraries to link to.
2626
"-Wl,--as-needed".to_string(),
27+
28+
// Always enable NX protection when it is available
29+
"-Wl,-z,noexecstack".to_string(),
2730
),
2831
position_independent_executables: true,
2932
archive_format: "gnu".to_string(),

src/librustc_back/target/openbsd_base.rs

+3
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ pub fn opts() -> TargetOptions {
2424
// libraries which follow this flag. Thus, use it before
2525
// specifying libraries to link to.
2626
"-Wl,--as-needed".to_string(),
27+
28+
// Always enable NX protection when it is available
29+
"-Wl,-z,noexecstack".to_string(),
2730
),
2831
position_independent_executables: true,
2932
archive_format: "gnu".to_string(),

0 commit comments

Comments
 (0)