diff options
| -rw-r--r-- | DESIGN | 9 | ||||
| -rw-r--r-- | Makefile | 8 |
2 files changed, 12 insertions, 5 deletions
| @@ -116,13 +116,20 @@ Build hardening the shipped binary | |||
| 116 | ---------------------------------- | 116 | ---------------------------------- |
| 117 | 117 | ||
| 118 | The production and debug binaries carry -fstack-protector-strong, PIE and | 118 | The production and debug binaries carry -fstack-protector-strong, PIE and |
| 119 | _FORTIFY_SOURCE=2; a GNU-style linker also gets full RELRO. Measured cost on | 119 | _FORTIFY_SOURCE=2; every linker but Apple's also gets full RELRO (-z relro,-z now). Measured cost on |
| 120 | the announce hot path is 300 to 305 nanoseconds, under two per cent, and the | 120 | the announce hot path is 300 to 305 nanoseconds, under two per cent, and the |
| 121 | individual flags sit inside the run-to-run noise: add_peer has few stack | 121 | individual flags sit inside the run-to-run noise: add_peer has few stack |
| 122 | buffers, most buffer sizes are known at compile time so FORTIFY emits no | 122 | buffers, most buffer sizes are known at compile time so FORTIFY emits no |
| 123 | runtime check, and PIE on arm64 is almost free. On x86-64 PIE costs a little | 123 | runtime check, and PIE on arm64 is almost free. On x86-64 PIE costs a little |
| 124 | more. End to end it is invisible, since a UDP announce is mostly kernel time. | 124 | more. End to end it is invisible, since a UDP announce is mostly kernel time. |
| 125 | 125 | ||
| 126 | RELRO is gated on the operating system because Apple's linker rejects -z. The | ||
| 127 | branch runs in the shell through a != assignment, the one form both bmake and | ||
| 128 | GNU make 4 accept; $(shell) is GNU only and GNU make 3.81, which stock macOS | ||
| 129 | ships, has neither. On that old make the != line is inert and leaves RELRO | ||
| 130 | empty, which is the right answer for macOS anyway, so every platform resolves | ||
| 131 | correctly without a make conditional. | ||
| 132 | |||
| 126 | The flags are not in OT_CFLAGS, so the sanitizer test builds do not inherit | 133 | The flags are not in OT_CFLAGS, so the sanitizer test builds do not inherit |
| 127 | them. AddressSanitizer checks harder than FORTIFY does, and the two clash on | 134 | them. AddressSanitizer checks harder than FORTIFY does, and the two clash on |
| 128 | FreeBSD, where a FORTIFY plus ASan build aborted a multi hash scrape that the | 135 | FreeBSD, where a FORTIFY plus ASan build aborted a multi hash scrape that the |
| @@ -46,9 +46,9 @@ OT_CFLAGS+=-Wall -Wextra -Wwrite-strings -pipe -pthread | |||
| 46 | 46 | ||
| 47 | HARDENING=-fstack-protector-strong -fPIE -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 | 47 | HARDENING=-fstack-protector-strong -fPIE -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 |
| 48 | HARDENING_LD=-pie | 48 | HARDENING_LD=-pie |
| 49 | # Full RELRO is free at runtime and makes the GOT read-only, but Apple's linker | 49 | # Full RELRO on every linker that takes it, which is all but Apple's. See DESIGN. |
| 50 | # does not accept -z, so enable it for the GNU-style linkers (Linux, the BSDs): | 50 | RELRO_LD!= case `uname -s` in Darwin) ;; *) printf %s -Wl,-z,relro,-z,now ;; esac |
| 51 | #HARDENING_LD+=-Wl,-z,relro,-z,now | 51 | HARDENING_LD+=$(RELRO_LD) |
| 52 | OT_LDFLAGS+=-pthread | 52 | OT_LDFLAGS+=-pthread |
| 53 | 53 | ||
| 54 | OPTS_debug=-D_DEBUG -g -ggdb | 54 | OPTS_debug=-D_DEBUG -g -ggdb |
| @@ -78,7 +78,7 @@ $(BINARY).debug: $(SOURCES) $(HEADERS) $(BUILDDEPS) | |||
| 78 | $(CC) -o $@ $(OPTS_debug) $(COMPILE) $(HARDENING) $(SOURCES) $(LINK) $(HARDENING_LD) | 78 | $(CC) -o $@ $(OPTS_debug) $(COMPILE) $(HARDENING) $(SOURCES) $(LINK) $(HARDENING_LD) |
| 79 | 79 | ||
| 80 | $(BUILDSTAMP): FORCE | 80 | $(BUILDSTAMP): FORCE |
| 81 | @echo "$(CFLAGS) $(COMPILE) $(LINK)" | cmp -s - $@ 2>/dev/null || echo "$(CFLAGS) $(COMPILE) $(LINK)" > $@ | 81 | @echo "$(CFLAGS) $(COMPILE) $(HARDENING) $(LINK) $(HARDENING_LD)" | cmp -s - $@ 2>/dev/null || echo "$(CFLAGS) $(COMPILE) $(HARDENING) $(LINK) $(HARDENING_LD)" > $@ |
| 82 | 82 | ||
| 83 | clean: | 83 | clean: |
| 84 | rm -rf $(BINARIES) $(BINARIES:=.dSYM) $(BUILDSTAMP) *.o *~ src/*.o src/*~ | 84 | rm -rf $(BINARIES) $(BINARIES:=.dSYM) $(BUILDSTAMP) *.o *~ src/*.o src/*~ |
