Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Port from 5.0: Fix relro, now, and PIE for Libraries#43036

Merged
Anipik merged 5 commits intodotnet:release/3.1from
ivdiazsa:Port_DockF
Jun 5, 2021
Merged

Port from 5.0: Fix relro, now, and PIE for Libraries#43036
Anipik merged 5 commits intodotnet:release/3.1from
ivdiazsa:Port_DockF

Conversation

@ivdiazsa
Copy link

@ivdiazsa ivdiazsa commented Feb 17, 2021

Port Description

This is a direct port from one part of PR 685 in the runtime repo. This one was added during .NET Core 5.0 development but there is a customer need to also have it in the .NET Core 3.1 release. The other part is in the core-setup repo, PR 9125.

This change adds the missing -z,relro and -z,now compile options, as well as the position independent related code and -pie linker option to the Native Unix libraries. Additionally, some operating systems require other flags, which were also added:

  • FreeBSD: -fuse-ld=lld
  • Darwin: -Wl, -bind_at_load

Customer Impact

Having these flags enabled provides the built binaries with an additional layer of security, which has become a necessary requirement for some compliance checks, as well as safer applications overall. This port was requested by teams in Azure.

Regression

This was not a regression.

Testing

The checksec tool was used to verify the executables and shared objects had been indeed built with PIE and Full RELRO enabled.

Risk

The risk of this is pretty low, since it's been well tested in the current main branch, as well as .NET 5.0 releases.

@ivdiazsa ivdiazsa requested review from janvorli and mangod9 February 17, 2021 02:24
@ivdiazsa ivdiazsa marked this pull request as draft February 19, 2021 01:55
@ivdiazsa ivdiazsa closed this Mar 29, 2021
@ivdiazsa ivdiazsa reopened this Mar 29, 2021
@ivdiazsa ivdiazsa marked this pull request as ready for review March 29, 2021 18:14
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-bind_at_load")
else (CMAKE_SYSTEM_NAME STREQUAL Darwin)
add_compile_options($<$<COMPILE_LANGUAGE:ASM>:-Wa,--noexecstack>)
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--build-id=sha1 -Wl,-z,relro,-z,now")
Copy link
Member

Choose a reason for hiding this comment

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

A nit - wrong indentation

add_definitions(-D_BSD_SOURCE) # required for getline
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -fuse-ld=lld -Xlinker --build-id=sha1")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fuse-ld=lld -Xlinker --build-id=sha1")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fuse-ld=lld")
Copy link
Member

Choose a reason for hiding this comment

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

I've just noticed we are missing the

set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -fuse-ld=lld")

here

Copy link
Member

@janvorli janvorli left a comment

Choose a reason for hiding this comment

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

LGTM, thank you!

@danmoseley
Copy link
Member

This will need the shiproom template?

@mangod9
Copy link
Member

mangod9 commented Apr 19, 2021

yeah @ivdiazsa was going to follow up in the .net core ASK mode channel and create the template.

@aik-jahoda
Copy link

Is this PR targeting current release? If yes we need approve and Servicing-approved tag.

@janvorli janvorli added the Servicing-consider Issue for next servicing release review label May 6, 2021
@janvorli janvorli added this to the 3.1.x milestone May 6, 2021
Copy link
Member

@jeffschwMSFT jeffschwMSFT left a comment

Choose a reason for hiding this comment

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

Approved. I will take for consideration in 3.1.x

cc @blowdart and @GrabYourPitchforks

@leecow leecow modified the milestones: 3.1.x, 3.1.17 May 11, 2021
@leecow leecow added Servicing-approved Approved for servicing release and removed Servicing-consider Issue for next servicing release review labels May 11, 2021
@Anipik Anipik merged commit b2c78d8 into dotnet:release/3.1 Jun 5, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Servicing-approved Approved for servicing release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants