# Build log hardening check, checks build logs for missing hardening flags.
-# Copyright (C) 2012-2017 Simon Ruderich
+# Copyright (C) 2012-2018 Simon Ruderich
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
my $option_all = 0;
my $option_arch = undef;
my $option_buildd = 0;
+my $option_debian = 0;
$option_color = 0;
if (not Getopt::Long::GetOptions(
'help|h|?' => \$option_help,
'color' => \$option_color,
'arch=s' => \$option_arch,
'buildd' => \$option_buildd,
+ 'debian' => \$option_debian,
)) {
require Pod::Usage;
Pod::Usage::pod2usage(2);
}
if ($option_version) {
print <<"EOF";
-blhc $VERSION Copyright (C) 2012-2017 Simon Ruderich
+blhc $VERSION Copyright (C) 2012-2018 Simon Ruderich
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
# use a large enough default.
my $parallel = 10;
+ # Don't check for PIE flags if automatically applied by the compiler. Only
+ # used in buildd and Debian mode.
+ my $disable_harden_pie = 0;
+ if ($option_debian) {
+ $disable_harden_pie = 1;
+ }
+
while (my $line = <$fh>) {
# Detect architecture automatically unless overridden. For buildd logs
# only, doesn't use the dpkg-buildpackage header. Necessary to ignore
# flags are not checked.
#
# Strong stack protector is used since dpkg 1.17.11.
+ #
+ # Recent GCC versions automatically use PIE (only on supported
+ # architectures) and dpkg respects this properly since 1.18.15 and
+ # doesn't pass PIE flags manually.
if ($option_buildd
and index($line, 'Toolchain package versions: ') == 0) {
require Dpkg::Version;
if (Dpkg::Version::version_compare($1, '1.17.11') >= 0) {
$disable_strong = 0;
}
+ if (Dpkg::Version::version_compare($1, '1.18.15') >= 0) {
+ $disable_harden_pie = 1;
+ }
}
if ($disable) {
# Option or auto detected.
if ($arch) {
- # The following was partially copied from dpkg-dev 1.18.15
+ # The following was partially copied from dpkg-dev 1.18.24
# (/usr/share/perl5/Dpkg/Vendor/Debian.pm, _add_hardening_flags()),
# copyright Raphaƫl Hertzog <hertzog@debian.org>, Kees Cook
# <kees@debian.org>, Canonical, Ltd. licensed under GPL version 2 or
(undef, $os, $cpu) = Dpkg::Arch::debarch_to_debtriplet($arch);
}
+ my %builtin_pie_arch = map { $_ => 1 } qw(
+ amd64 arm64 armel armhf i386 kfreebsd-amd64 kfreebsd-i386
+ mips mipsel mips64el ppc64el s390x sparc sparc64
+ );
+
# Disable unsupported hardening options.
if ($os !~ /^(?:linux|kfreebsd|knetbsd|hurd)$/
or $cpu =~ /^(?:hppa|avr32)$/) {
$harden_relro = 0;
$harden_bindnow = 0;
}
+
+ if ($disable_harden_pie and exists $builtin_pie_arch{$arch}) {
+ $harden_pie = 0;
+ }
}
# Default values.
=back
+=item B<--debian>
+
+Apply Debian-specific settings. At the moment this only disables checking for
+PIE which is automatically applied by Debian's GCC and no longer requires a
+compiler command line argument.
+
=item B<--color>
Use colored (ANSI) output for warning messages.
pbuilder path/to/package.dsc | tee path/log/file
blhc path/to/file || echo flags missing
+Assume this build log was created on a Debian system and thus don't warn about
+missing PIE flags if the current architecture injects them automatically (this
+is enabled in buildd mode per default). C<--arch> is necessary if the build
+log contains no architecture information as written by dpkg-buildpackage.
+
+ blhc --debian --all --arch=amd64 path/to/log/file
+
=head1 BUILDD TAGS
The following tags are used in I<--buildd> mode. In braces the additional data
=head1 LICENSE AND COPYRIGHT
-Copyright (C) 2012-2017 by Simon Ruderich
+Copyright (C) 2012-2018 by Simon Ruderich
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by