2 # Copyright (C) 2009 Red Hat Inc.
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 2 of the License, or
7 # (at your option) any later version.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 die("NOEXEC_CHECK not set") unless(exists($ENV{NOEXEC_CHECK}));
23 my @files = split(/ /, $ENV{NOEXEC_CHECK});
25 FILES: foreach my $file (@files) {
27 my @cmd = ('readelf', '-l', $file);
28 open($output, '-|', @cmd)
29 or die("$0: failed to run: '".join(' ', @cmd)."': $!\n");
34 # Find the offset of the Flags field
36 next unless(/^\s*Type\b/);
41 # Look for a Flg field on this line (32 bit)
42 $offset = index($_, 'Flg ');
45 # 64 bit is split over 2 lines. Look for a Flags field on the next
48 $offset = index($_, 'Flags ');
53 die("Unrecognised header: ".join("\n", @lines)) if(-1 == $offset);
57 # Find the GNU_STACK entry
59 next unless(/^\s*GNU_STACK\b/);
61 # Skip over input lines according to the header
62 for(my $i = 1; $i < $line; $i++) {
66 my $flags = substr($_, $offset, 3);
68 $flags =~ /^[ R][ W]([ E])$/ or die("Unrecognised flags: $flags");
71 print "***** $file has an executable stack *****\n";
78 die("Didn't find GNU_STACK entry");