Skip to content
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

Verify security hardening features are turned on #1064

Conversation

defuse
Copy link
Contributor

@defuse defuse commented Jul 1, 2016

No description provided.

@daira
Copy link
Contributor

daira commented Jul 5, 2016

ACK, but see #915 (comment) .

@defuse
Copy link
Contributor Author

defuse commented Jul 5, 2016

I just did a rebuild with --disable-hardening, and the test catches the basic stuff but it still said FORTIFY_SOURCE was on. I think that's because it didn't completely rebuild everything, so the symbols it looks for to check that were still in there. I'm trying again with a full rebuild (after git clean -dfx).

if "${REPOROOT}/qa/zcash/checksec.sh" --fortify-file "$1" | grep -q "FORTIFY_SOURCE support available.*Yes" &&
"${REPOROOT}/qa/zcash/checksec.sh" --fortify-file "$1" | grep -q "Binary compiled with FORTIFY_SOURCE support.*Yes"; then
if { "${REPOROOT}/qa/zcash/checksec.sh" --fortify-file "$1" | grep -q "FORTIFY_SOURCE support available.*Yes"; } &&
{ "${REPOROOT}/qa/zcash/checksec.sh" --fortify-file "$1" | grep -q "Binary compiled with FORTIFY_SOURCE support.*Yes"; } then
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this line should strictly speaking end in }; then. } then is accepted and apparently works, but I can find no documentation guaranteeing that it will work.

@daira
Copy link
Contributor

daira commented Jul 11, 2016

ACK.

@daira
Copy link
Contributor

daira commented Jul 11, 2016

Still concerned about #915 (comment) though.

@ebfull
Copy link
Contributor

ebfull commented Jul 18, 2016

Is this still WIP or can it be reviewed?

@defuse
Copy link
Contributor Author

defuse commented Jul 21, 2016

I pulled in upstream's stuff, here's a TODO list:

@defuse defuse force-pushed the t915-enable-security-hardening branch from ef0f257 to a8cdc16 Compare July 22, 2016 01:54
@defuse
Copy link
Contributor Author

defuse commented Jul 22, 2016

force pushed

test_fortify_source "${REPOROOT}/src/zcash-gtest"
test_fortify_source "${REPOROOT}/src/bitcoin-tx"
test_fortify_source "${REPOROOT}/src/test/test_bitcoin"
test_fortify_source "${REPOROOT}/src/zcash/GenerateParams"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a bit worried if we add another binary we'll forget to put it here, but I don't know of a better practical alternative.

@ebfull
Copy link
Contributor

ebfull commented Jul 22, 2016

What's the story with the CXXFLAGS we give libzcash?

@defuse
Copy link
Contributor Author

defuse commented Jul 22, 2016

@ebfull haven't got to that yet

@defuse
Copy link
Contributor Author

defuse commented Jul 22, 2016

Something is really wrong with our build system, here's a command from the output showing a build in libzcash:

/home/firexware/Data-1/Documents/FireXware/la/zcash/depends/x86_64-unknown-linux-gnu/native/bin/ccache g++ -m64 -DHAVE_CONFIG_H -I. -I../src/config  -DMULTICORE -fopenmp -fPIC -DBINARY_OUTPUT -DCURVE_ALT_BN128 -DBOOST_SPIRIT_THREADSAFE -DHAVE_BUILD_INFO -D__STDC_FORMAT_MACROS    -pipe -O2 -O0 -g -Wstack-protector -fstack-protector-all -fPIE -fvisibility=hidden -DSTATIC -I. -I./obj -pthread -I/home/firexware/Data-1/Documents/FireXware/la/zcash/depends/x86_64-unknown-linux-gnu/include -I./leveldb/include -I./leveldb/helpers/memenv -I/home/firexware/Data-1/Documents/FireXware/la/zcash/depends/x86_64-unknown-linux-gnu/include -I/home/firexware/Data-1/Documents/FireXware/la/zcash/depends/x86_64-unknown-linux-gnu/include -I./secp256k1/include  -I/home/firexware/Data-1/Documents/FireXware/la/zcash/depends/x86_64-unknown-linux-gnu/include/libsnark -I/home/firexware/Data-1/Documents/FireXware/la/zcash/depends/x86_64-unknown-linux-gnu/include/  -DBOOST_SPIRIT_THREADSAFE -DHAVE_BUILD_INFO -D__STDC_FORMAT_MACROS  -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2  -std=c++11 -pipe -O2 -Wno-deprecated-declarations -Wno-placement-new -Wno-terminate -Werror -O1 -g  -Wstack-protector -fstack-protector-all -fPIE -MT zcash/libzcash_a-Note.o -MD -MP -MF zcash/.deps/libzcash_a-Note.Tpo -c -o zcash/libzcash_a-Note.o `test -f 'zcash/Note.cpp' || echo './'`zcash/Note.cpp

Notice there's -O1 and -O2 multiple times.

@@ -415,7 +415,7 @@ libzcash_a_SOURCES = \
zcash/prf.cpp \
zcash/util.cpp

