I think we may be able to add some configure/compiler/linker flags in Tor Browser that can improve security without many downsides. Let's figure out what those are and add them.
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information
Child items ...
Show closed items
Linked items 0
Link issues together to show that they're related.
Learn more.
Using about:buildconfig, the browser reports compiler flags and configure arguments for our tor-browser.git builds. Are these a complete list of the compiler flags actually used? I don't know. In any case, here are the current reports:
Trac: Description: I think we are probably forgetting some configure/compiler/linker flags in Tor Browser that can improve security. Let's figure out what those are and add them. I would suggest child tickets for each new flag, so we can do this step by step.
to
I think we may be able to add some configure/compiler/linker flags in Tor Browser that can improve security without many downsides. Let's figure out what those are and add them. I would suggest child tickets for each new flag, so we can do this step by step.
Here are some security flags I think we can add to the gcc-based builds (Linux and mingw). There is heavy overlap with the proposed flags in https://bugzilla.mozilla.org/show_bug.cgi?id=620058. (I think we should be able to add similar flags to the clang based builds -- I will look into that after we settle on flags to add to gcc.)
Note I am leaving out more advanced mitigations like -fvtable-verify=std for this iteration because getting these to work is likely to be complex.
Trac: Description: I think we may be able to add some configure/compiler/linker flags in Tor Browser that can improve security without many downsides. Let's figure out what those are and add them. I would suggest child tickets for each new flag, so we can do this step by step.
to
I think we may be able to add some configure/compiler/linker flags in Tor Browser that can improve security without many downsides. Let's figure out what those are and add them.
Here are some security flags I think we can add to the gcc-based builds (Linux and mingw). There is heavy overlap with the proposed flags in https://bugzilla.mozilla.org/show_bug.cgi?id=620058. (I think we should be able to add similar flags to the clang based builds -- I will look into that after we settle on flags to add to gcc.)
{{{
-Werror=format
-Werror=format-security
-fstack-protector-strong
--param ssp-buffer-size=4
-pie -fPIE
-D_FORTIFY_SOURCE=2 -O1
-Wl,-z,relro,-z,now
-ftrapv
}}}
Uhm. We are doing already most of those things. Have you looked at our gitian build scripts? And I am not so sure we should build with ftrapv see comment:1:ticket:18310.
Note I am leaving out more advanced mitigations like -fvtable-verify=std for this iteration because getting these to work is likely to be complex.
Here are some security flags I think we can add to the gcc-based builds (Linux and mingw). There is heavy overlap with the proposed flags in https://bugzilla.mozilla.org/show_bug.cgi?id=620058. (I think we should be able to add similar flags to the clang based builds -- I will look into that after we settle on flags to add to gcc.)
Uhm. We are doing already most of those things. Have you looked at our gitian build scripts?
Sorry I hadn't found the existing build flags before posting this ticket. I discussed with gk what is already in our build scripts.
On linux, we have in gitian/descriptors/linux/gitian-firefox.yml:
{{{
export DEB_BUILD_HARDENING=1
export DEB_BUILD_HARDENING_STACKPROTECTOR=1
export DEB_BUILD_HARDENING_FORTIFY=1
export DEB_BUILD_HARDENING_FORMAT=1
export DEB_BUILD_HARDENING_PIE=1
Indeed this covers most of the flags I mentioned. I'm not sure about `-Wl,-z,relro,-z,now`. gk, do you know how these are covered? boklm pointed me to [a part of the Tor Browser test suite](https://gitweb.torproject.org/boklm/tor-browser-bundle-testsuite.git/tree/TBBTestSuite/TestSuite/BrowserBundleTests.pm#n45) that seems to indicate that full relro is applied. Is that correct? I think it would be useful also to somehow confirm that we are now using -fstack-protector-strong and not -fstack-protector; I will try to investigate that.* On Windows, we have in [gitian/build-helpers/i686-w64-mingw32-g++](https://gitweb.torproject.org/builders/tor-browser-bundle.git/tree/gitian/build-helpers/i686-w64-mingw32-g++):
I'm not familiar with Windows/mingw build flags, but it looks like we could possibly switch to -fstack-protector-strong. Also I wonder if -D_FORTIFY_SOURCE=2 and the relro flags make sense.* On Mac, we are adding -fPIE to the clang flags in [gitian/descriptors/mac/gitian-firefox.yml](https://gitweb.torproject.org/builders/tor-browser-bundle.git/tree/gitian/descriptors/mac/gitian-firefox.yml#n43). clang largely supports gcc's build flags so I think we could probably add most or all of the flags from comment:6 to the build. (I tried all of those flags with clang++ while building a "hello world" c++ program and confirmed that clang++ at least did not complain that any of the flags were unknown.)> And I am not so sure we should build with `ftrapv` see comment:1:ticket:18310.That's interesting. I'm not sure what the right answer is. RCE seems a lot worse than DOS, though.> > Note I am leaving out more advanced mitigations like -fvtable-verify=std for this iteration because getting these to work is likely to be complex.> > That is broken and not working due to Mozilla internals, see: https://bugzilla.mozilla.org/show_bug.cgi?id=1046600I read in [Tice et al 2014](https://www.usenix.org/system/files/conference/usenixsecurity14/sec14-paper-tice.pdf) that there is a mechanism in the VTV code to "whitelist" some parts of the code that would otherwise fail verification. I wonder if that feature is deployed in the gcc VTV implementation and could be used to get around the problematic vtable hacking Nathan Froyd [mentions in the Mozilla bug](https://bugzilla.mozilla.org/show_bug.cgi?id=1046600#c2). Similarly, clang's -fsanitize has an option to["blacklist"](https://clang.llvm.org/docs/ControlFlowIntegrity.html#forward-edge-cfi-for-virtual-calls) certain functions so that they also don't fail verification.Something else that occurs to me is it would be nice to document our hardening flags for each build (hardened, alpha, release) in the Tor Browser design document.
Here are some security flags I think we can add to the gcc-based builds (Linux and mingw). There is heavy overlap with the proposed flags in https://bugzilla.mozilla.org/show_bug.cgi?id=620058. (I think we should be able to add similar flags to the clang based builds -- I will look into that after we settle on flags to add to gcc.)
{{{
-Werror=format
-Werror=format-security
-fstack-protector-strong
--param ssp-buffer-size=4
-pie -fPIE
-D_FORTIFY_SOURCE=2 -O1
-Wl,-z,relro,-z,now
-ftrapv
}}}
Uhm. We are doing already most of those things. Have you looked at our gitian build scripts?
Sorry I hadn't found the existing build flags before posting this ticket. I discussed with gk what is already in our build scripts.
On linux, we have in gitian/descriptors/linux/gitian-firefox.yml:
{{{
export DEB_BUILD_HARDENING=1
export DEB_BUILD_HARDENING_STACKPROTECTOR=1
export DEB_BUILD_HARDENING_FORTIFY=1
export DEB_BUILD_HARDENING_FORMAT=1
export DEB_BUILD_HARDENING_PIE=1
}}}
Indeed this covers most of the flags I mentioned. I'm not sure about -Wl,-z,relro,-z,now. gk, do you know how these are covered? boklm pointed me to a part of the Tor Browser test suite that seems to indicate that full relro is applied. Is that correct?
Yes, full relro is applied. I think we get the flags you mentioned by export DEB_BUILD_HARDENING=1. The other *HARDENING flags should not be needed. I opened #21565 (moved) for the clean-up.
[snip]
And I am not so sure we should build with ftrapv see comment:1:ticket:18310.
That's interesting. I'm not sure what the right answer is. RCE seems a lot worse than DOS, though.
-ftrapv is not the only means we apply to Tor Browser. A useful exercise would be to understand for which cases -ftrapv would be needed given all our other hardening flags.
[snip]
Something else that occurs to me is it would be nice to document our hardening flags for each build (hardened, alpha, release) in the Tor Browser design document.
hardening-wrapper is obsolete and has been removed from unstable. Please use dpkg-buildflags as explained above.
https://wiki.debian.org/Hardening#hardening-wrapper
hardening-check can only check the resulting binaries and thus might not catch missing hardening flags if they are only missing in a few places. blhc is a small parser written in Perl which checks the build logs for missing hardening flags. It can be used on build logs created by dpkg-buildpackage or buildd.
http://ruderich.org/simon/blhc/
For comparison, here are the current Firefox release build flags:
For comparison we need ESR52 build options, both 32-bit and 64-bit for every OS. What about official MinGW builds?
I'm not familiar with Windows/mingw build flags, but it looks like we could possibly switch to -fstack-protector-strong.
All occurrences of -fstack-protector --param ssp-buffer-size=4 should be replaced with at least -fstack-protector=strong.
http://www.outflux.net/blog/archives/2014/01/27/fstack-protector-strong/
For those who want to protect all the functions then -fstack-protector-all is recommended.
https://wiki.debian.org/Hardening#DEB_BUILD_HARDENING_STACKPROTECTOR_.28gcc.2Fg.2B-.2B--fstack-protector-strong.29
Also I wonder if -D_FORTIFY_SOURCE=2 and the relro flags make sense.
-D_FORTIFY_SOURCE=2 -O1 is a
Compile-time protection against static sized buffer overflows. No known regressions or performance loss. This should be enabled system-wide.
https://wiki.debian.org/Hardening#gcc-D_FORTIFY_SOURCE.3D2_-O1
After a lot of experimentation, I opened #23024 (moved) and #23025 (moved) to add some extra hardening flags for Windows and Mac respectively. In the meantime I also found several promising flags didn't work after all:
Windows (mingw cross-compile):
-z,relro,-z,now fails (is there an equivalent flag for Windows binaries?)
Replying to arthuredelstein:
During your investigations Mozilla suddenly started to harden Firefox :0. So this looks like the third part of Tor Patch Uplifting project (next to FPI and fingerprinting). (Mark their tickets accordingly ;)
-z,relro,-z,now fails (is there an equivalent flag for Windows binaries?)
This is how it works on Windows by default, no equivalents required.
-Wl,-z,relro,-z,now when "Options passed to the compiler when linking executables or shared objects" or -z relro -z now "if the linker is called directly".
relro - "Create an ELF PT_GNU_RELRO segment header in the object." (i.e. Linux only)
This is https://bugzilla.mozilla.org/show_bug.cgi?id=1359912 (and dependencies!)
now - Don't use Linux-only lazy binding
This is https://bugzilla.mozilla.org/show_bug.cgi?id=1359918
Werror=format throws errors (around uses of %lld)
Mozilla uses -Wno-format, because "# We use mix of both POSIX and Win32 printf format across the tree, so format warnings are useless on mingw."
But, suddenly, https://bugzilla.mozilla.org/show_bug.cgi?id=1359915