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

Build generates PIC even for static library #4

Open
abdes opened this issue Aug 26, 2022 · 3 comments
Open

Build generates PIC even for static library #4

abdes opened this issue Aug 26, 2022 · 3 comments
Assignees

Comments

@abdes
Copy link
Owner

abdes commented Aug 26, 2022

This is a remanent from the old cmake file.

For static lib build, and given that we do not use the same intermediary object files for shared and static, the archive library should be built without -fPIC.

@abdes abdes closed this as completed in 476364c Aug 26, 2022
@noloader
Copy link
Collaborator

noloader commented Aug 26, 2022

I think the sharp edge here is a wrapper DLL or shared object. For this use case, this could happen:

  • CMake builds libcryptopp.a without -fPIC
  • User creates a shared object, uses -fPIC
  • User shared object links to libcryptopp.a

The user will experience relocation errors when linking their shared object with libcryptopp.a.

I think the same could happen if the user built an executable linked against libcryptopp.a, and used -fPIC or -fPIE for position independent code (Unix & Linux) or ASLR (Windows):

  • CMake builds libcryptopp.a without -fPIC
  • User creates a program, uses -fPIC or -fPIE
  • User program links to libcryptopp.a

See Wrapper DLL on the Crypto++ wiki. And see https://www.google.com/search?q=ld+relocation+error+'-fPIC' (and the slew of answers that say "rebuild with -fPIC").

@noloader
Copy link
Collaborator

It is probably worth mentioning...

used -fPIC or -fPIE for position independent code (Unix & Linux) or ASLR (Windows)

ASLR was introduced by Microsoft in Windows XP. Utilizing ASLR has been part of the secure coding guide since at least the year 2000.

Position independent code has been part of Unix & Linux for years also. It became a recommendation around 2010 for secure coding Unix & Linux. In 2012 Android adopted it.

It is very unfortunate CMake does not enable it by default given it has been a standard option for over 10 years. Code that does not use position independent code or ASLR will fail a security audit nowadays.

@abdes abdes reopened this Aug 26, 2022
@abdes
Copy link
Owner Author

abdes commented Aug 26, 2022

Hmm… from a hardening point of view it makes sense.

Anyway, the only reason I thought it should be removed is that some distros require that archive libs should be built with no -fPIC.

I will make a specific test case for using wrapper DLL and a test case for -fPIE executable and document the scenarios clearly in the code if we decide to keep/remove -fPIC/-fPIE.

@abdes abdes self-assigned this Aug 26, 2022
abdes added a commit that referenced this issue Aug 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants