Skip to content

Commit 585e93a

Browse files
Eric Sandeentorvalds
authored andcommitted
find dynamic stack allocations in checkstack.pl
Currently, checkstack.pl only looks for fixed subtractions from the stack pointer. However, things like this: void function(int size) { char stackbuster[size << 2]; ... are certainly worth pointing out, I think. This could perhaps be done more cleanly, and the following patch only adds "dynamic" REs for x86 and x86_64, but it works: 0x00b0 crypto_cbc_decrypt_inplace [cbc]: Dynamic (%rax) 0x00ad crypto_pcbc_decrypt_inplace [pcbc]: Dynamic (%rax) 0x02f6 crypto_pcbc_encrypt_inplace [pcbc]: Dynamic (%rax) 0x036c _crypto_xcbc_digest_setkey [xcbc]: Dynamic (%rax) ... (Inspired by Keith Owens' old stack-check script) Signed-off-by: Eric Sandeen <sandeen@redhat.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 545e400 commit 585e93a

1 file changed

Lines changed: 23 additions & 1 deletion

File tree

scripts/checkstack.pl

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,12 @@
2626
# $& (whole re) matches the complete objdump line with the stack growth
2727
# $1 (first bracket) matches the size of the stack growth
2828
#
29+
# $dre is similar, but for dynamic stack redutions:
30+
# $& (whole re) matches the complete objdump line with the stack growth
31+
# $1 (first bracket) matches the dynamic amount of the stack growth
32+
#
2933
# use anything else and feel the pain ;)
30-
my (@stack, $re, $x, $xs);
34+
my (@stack, $re, $dre, $x, $xs);
3135
{
3236
my $arch = shift;
3337
if ($arch eq "") {
@@ -46,9 +50,11 @@
4650
} elsif ($arch =~ /^i[3456]86$/) {
4751
#c0105234: 81 ec ac 05 00 00 sub $0x5ac,%esp
4852
$re = qr/^.*[as][du][db] \$(0x$x{1,8}),\%esp$/o;
53+
$dre = qr/^.*[as][du][db] (%.*),\%esp$/o;
4954
} elsif ($arch eq 'x86_64') {
5055
# 2f60: 48 81 ec e8 05 00 00 sub $0x5e8,%rsp
5156
$re = qr/^.*[as][du][db] \$(0x$x{1,8}),\%rsp$/o;
57+
$dre = qr/^.*[as][du][db] (\%.*),\%rsp$/o;
5258
} elsif ($arch eq 'ia64') {
5359
#e0000000044011fc: 01 0f fc 8c adds r12=-384,r12
5460
$re = qr/.*adds.*r12=-(([0-9]{2}|[3-9])[0-9]{2}),r12/o;
@@ -141,6 +147,22 @@ ($)
141147
next if ($size < 100);
142148
push @stack, "$intro$size\n";
143149
}
150+
elsif (defined $dre && $line =~ m/$dre/) {
151+
my $size = "Dynamic ($1)";
152+
153+
next if $line !~ m/^($xs*)/;
154+
my $addr = $1;
155+
$addr =~ s/ /0/g;
156+
$addr = "0x$addr";
157+
158+
my $intro = "$addr $func [$file]:";
159+
my $padlen = 56 - length($intro);
160+
while ($padlen > 0) {
161+
$intro .= ' ';
162+
$padlen -= 8;
163+
}
164+
push @stack, "$intro$size\n";
165+
}
144166
}
145167

146168
print sort bysize @stack;

0 commit comments

Comments
 (0)