-
Notifications
You must be signed in to change notification settings - Fork 28
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
restraint binaries are not built with relro/pie/bind_now #255
Comments
From the output of command Hardened: restraintd: FAIL: pie test because not built with '-Wl,-pie' (gcc/clang) or '-buildmode pie' (go)
Hardened: restraintd: FAIL: bind-now test because not linked with -Wl,-z,now
Hardened: restraintd: FAIL: cf-protection test because .note.gnu.property section did not contain the necessary flags
Hardened: restraintd: Overall: FAIL.
...<snip>... Looks we should add |
A manual test is done on x86_64 (Fedora 36). That is, 01 - patchdiff --git a/src/Makefile b/src/Makefile
index e933843..a27d0bc 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -33,6 +33,19 @@ CFLAGS += -Wall -Werror -std=c99 $(shell pkg-config --cflags $(PACKAGES))
# Keep this until we have Glib 2.68 in third-party module
CFLAGS += -Wno-deprecated-declarations
+# XXX: Support to build binaries relro/pie/bind_now. For more,
+# please refer to:
+# https://github.com/restraint-harness/restraint/issues/255
+CFLAGS += -fshort-enums
+CFLAGS += -fcf-protection=full
+CFLAGS += -fplugin=annobin
+CFLAGS += -fstack-protector-strong
+CFLAGS += -D_FORTIFY_SOURCE=3
+CFLAGS += -D_GLIBCXX_ASSERTIONS
+CFLAGS += -Wl,-pie -fpie
+LDFLAGS += -Wl,-z,now
+LDFLAGS += -pie
+
ifeq ($(STATIC), 1)
# The LIBS list must start with static then followed with dynamic.
# DYNAMICLIBS must be stripped out of THIRDPTYLIBS leaving 02 - buildLet's take a look at the building log after CFLAGS and LDFLAGS are updated, $ make restraint
gcc -g -O2 -Wall -Werror -std=c99 -I/usr/include/glib-2.0 -I/usr/lib64/glib-2.0/include -I/usr/include/sysprof-4 -I/usr/include/libmount -I/usr/include/blkid -I/usr/include/gio-unix-2.0 -I/usr/include/json-c -I/usr/include/libsoup-2.4 -pthread -I/usr/include/libxml2 -Wno-deprecated-declarations -fshort-enums -fcf-protection=full -fplugin=annobin -fstack-protector-strong -D_FORTIFY_SOURCE=3 -D_GLIBCXX_ASSERTIONS -Wl,-pie -fpie -c -o client.o client.c
gcc -g -O2 -Wall -Werror -std=c99 -I/usr/include/glib-2.0 -I/usr/lib64/glib-2.0/include -I/usr/include/sysprof-4 -I/usr/include/libmount -I/usr/include/blkid -I/usr/include/gio-unix-2.0 -I/usr/include/json-c -I/usr/include/libsoup-2.4 -pthread -I/usr/include/libxml2 -Wno-deprecated-declarations -fshort-enums -fcf-protection=full -fplugin=annobin -fstack-protector-strong -D_FORTIFY_SOURCE=3 -D_GLIBCXX_ASSERTIONS -Wl,-pie -fpie -c -o errors.o errors.c
gcc -g -O2 -Wall -Werror -std=c99 -I/usr/include/glib-2.0 -I/usr/lib64/glib-2.0/include -I/usr/include/sysprof-4 -I/usr/include/libmount -I/usr/include/blkid -I/usr/include/gio-unix-2.0 -I/usr/include/json-c -I/usr/include/libsoup-2.4 -pthread -I/usr/include/libxml2 -Wno-deprecated-declarations -fshort-enums -fcf-protection=full -fplugin=annobin -fstack-protector-strong -D_FORTIFY_SOURCE=3 -D_GLIBCXX_ASSERTIONS -Wl,-pie -fpie -c -o xml.o xml.c
gcc -g -O2 -Wall -Werror -std=c99 -I/usr/include/glib-2.0 -I/usr/lib64/glib-2.0/include -I/usr/include/sysprof-4 -I/usr/include/libmount -I/usr/include/blkid -I/usr/include/gio-unix-2.0 -I/usr/include/json-c -I/usr/include/libsoup-2.4 -pthread -I/usr/include/libxml2 -Wno-deprecated-declarations -fshort-enums -fcf-protection=full -fplugin=annobin -fstack-protector-strong -D_FORTIFY_SOURCE=3 -D_GLIBCXX_ASSERTIONS -Wl,-pie -fpie -c -o utils.o utils.c
gcc -g -O2 -Wall -Werror -std=c99 -I/usr/include/glib-2.0 -I/usr/lib64/glib-2.0/include -I/usr/include/sysprof-4 -I/usr/include/libmount -I/usr/include/blkid -I/usr/include/gio-unix-2.0 -I/usr/include/json-c -I/usr/include/libsoup-2.4 -pthread -I/usr/include/libxml2 -Wno-deprecated-declarations -fshort-enums -fcf-protection=full -fplugin=annobin -fstack-protector-strong -D_FORTIFY_SOURCE=3 -D_GLIBCXX_ASSERTIONS -Wl,-pie -fpie -c -o process.o process.c
gcc -g -O2 -Wall -Werror -std=c99 -I/usr/include/glib-2.0 -I/usr/lib64/glib-2.0/include -I/usr/include/sysprof-4 -I/usr/include/libmount -I/usr/include/blkid -I/usr/include/gio-unix-2.0 -I/usr/include/json-c -I/usr/include/libsoup-2.4 -pthread -I/usr/include/libxml2 -Wno-deprecated-declarations -fshort-enums -fcf-protection=full -fplugin=annobin -fstack-protector-strong -D_FORTIFY_SOURCE=3 -D_GLIBCXX_ASSERTIONS -Wl,-pie -fpie -c -o restraint_forkpty.o restraint_forkpty.c
gcc -Wl,-z,now -pie -o restraint client.o errors.o xml.o utils.o process.o restraint_forkpty.o -ljson-c -larchive -lcurl -lsoup-2.4 -Wl,--export-dynamic -lgmodule-2.0 -pthread -lglib-2.0 -lgio-2.0 -lgobject-2.0 -lglib-2.0 -lxml2 -lutil -pthread 03 - checkNow we can check the restraint binaries via $ annocheck --verbose restraint
annocheck: Version 10.93.
Hardened: restraint: info: no matching profile found.
Hardened: restraint: PASS: pie test
Hardened: restraint: PASS: optimization test
Hardened: restraint: PASS: pic test
Hardened: restraint: PASS: stack-prot test
Hardened: restraint: PASS: cf-protection test because correct flags found in .note.gnu.property note
Hardened: restraint: PASS: writable-got test
Hardened: restraint: PASS: dynamic-segment test
Hardened: restraint: PASS: bind-now test
Hardened: restraint: PASS: stack-clash test
Hardened: restraint: PASS: fortify test because fortify note found
Hardened: restraint: PASS: glibcxx-assertions test
Hardened: restraint: PASS: entry test
Hardened: restraint: PASS: gnu-stack test because stack segment exists with the correct permissions
Hardened: restraint: PASS: gnu-relro test
Hardened: restraint: PASS: gaps test because no gaps found in .text section coverage
Hardened: restraint: PASS: notes test
Hardened: restraint: skip: branch-protection test because not an AArch64 binary
Hardened: restraint: skip: dynamic-tags test because AArch64 specific
Hardened: restraint: PASS: fast test
Hardened: restraint: skip: go-revision test because no GO compiled code found
Hardened: restraint: PASS: instrumentation test
Hardened: restraint: skip: only-go test because no GO compiled code found
Hardened: restraint: PASS: production test
Hardened: restraint: PASS: property-note test because CET enabled property note found
Hardened: restraint: PASS: run-path test
Hardened: restraint: PASS: rwx-seg test
Hardened: restraint: PASS: short-enums test
Hardened: restraint: skip: stack-realign test because not a 32-bit i686 executable
Hardened: restraint: PASS: textrel test
Hardened: restraint: PASS: threads test
Hardened: restraint: PASS: unicode test
Hardened: restraint: Overall: PASS. |
Please do not try to reinvent the wheel if at all possible - Fedora/RHEL RPM build system already does this for you - you don't need an (incomplete?) explicit list of FLAGS. Like I mentioned in my original post, reusing the variables already available to you as
(Or similar syntax with When a new hardening flag appears in gcc/clang and it gets added to |
The
annocheck
(1) tool from theannobin-annocheck
package reports thatThis may or may not be because the
restraint.spec
doesn't setLDFLAGS
, it only setsCFLAGS
:This should presumably export
LDFLAGS
:The text was updated successfully, but these errors were encountered: