Skip to content

Consider passing hardening ELF flags to LDFAGS in Makefile #1322

@Dentrax

Description

@Dentrax

We need to ensure that the linker resolves all dynamically linked functions at the beginning of the execution, and then makes the GOT read-only. This technique is called RELRO and ensures that the GOT cannot be overwritten in vulnerable ELF binaries. 1

gcc -g -O0 -Wl,-z,relro,-z,now -o <binary_name> <source_code>

In Go equivalent:

-extldflags=-zrelro -extldflags=-znow

An example implementation to Vault: https://github.com/hashicorp/vault-csi-provider/pull/143/files by @developer-guy

- trimpath increases build reproducibility. Per default full file paths are added to the go binary so two users will very likely have different binaries build even though the code is the same.
- w No DWARF (reduces binary size)
- s No symbol table (even less binary size)
- znow and zrelro Hardening, adds runtime costs.

Footnotes

  1. https://www.redhat.com/en/blog/hardening-elf-binaries-using-relocation-read-only-relro

Metadata

Metadata

Assignees

No one assigned

    Labels

    featureNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions