X-Git-Url: https://ruderich.org/simon/gitweb/?p=blhc%2Fblhc.git;a=blobdiff_plain;f=bin%2Fblhc;h=193297e4b7fdba4ffb6095074b4c3cea0774e055;hp=d56a6c079eb9cd641961f87f13efc609dee4b29f;hb=c00a6af3163584d9bbe5f0742f9ed001c202e564;hpb=a0449437d5ece8f14f3b450e91325e0e8a6765e7 diff --git a/bin/blhc b/bin/blhc index d56a6c0..193297e 100755 --- a/bin/blhc +++ b/bin/blhc @@ -222,11 +222,17 @@ my @def_cflags_fortify = ( # fortify needs at least -O1, but -O2 is recommended anyway ); my @def_cflags_stack = ( - '-fstack-protector', + '-fstack-protector', # keep first, used by cflags_stack_broken() '--param[= ]ssp-buffer-size=4', ); my @def_cflags_stack_strong = ( - '-fstack-protector-strong', + '-fstack-protector-strong', # keep first, used by cflags_stack_broken() +); +my @def_cflags_stack_bad = ( + # Blacklist all stack protector options for simplicity. + '-fno-stack-protector', + '-fno-stack-protector-all', + '-fno-stack-protector-strong', ); my @def_cflags_pie = ( '-fPIE', @@ -270,6 +276,7 @@ my @flag_refs = ( \@def_cflags_fortify, \@def_cflags_stack, \@def_cflags_stack_strong, + \@def_cflags_stack_bad, \@def_cflags_pie, \@def_cxxflags, \@def_cppflags, @@ -471,6 +478,19 @@ sub cppflags_fortify_broken { return 1; } +sub cflags_stack_broken { + my ($line, $missing_flags, $strong) = @_; + + my $flag = $strong ? $def_cflags_stack_strong[0] + : $def_cflags_stack[0]; + + if (not flag_overwritten($line, $flag, \@def_cflags_stack_bad)) { + return 0; + } + push @{$missing_flags}, $flag; + return 1; +} + # Modifies $missing_flags_ref array. sub pic_pie_conflict { my ($line, $pie, $missing_flags_ref, @flags_pie) = @_; @@ -1053,7 +1073,7 @@ foreach my $file (@ARGV) { # treated as a normal compiler line. next if $line =~ m{^\s*rm\s+}; # Some build systems emit "gcc > file". - next if $line =~ m{$cc_regex_normal\s*>\s*\S+}; + next if $line =~ m{$cc_regex_normal\s*>\s*\S+}o; # Check if additional hardening options were used. Used to ensure # they are used for the complete build. @@ -1356,7 +1376,10 @@ LINE: # Check hardening flags. my @missing; - if ($compile and not all_flags_used($line, \@missing, @cflags) + if ($compile and (not all_flags_used($line, \@missing, @cflags) + or (($harden_stack or $harden_stack_strong) + and cflags_stack_broken($line, \@missing, + $harden_stack_strong))) # Libraries linked with -fPIC don't have to (and can't) be # linked with -fPIE as well. It's no error if only PIE flags # are missing.