libzcash_a_CPPFLAGS = -DMULTICORE -fopenmp -fPIC -DBINARY_OUTPUT -DCURVE_ALT_BN128 -DBOOST_SPIRIT_THREADSAFE -DHAVE_BUILD_INFO -D__STDC_FORMAT_MACROS $(HARDENED_CPPFLAGS) -pipe -O2 -O0 -g -Wstack-protector -fstack-protector-all -fPIE -fvisibility=hidden -DSTATIC $(BITCOIN_INCLUDES)
libzcash_a_CPPFLAGS = -DMULTICORE -fopenmp -fPIC -DBINARY_OUTPUT -DCURVE_ALT_BN128 -DBOOST_SPIRIT_THREADSAFE -DHAVE_BUILD_INFO -D__STDC_FORMAT_MACROS $(HARDENED_CPPFLAGS) $(HARDENED_CXXFLAGS) $(HARDENED_LDFLAGS) -pipe -O2 -O0 -g -Wstack-protector -fstack-protector-all -fPIE -fvisibility=hidden -DSTATIC $(BITCOIN_INCLUDES)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not related to this change: How did we end up with -O2 -O0 right beside each other?!?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also I don't even know if CXXFLAGS will be effective when given to CPPFLAGS... if I add a libzcash_a_CXXFLAGS = ... will it magically put that in the appropriate build commands? What about LDFLAGS?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How did we end up with -O2 -O0 right beside each other?!?

Not sure, we should get rid of it.

will it magically put that in the appropriate build commands

Yes.

What about LDFLAGS?

Yes. And we should.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How did we end up with -O2 -O0 right beside each other?!?
Not sure, we should get rid of it.

Hypothesis: Someone cut and pasted flags from a command executed by Make that appeared in their build output.

I've seen -O2 -O0 -g before in the commands issued by Make due to different variable expansions, but I've never seen those flags defined next to eachother (which is nonsensical). It may be that someone cut and pasted a command?

(BTW: g++ documents that it always uses the last occurring -O value.)

@defuse defuse force-pushed the t915-enable-security-hardening branch from 2d04fae to be0d1e1 Compare July 22, 2016 02:44
@defuse
Copy link
Contributor Author

defuse commented Jul 22, 2016

force pushed again, doing some cleanup

@defuse defuse force-pushed the t915-enable-security-hardening branch from be0d1e1 to 73537eb Compare July 22, 2016 02:45
@defuse defuse changed the title [WIP] Verify security hardening features are turned on Verify security hardening features are turned on Jul 22, 2016
@defuse
Copy link
Contributor Author

defuse commented Jul 22, 2016

Ok, this is ready for review.

Rant: But even though I've read more than the first half of a whole book about it, I don't understand the configure/autoconf/magic-variable-name-interpretation crap so I don't have much confidence that the security stuff is really enabled for everything. #1064 (comment) demonstrates there is at least something wrong with our build (prior to the work in this PR).

@defuse defuse added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jul 22, 2016
@solardiz
Copy link
Contributor

On Thu, Jul 21, 2016 at 12:45:14PM -0700, Taylor Hornby wrote:

  • Use -O1 instead of -O2.

I probably missed earlier discussion somewhere, but why do you prefer -O1? I think going with -O1 may actually hurt security, not to mention performance. How about "-O2 -fno-strict-aliasing -fwrapv"? That's for production builds; for development, we should also test with pure -O2 or even -O3, and ensure we receive no strict aliasing violation warnings, etc. (which are not printed in the -fno-strict-aliasing mode).

@daira
Copy link
Contributor

daira commented Jul 22, 2016

I prefer -O1 because I don't trust GCC's implementation of optimizations used at higher levels to be correct. I can't say I trust GCC at all, but we're forced to, and the optimizations at -O2 and above start getting very complicated. However, +1 for -fwrapv, and +0.5 for -fno-strict-aliasing.

@ebfull
Copy link
Contributor

ebfull commented Jul 27, 2016

ACK but my complaints on #1064 (comment) may be relevant.

@ebfull
Copy link
Contributor

ebfull commented Aug 1, 2016

This can be merged I believe! Let's merge it soon so we can see the performance impact!

@nathan-at-least nathan-at-least modified the milestones: z8 release - core (excl. RPC) audit freeze, functional PoW, z9 Release - RPC, Audit tasks, Testing improvements Aug 1, 2016
@bitcartel
Copy link
Contributor

There might be an issue. I just performed a build and I can see both -O1 and -O2 flags are being used:

-DBOOST_SPIRIT_THREADSAFE -DHAVE_BUILD_INFO -D__STDC_FORMAT_MACROS -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 -std=c++11 -pipe -O2 -Wno-deprecated-declarations -Wno-placement-new -Wno-terminate -Werror -O1 -g -Wstack-protector

@bitcartel
Copy link
Contributor

bitcartel commented Aug 3, 2016

@defuse I think we just need a one line change. Here's the diff: https://gist.github.com/bitcartel/436ae915ce7873e374b55e158f04fa47

@daira
Copy link
Contributor

daira commented Aug 3, 2016

That change replaces -O2 -O0 with -O1 in the libzcash flags, but the flags in @bitcartel's comment above did not contain -O0, so I think they must be using a different variable.

Why do we have these options specified in so many different places?

@bitcartel
Copy link
Contributor

Optimization flags affect performance measurements, but are they a roadblock for this PR to satisfy "Verify security hardening features are turned on"?

I think we can and should merge but will wait for feedback before doing so. In the meantime, I've opened #1168 as a reminder to review and fix optimization flags for the next release, z9.

@bitcartel
Copy link
Contributor

ACK after dicussion with @nathan-at-least.

@bitcartel
Copy link
Contributor

@zkbot r+

@zkbot
Copy link
Contributor

zkbot commented Aug 3, 2016

📌 Commit 73537eb has been approved by bitcartel

@zkbot
Copy link
Contributor

zkbot commented Aug 3, 2016

⌛ Testing commit 73537eb with merge abd4c16...

zkbot pushed a commit that referenced this pull request Aug 3, 2016
…ecurity-hardening, r=bitcartel

Verify security hardening features are turned on
@zkbot
Copy link
Contributor

zkbot commented Aug 4, 2016

☀️ Test successful - zcash

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: Awaiting review from the assignee but also interested parties.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants