blhc (build log hardening check) is a small tool which checks build logs for missing hardening flags.
Hardening flags enable additional security features in the compiler to prevent e.g. stack overflows, format string vulnerabilities, GOT overwrites, etc.
Because most build systems are quite complicated there are many places where compiler flags from the environment might be ignored. The parser verifies that all compiler commands use the correct hardening flags and thus all hardening features are correctly used.
It’s designed to check build logs generated by Debian’s dpkg-buildpackage (or tools using dpkg-buildpackage like pbuilder or sbuild (which is used for the official buildd build logs)) to help maintainers detect missing hardening flags in their packages.
At the moment it works only on Debian and derivatives but it should be easily extendable to other systems as well. Patches are welcome, see README for details.
Only gcc is detected as compiler at the moment. If other compilers support hardening flags as well, please report them.
blhc can be run directly from the source tree (
bin/blhc) or copied anywhere
on the system. It doesn’t have to be explicitly installed. To read the man
blhc is licensed under GPL 3 (or later).
If you find any bugs or have suggestions please tell me at firstname.lastname@example.org.
blhc path/to/log/file ...
If there’s no output, no flags are missing and the build log is fine.
Also see README and man page in tarball.
Current development happens in the git repository (also browsable as Gitweb):
git clone https://ruderich.org/simon/blhc/blhc.git
blhc is also packaged in Debian.
Version 0.07 (2016-09-11):
Version 0.06 (2016-06-05):
Sync architecture specific hardening support with dpkg 1.18.2.
Fix false positive in "libtool: link: g++ -include test.h .." (Debian Bug #784959), reported by Raphaël Hertzog.
Fix false positive with
gcc -v (Debian Bug #765756), reported by Andreas
Fix false positive in
rm lines (Debian Bug #772853), reported by Jakub
Sync architecture specific hardening support with dpkg 1.17.18.
Update t/tests.t for new output of Pod::Usage in 1.65 (Debian Bug #825428), reported by Niko Tyni, patch by Gregor Herrmann.
Fix false positives for comment lines (Debian Bug #825671), reported by Fabian Wolff.
Improve non-verbose detection for parallel builds (Debian Bug #801492), reported by Mattia Rizzolo, initial patch by Julien Lamy.
Version 0.05 (2014-08-20):
Fix false positive in configure output if $CC contains options (Debian bug #710135), reported by Bastien Roucariès.
Handle another case of Qt’s
moc (Debian bug #710780), reported by Felix
Fix detection of build dependencies for buildd logs (Debian bug #719656), reported by Nicolas Boulenguez.
Fix buildd architecture detection. Only relevant if the chroot setup fails and dpkg-buildpackage is never run; therefore a minor issue.
Fix false positive when "compiling" python files (Debian bugs #714630 and #753080), reported by Matthias Klose, patch by James McCoy.
Don’t check for hardening flags in non-verbose compiler commands spanning multiple lines.
Better handling of libtool commands (Debug bug #717598), reported by Stefan Fritsch.
Sync architecture specific hardening support with dpkg 1.17.13.
Check for -fstack-protector-strong on supported platforms (since dpkg 1.17.11) (Debian bug #757885), reported by Markus Koschany.
Consider lines with -O0 or -Og debug builds and disable checks for -O2 (Debian bug #714628), reported by Matthias Klose. Also don’t check for fortification in those lines as it requires optimization (Debian bug #757683), also reported by Matthias Klose.
Version 0.04 (2013-03-01):
Fix many false positives, this includes compiled header files, lines with
only CC=gcc but no other compiler commands and
Accept -Wformat=2 because it implies -Wformat.
Accept --param ssp-buffer-size=4 (space instead of equals sign).
Fix build dependency related checks (Ada, hardening-wrapper) for pbuilder build logs.
Fix architecture detection in old buildd build logs which use an additional "is" in the "dpkg-buildpackage: host architecture" field.
Updated output in buildd mode.
Only return non-zero exit codes for errors in buildd mode, not for warnings.
Minor performance improvements.
Support for Ada files.
Version 0.03 (2012-05-27):
Fix --ignore-flag with -fPIE.
Detect overwrite of -D_FORTIFY_SOURCE=2 with -D_FORTIFY_SOURCE=0 or 1 or -U_FORTIFY_SOURCE.
Add --ignore-arch-flag and --ignore-arch-line options to ignore flags and lines on certain architectures only.
Buildd tags "no-compiler-commands" and "invalid-cmake-used" are now information (I-) instead of warning (W-).
Ignore false positives when using moc-qt4.
Version 0.02 (2012-04-28):
Version 0.01 (2012-04-13):
The following links provide additional information about Debian’s hardening process and general information about available hardening options.
https://wiki.debian.org/ReleaseGoals/SecurityHardeningBuildFlags: Debian hardening release goal.
https://wiki.debian.org/HardeningWalkthrough: Walkthrough to enable hardening flags for a Debian package.
https://wiki.debian.org/Hardening: General information about hardening flags.
https://qa.debian.org/bls/: Debian’s buildd log parser. It uses blhc to check packages for missing hardening flags.