-
Notifications
You must be signed in to change notification settings - Fork 3
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
Makefile: Apply minimum hardening to libs and applications. #33
Makefile: Apply minimum hardening to libs and applications. #33
Conversation
besser82
commented
Dec 22, 2024
- -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.
This kind of options are normally applied by the distro, not by flags coming from the package itself, but for a rather system-specific package like this I suppose we may. On Owl, our patched Is the name |
That flag ensures that there are no undefined symbols left during link-time, and thus should be used toghether with
Yes, the idea is to have them applied even if |
Given that all of |
I think the intent is to use it for compiler flags as well, so no... or would we prefer two variables? |
The compiler flags should be passed to the linker as well (because of LTO), but the linker-only flags don't have to be passed to the compiler (they would be ignored). If the idea is to have a single variable for both, then the patch is good as it is. |
e78d7c7
to
1ac0ac7
Compare
Rebased onto main, and updated to not required an additional variable. |
So now the idea is to have those hardening flags where appropriate in all builds, and if a build doesn't want them it has to pass the corresponding @ldv-alt What do you think? |
Just to give abit more of context: Those flags are supported since gcc v4.0, and define the absolute minimum of portable hardening; the same flags are the ones applied to packages like shadow-utils and alike by default since RHEL 5 or so. |
1ac0ac7
to
b52ec3f
Compare
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 <[email protected]>
b52ec3f
to
947c61d
Compare
That's not quite true. gcc 4.6.3 that we had in Owl (until we've essentially stopped maintaining it) recognizes Also, we're running into some issue on linking, but maybe that's a gcc bug or our gcc packaging bug?
|
I think I'll merge this, and if we want to use a legacy Owl system for testing of tcb after this change then we'll be able to override the flags for such build. |
@@ -13,6 +13,10 @@ OMIT_PAM_MODULE = | |||
# May be needed when compiling to use with OpenPAM. | |||
PAM_SO_SUFFIX = | |||
|
|||
# Flags for hardening. | |||
HARDENING_CFLAGS = -fstack-protector-strong -D_FORTIFY_SOURCE=2 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, this -D_FORTIFY_SOURCE=2
might be problematic for ALT because there the default is -D_FORTIFY_SOURCE=3
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it should be OK since per my reading of the changes here HARDENING_CFLAGS
is prepended before the passed CFLAGS
. Unless you have that as compiler default, not as part of default RPM optflags
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Apparently, it's a compiler default, so now I see the following warnings:
<command-line>: warning: "_FORTIFY_SOURCE" redefined
<built-in>: note: this is the location of the previous definition
"info gcc" on that system displays the following note:
NOTE: In ALT 12.2.1-alt2 and later versions, '-D_FORTIFY_SOURCE=3' is set by default, and is activated when '-O' is set to 1 or higher.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We'd probably avoid this specific issue by upgrading to =3
, but overall it's not good we may override a potentially better default.