<html>
<head>
<style><!--
.hmmessage P
{
margin:0px;
padding:0px
}
body.hmmessage
{
font-size: 10pt;
font-family:΢ÈíÑźÚ
}
--></style></head>
<body class='hmmessage'><div dir='ltr'>
i don't know why you want to corrupt kernel stack by using this method, stack usually grow from high address to low address, <BR>if you allocate a buff in a function then use memset(), it is writing data from low address to high address.<BR>in your implementation, you allocate an array with 8000*4=32000 bytes ( int arr[8000]; ), then you try to corrupt stack by using memset(), which operate memory by bytes, rather than by int. so this memset() only corrupt the first 8192 bytes of the buffer, which is far away from your current task stack. <BR> <BR> thread_info locates at the bottom of current task's stack, please reference the source code of current_thread_info() function of your platform. i think it is true for X86 or ARM.<BR> <BR> if you really want to corrupt current kernel task's stack, please try below code, i did't test it but i think it should work, at least you can find something from the log:<BR> <BR> char *sp_addr;<br> struct thread_info *thread = current_thread_info();<BR> sp_addr = (char*)thread;<br> <br> printk("sp_addr==thread:%p, task:%p\n", thread, thread->task);<br> <br> memset (sp_addr, 0x0, 1024);<br> <br> printk("after corrupt, task:%p, it is dying...\n", thread->task);<br><br> <BR><div><div id="SkyDrivePlaceholder"></div>> Date: Thu, 13 Sep 2012 15:32:05 +0530<br>> Subject: Re: kernel stack memory<br>> From: mujeeb.adil@gmail.com<br>> To: getarunks@gmail.com<br>> CC: shubham20006@gmail.com; kernelnewbies@kernelnewbies.org<br>> <br>> Hi,<br>> <br>> On Thu, Sep 13, 2012 at 1:59 PM, Arun KS <getarunks@gmail.com> wrote:<br>> > Hello Shubham,<br>> ><br>> > On Thu, Sep 13, 2012 at 12:15 PM, shubham sharma <shubham20006@gmail.com><br>> > wrote:<br>> >><br>> >> Hi,<br>> >><br>> >> As far as i know, the size of stack allocated in the kernel space is<br>> >> 8Kb for each process. But in case i use more than 8Kb of memory from<br>> >> the stack then what will happen? I think that in that case the system<br>> >> would crash because i am accessing an illegal memory area. I wrote<br>> >> kernel module in which i defined an integer array whose size was 8000.<br>> >> But still it did not crash my system. Why?<br>> >><br>> >> The module i wrote was as follows:<br>> >><br>> >> #include <linux/kernel.h><br>> >> #include <linux/module.h><br>> >><br>> >> int __init init_my_module(void)<br>> >> {<br>> >> int arr[8000];<br>> >> printk("%s:%d\tmodule initilized\n", __func__, __LINE__);<br>> >> arr[1] = 1;<br>> >> arr[4000] = 1;<br>> >> arr[7999] = 1;<br>> ><br>> > Instead do a memset.<br>> > memset(arr, 0, 8192);<br>> ><br>> > If you do this the current calling process thread_info will be set to zero.<br>> > This should cause a crash.<br>> <br>> I tried and this is also not causing any crash.<br>> <br>> Thanks,<br>> Adil<br>> ><br>> > Thanks,<br>> > Arun<br>> ><br>> ><br>> >><br>> >> printk("%s:%d\tarr[1]:%d, arr[4000]:%d, arr[7999]:%d\n", __func__,<br>> >> __LINE__, arr[1], arr[4000], arr[7999]);<br>> >> return 0;<br>> >> }<br>> >><br>> >> void __exit cleanup_my_module(void)<br>> >> {<br>> >> printk("exiting\n");<br>> >> return;<br>> >> }<br>> >><br>> >> module_init(init_my_module);<br>> >> module_exit(cleanup_my_module);<br>> >><br>> >> MODULE_LICENSE("GPL");<br>> >><br>> >> _______________________________________________<br>> >> Kernelnewbies mailing list<br>> >> Kernelnewbies@kernelnewbies.org<br>> >> http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies<br>> ><br>> ><br>> ><br>> > _______________________________________________<br>> > Kernelnewbies mailing list<br>> > Kernelnewbies@kernelnewbies.org<br>> > http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies<br>> ><br>> <br>> _______________________________________________<br>> Kernelnewbies mailing list<br>> Kernelnewbies@kernelnewbies.org<br>> http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies<br></div>                                            </div></body>
</html>