Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 036620a

Browse files
besser82solardiz
authored andcommittedJan 20, 2025·
Makefile: Apply minimum hardening to libs and applications.
This enables stack-protector-strong with _FORTIFY_SOURCE=2, and the following linker flags: -Wl,-z,defs: Disallows undefined symbols at link-time. -Wl,-z,relro: Relocation Read-Only protects the Global Offset Table (GOT) in ELF binaries from being overwritten. -Wl,-z,now: Tell the dynamic linker to resolve all symbols when the program is started, or when the shared library is loaded. Signed-off-by: Björn Esser <besser82@fedoraproject.org>
1 parent c96fded commit 036620a

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed
 

‎ChangeLog

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,17 @@
88
proceeding.
99
* progs/tcb_unconvert.c (main): Likewise.
1010

11+
Makefile: Apply minimum hardening to libs and applications.
12+
This enables stack-protector-strong with _FORTIFY_SOURCE=2, and the
13+
following linker flags:
14+
-Wl,-z,defs: Disallows undefined symbols at link-time.
15+
-Wl,-z,relro: Relocation Read-Only protects the Global Offset Table
16+
(GOT) in ELF binaries from being overwritten.
17+
-Wl,-z,now: Tell the dynamic linker to resolve all symbols when the
18+
program is started, or when the shared library is loaded.
19+
* Make.defs: Define HARDENING_(C|LD)FLAGS, and prepend to coresponding
20+
CFLAGS or LDFLAGS variable.
21+
1122
2024-12-20 Björn Esser <besser82 at fedoraproject.org>
1223

1324
libnss_tcb: Disallow potentially-malicious user names in getspnam(3).

‎Make.defs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ OMIT_PAM_MODULE =
1313
# May be needed when compiling to use with OpenPAM.
1414
PAM_SO_SUFFIX =
1515

16+
# Flags for hardening.
17+
HARDENING_CFLAGS = -fstack-protector-strong -D_FORTIFY_SOURCE=2
18+
HARDENING_LDFLAGS = -Wl,-z,defs -Wl,-z,relro -Wl,-z,now
19+
1620
DBGFLAG = #-ggdb
1721
ifndef CFLAGS
1822
CFLAGS = -O2
@@ -23,7 +27,8 @@ ifneq ($(WERROR),)
2327
CFLAGS += -Werror
2428
endif
2529
#CFLAGS += -DFAIL_RECORD
26-
LDFLAGS += $(DBGFLAG) -L../libs
30+
CFLAGS := $(HARDENING_CFLAGS) $(CFLAGS)
31+
LDFLAGS := $(HARDENING_LDFLAGS) $(LDFLAGS) $(DBGFLAG) -L../libs
2732

2833
PREFIX = /usr
2934
SBINDIR = /sbin

0 commit comments

Comments
 (0)
Please sign in to comment.