Skip to content

Harden shared library with full RELRO and immediate binding - #320

Merged
jim-mlodgenski merged 1 commit into
mainfrom
harden/relro-now
Aug 19, 2026
Merged

Harden shared library with full RELRO and immediate binding#320
jim-mlodgenski merged 1 commit into
mainfrom
harden/relro-now

Conversation

@jim-mlodgenski

Copy link
Copy Markdown
Contributor

What

Add -Wl,-z,relro,-z,now to PG_LDFLAGS so the built pg_tle.so gets full RELRO (GOT read-only after load) and immediate binding (all symbols resolved at load time). This makes the GOT a non-writable target, mitigating GOT-overwrite exploitation techniques.

Guarded to Linux, since -z ... is a GNU-ld/lld option that Apple's ld rejects:

ifeq ($(shell uname -s),Linux)
PG_LDFLAGS += -Wl,-z,relro,-z,now
endif

Verification

Built against PG 17 and confirmed the flags land in the .so:

$ readelf -l pg_tle.so | grep RELRO
  GNU_RELRO      0x...
$ readelf -d pg_tle.so | grep -iE 'BIND_NOW|NOW'
 0x...1e (FLAGS)    BIND_NOW
 0x...fb (FLAGS_1)  Flags: NOW

Runtime behavior is unchanged; this is link-time hardening only.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

Add -Wl,-z,relro,-z,now (Linux-only guard) so the GOT is read-only
after load and all symbols bind at load time. Verified via readelf:
GNU_RELRO segment + BIND_NOW present in pg_tle.so.
@jim-mlodgenski
jim-mlodgenski merged commit 2f4b7b3 into main Aug 19, 2026
18 checks passed
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

Successfully merging this pull request may close these issues.

1 participant