public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] find dynamic stack allocations in checkstack.pl
@ 2008-05-02 17:26 Eric Sandeen
  2008-05-02 22:35 ` Jörn Engel
  0 siblings, 1 reply; 3+ messages in thread
From: Eric Sandeen @ 2008-05-02 17:26 UTC (permalink / raw)
  To: Linux Kernel Mailing List; +Cc: Jörn Engel, Andrew Morton

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>
---

Index: linux-2.6.25/scripts/checkstack.pl
===================================================================
--- linux-2.6.25.orig/scripts/checkstack.pl	2008-05-02 12:18:15.426407528 -0500
+++ linux-2.6.25/scripts/checkstack.pl	2008-05-02 12:18:25.989469552 -0500
@@ -26,8 +26,12 @@
 # $& (whole re) matches the complete objdump line with the stack growth
 # $1 (first bracket) matches the size of the stack growth
 #
+# $dre is similar, but for dynamic stack redutions:
+# $& (whole re) matches the complete objdump line with the stack growth
+# $1 (first bracket) matches the dynamic amount of the stack growth
+#
 # use anything else and feel the pain  ;) 
-my (@stack, $re, $x, $xs);
+my (@stack, $re, $dre, $x, $xs);
 {
 	my $arch = shift;
 	if ($arch eq "") {
@@ -47,9 +51,11 @@ my (@stack, $re, $x, $xs);
 	} elsif ($arch =~ /^i[3456]86$/) {
 		#c0105234:       81 ec ac 05 00 00       sub    $0x5ac,%esp
 		$re = qr/^.*[as][du][db]    \$(0x$x{1,8}),\%esp$/o;
+		$dre = qr/^.*[as][du][db]    (%.*),\%esp$/o;
 	} elsif ($arch eq 'x86_64') {
 		#    2f60:	48 81 ec e8 05 00 00 	sub    $0x5e8,%rsp
 		$re = qr/^.*[as][du][db]    \$(0x$x{1,8}),\%rsp$/o;
+		$dre = qr/^.*[as][du][db]    (\%.*),\%rsp$/o;
 	} elsif ($arch eq 'ia64') {
 		#e0000000044011fc:       01 0f fc 8c     adds r12=-384,r12
 		$re = qr/.*adds.*r12=-(([0-9]{2}|[3-9])[0-9]{2}),r12/o;
@@ -142,6 +148,22 @@ while (my $line = <STDIN>) {
 		next if ($size < 100);
 		push @stack, "$intro$size\n";
 	}
+	elsif (defined $dre && $line =~ m/$dre/) {
+		my $size = "Dynamic ($1)";
+
+		next if $line !~ m/^($xs*)/;
+		my $addr = $1;
+		$addr =~ s/ /0/g;
+		$addr = "0x$addr";
+
+		my $intro = "$addr $func [$file]:";
+		my $padlen = 56 - length($intro);
+		while ($padlen > 0) {
+			$intro .= '	';
+			$padlen -= 8;
+		}
+		push @stack, "$intro$size\n";
+	}
 }
 
 print sort bysize @stack;


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] find dynamic stack allocations in checkstack.pl
  2008-05-02 17:26 [PATCH] find dynamic stack allocations in checkstack.pl Eric Sandeen
@ 2008-05-02 22:35 ` Jörn Engel
  2008-05-03  2:21   ` Eric Sandeen
  0 siblings, 1 reply; 3+ messages in thread
From: Jörn Engel @ 2008-05-02 22:35 UTC (permalink / raw)
  To: Eric Sandeen; +Cc: Linux Kernel Mailing List, Jörn Engel, Andrew Morton

On Fri, 2 May 2008 12:26:29 -0500, Eric Sandeen wrote:
> 
> @@ -142,6 +148,22 @@ while (my $line = <STDIN>) {
>  		next if ($size < 100);
>  		push @stack, "$intro$size\n";
>  	}
> +	elsif (defined $dre && $line =~ m/$dre/) {

These two could join a line.  Otherwise an excellent addition.

Reviewed-By: Joern Engel <joern@logfs.org>

Jörn

-- 
"Translations are and will always be problematic. They inflict violence
upon two languages." (translation from German)

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] find dynamic stack allocations in checkstack.pl
  2008-05-02 22:35 ` Jörn Engel
@ 2008-05-03  2:21   ` Eric Sandeen
  0 siblings, 0 replies; 3+ messages in thread
From: Eric Sandeen @ 2008-05-03  2:21 UTC (permalink / raw)
  To: Jörn Engel; +Cc: Linux Kernel Mailing List, Jörn Engel, Andrew Morton

Jörn Engel wrote:
> On Fri, 2 May 2008 12:26:29 -0500, Eric Sandeen wrote:
>> @@ -142,6 +148,22 @@ while (my $line = <STDIN>) {
>>  		next if ($size < 100);
>>  		push @stack, "$intro$size\n";
>>  	}
>> +	elsif (defined $dre && $line =~ m/$dre/) {
> 
> These two could join a line.  Otherwise an excellent addition.

Thanks... was just following the existing style (in this part of the
file, anyway...)

-Eric

> Reviewed-By: Joern Engel <joern@logfs.org>
> 
> Jörn
> 


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2008-05-03  2:21 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-05-02 17:26 [PATCH] find dynamic stack allocations in checkstack.pl Eric Sandeen
2008-05-02 22:35 ` Jörn Engel
2008-05-03  2:21   ` Eric Sandeen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox