Skip to contentSkip to conversation

lkdtm: reduce stack size

PATCH In review Frank Seidel 3 participants 5 messages Mar 1, 2009 – Mar 2, 2009 Char and misc drivers

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 lkdtm: reduce stack size

From: Frank Seidel <[email protected]>

Reduce stack memory footprint of lkdtm
(recursive_loop). From 1024 bytes on i386 down
to <10.

---
 drivers/misc/lkdtm.c |   16 +++++++++++++---
 1 file changed, 13 insertions(+), 3 deletions(-)
drivers/misc/lkdtm.c +13 -3
@@ -225,14 +225,24 @@ static int lkdtm_parse_commandline(void)
 
 static int recursive_loop(int a)
 {
-	char buf[1024];
+	char *buf;
+	int ret;
+
+	buf = kmalloc(1024, GFP_KERNEL);
+	if (!buf) {
+		printk(KERN_ERR "lkdtm : couldn't allocate buffer\n");
+		return -ENOMEM;
+	}
 
 	memset(buf,0xFF,1024);
 	recur_count--;
 	if (!recur_count)
-		return 0;
+		ret = 0;
 	else
-        	return recursive_loop(a);
+		ret = recursive_loop(a);
+
+	kfree(buf);
+	return ret;
 }
 
 void lkdtm_handler(void)
#1 lore raw

Hi Frank,

Quoted 6 lines · Frank Seidel

From: Frank Seidel <[email protected]>

Reduce stack memory footprint of lkdtm
(recursive_loop). From 1024 bytes on i386 down
to <10.

The intention here is infact to trigger a stack overflow. This module is used to test kernel dumping mechanism like kdump. So the expectation is that the kernel will dump as soon as the stack overflows.

Quoted 35 lines
---
 drivers/misc/lkdtm.c |   16 +++++++++++++---
 1 file changed, 13 insertions(+), 3 deletions(-)
drivers/misc/lkdtm.c +13 -3
@@ -225,14 +225,24 @@ static int lkdtm_parse_commandline(void)
 
 static int recursive_loop(int a)
 {
-	char buf[1024];
+	char *buf;
+	int ret;
+
+	buf = kmalloc(1024, GFP_KERNEL);
+	if (!buf) {
+		printk(KERN_ERR "lkdtm : couldn't allocate buffer\n");
+		return -ENOMEM;
+	}
 
 	memset(buf,0xFF,1024);
 	recur_count--;
 	if (!recur_count)
-		return 0;
+		ret = 0;
 	else
-        	return recursive_loop(a);
+		ret = recursive_loop(a);
+
+	kfree(buf);
+	return ret;
 }
 
 void lkdtm_handler(void)
Signature · 5 lines
Regards,
Ankita Garg ([email protected])
Linux Technology Center
IBM India Systems & Technology Labs, 
Bangalore, India   
#2 lore raw
Quoted 3 lines · Ankita Garg

The intention here is infact to trigger a stack overflow. This module is used to test kernel dumping mechanism like kdump. So the expectation is that the kernel will dump as soon as the stack overflows.

Oh, i see. Then this patch of course doesn't make sense.

Thanks,
Frank

#4 lore raw
In reply to Bernd Petrovitsch

Hi Bernd,

Quoted 13 lines · Bernd Petrovitsch

Hi!

Quoted 10 lines · Ankita Garg

Hi Frank,

Quoted 6 lines · Frank Seidel

From: Frank Seidel <[email protected]>

Reduce stack memory footprint of lkdtm
(recursive_loop). From 1024 bytes on i386 down
to <10.

Quoted 8 lines
Quoted 3 lines

The intention here is infact to trigger a stack overflow. This module is used to test kernel dumping mechanism like kdump. So the expectation is that the kernel will dump as soon as the stack overflows.

That answers why the variable exists at all. It is only zeroed and never else used.
Hmm, adding the above as a comment makes probably sense.

There is some text at the head of the module file that explains what the module does and the usage, etc. I suppose that would be sufficient ?

Signature · 5 lines
Regards,
Ankita Garg ([email protected])
Linux Technology Center
IBM India Systems & Technology Labs, 
Bangalore, India   
#3 lore raw
In reply to Ankita Garg

Hi!

Quoted 5 lines · Ankita Garg

Hi Frank,

Quoted 2 lines · Frank Seidel

From: Frank Seidel <[email protected]>

Quoted 8 lines
Quoted 4 lines

Reduce stack memory footprint of lkdtm
(recursive_loop). From 1024 bytes on i386 down
to <10.

The intention here is infact to trigger a stack overflow. This module is used to test kernel dumping mechanism like kdump. So the expectation is that the kernel will dump as soon as the stack overflows.

That answers why the variable exists at all. It is only zeroed and never else used.
Hmm, adding the above as a comment makes probably sense.

Quoted 34 lines
Quoted 34 lines
---
 drivers/misc/lkdtm.c |   16 +++++++++++++---
 1 file changed, 13 insertions(+), 3 deletions(-)
drivers/misc/lkdtm.c +13 -3
@@ -225,14 +225,24 @@ static int lkdtm_parse_commandline(void)
 
 static int recursive_loop(int a)
 {
-	char buf[1024];
+	char *buf;
+	int ret;
+
+	buf = kmalloc(1024, GFP_KERNEL);
+	if (!buf) {
+		printk(KERN_ERR "lkdtm : couldn't allocate buffer\n");
+		return -ENOMEM;
+	}
 
 	memset(buf,0xFF,1024);
 	recur_count--;
 	if (!recur_count)
-		return 0;
+		ret = 0;
 	else
-        	return recursive_loop(a);
+		ret = recursive_loop(a);
+
+	kfree(buf);
+	return ret;
 }
 
Quoted 1 line

drivers/misc/lkdtm.c static int lkdtm_parse_commandline(void) · line 248

Quoted 1 line
drivers/misc/lkdtm.c +0 -0
 void lkdtm_handler(void)

Bernd

Signature · 3 lines
Firmix Software GmbH                   http://www.firmix.at/
mobil: +43 664 4416156                 fax: +43 1 7890849-55
          Embedded Linux Development and Services