Re: kernel stack memory

2012-09-16 Thread Rajat Sharma
Some useful debugging options:

CONFIG_DEBUG_STACK_USAGE
CONFIG_DEBUG_STACKOVERFLOW

 if you take enough large array so as to hit the heap
 area at that present moment (they both grow towards each other)

I doubt if it is true for kernel mode stack. Kernel stack allocation is
plain pages allocation using zone buddy allocator (alloc_pages_node), so
what is beyond that page, allocated to something else or not is really not
predictable. However one thing which is predictable (and other people have
pointed out as well) is overrunning thread_info struct of the current task.
Also this overrun may not show up with this simple module, because there is
no need to access thread_info here. My suggestions:

   1. Try putting a schedule call after overrunning thread_info structure,
   thread_info might be accessed while scheduling back current process.
   2. Try to access current macro after overrun, it will try do access
   corrupt thread_info structure to get task_struct pointer.

But make sure to corrupt the thread_info structure in predictive manner as
pointed out in previous mails :).
-Rajat

On Sun, Sep 16, 2012 at 10:35 AM, Shreyansh Jain shrey.li...@gmail.com
wrote:
 Hi 卜弋天 and list,

 Please find my comments inline

 On Thu, Sep 13, 2012 at 7:38 PM, 卜弋天 bu...@live.cn wrote:
 i don't know why you want to corrupt kernel stack by using this method,
 stack usually grow from high address to low address,
 if you allocate a buff in a function then use memset(), it is writing
data
 from low address to high address.
 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.

   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.

   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:

  char *sp_addr;
  struct thread_info *thread = current_thread_info();
  sp_addr = (char*)thread;

  printk(sp_addr==thread:%p, task:%p\n, thread, thread-task);

  memset (sp_addr, 0x0, 1024);

  printk(after corrupt, task:%p, it is dying...\n, thread-task);

 Actually, after reading through the first authors email, it seems he
 is trying to find the answer to How much is maximum allocatable space
 on the Kernel Stack (Shubham, please correct me if  I am wrong).

 In that essence what you have mentioned above is more of a direct
 method of corrupting the thread_info structure - a definitive stack
 corruption.



 Date: Thu, 13 Sep 2012 15:32:05 +0530
 Subject: Re: kernel stack memory
 From: mujeeb.a...@gmail.com
 To: getaru...@gmail.com
 CC: shubham20...@gmail.com; kernelnewbies@kernelnewbies.org


 Hi,

 On Thu, Sep 13, 2012 at 1:59 PM, Arun KS getaru...@gmail.com wrote:
  Hello Shubham,
 
  On Thu, Sep 13, 2012 at 12:15 PM, shubham sharma
  shubham20...@gmail.com
  wrote:
 
  Hi,
 
  As far as i know, the size of stack allocated in the kernel space is
  8Kb for each process. But in case i use more than 8Kb of memory from
  the stack then what will happen? I think that in that case the system
  would crash because i am accessing an illegal memory area. I wrote
  kernel module in which i defined an integer array whose size was
8000.
  But still it did not crash my system. Why?
 
  The module i wrote was as follows:
 
  #include linux/kernel.h
  #include linux/module.h
 
  int __init init_my_module(void)
  {
  int arr[8000];
  printk(%s:%d\tmodule initilized\n, __func__, __LINE__);
  arr[1] = 1;
  arr[4000] = 1;
  arr[7999] = 1;
 
  Instead do a memset.
  memset(arr, 0, 8192);
 
  If you do this the current calling process thread_info will be set to
  zero.
  This should cause a crash.

 I tried and this is also not causing any crash.

 Thanks,
 Adil
 
  Thanks,
  Arun
 
 
 
  printk(%s:%d\tarr[1]:%d, arr[4000]:%d, arr[7999]:%d\n, __func__,
  __LINE__, arr[1], arr[4000], arr[7999]);
  return 0;
  }
 
  void __exit cleanup_my_module(void)
  {
  printk(exiting\n);
  return;
  }
 
  module_init(init_my_module);
  module_exit(cleanup_my_module);
 
  MODULE_LICENSE(GPL);
 

 Though I don't have an exact answer, but what I understand is that
 there is no limit imposed by the kernel while writing in the kernel
 layer (as Kshemendra's first post pointed out). Thus, you keep writing
 what you wish till either you corrupt the next instruction set or some
 data structure which would be read somewhere in future (at that time
 what can happen is undefined). Assuming this understanding is some
 what correct, if you take enough large array so as to hit the heap
 area at that present moment (they both grow towards each other), you
 can have a undefined 

some problem about make menuconfig

2012-09-16 Thread g.wangweih...@gmail.com
hello all:
I had a problem. I want to build a kernel-2.6.22.19 in my ubuntu which's
kernel is 3.2 for embedded platform. But i failed in the step of /make
menuconfig/.
It tips as this:
 kiongf@ubuntu:~/sigma/tarball.386/smp86xx_kernel_source_R2.6.22-35/linux$
 make menuconfig
 HOSTCC scripts/kconfig/lxdialog/checklist.o
 HOSTCC scripts/kconfig/lxdialog/inputbox.o
 HOSTCC scripts/kconfig/lxdialog/menubox.o
 HOSTCC scripts/kconfig/lxdialog/textbox.o
 scripts/kconfig/lxdialog/textbox.c: 在函数‘print_line’中:
 scripts/kconfig/lxdialog/textbox.c:323:9: 警告: 变量‘x’被设定但未被使
 用 [-Wunused-but-set-variable]
 scripts/kconfig/lxdialog/textbox.c:323:6: 警告: 变量‘y’被设定但未被使
 用 [-Wunused-but-set-variable]
 HOSTCC scripts/kconfig/lxdialog/util.o
 HOSTCC scripts/kconfig/lxdialog/yesno.o
 HOSTCC scripts/kconfig/mconf.o
 HOSTLD -static scripts/kconfig/mconf
 scripts/kconfig/lxdialog/checklist.o: In function `print_arrows':
 checklist.c:(.text+0x5a): undefined reference to `acs_map'
 checklist.c:(.text+0xbc): undefined reference to `acs_map'
 checklist.c:(.text+0x105): undefined reference to `acs_map'
 checklist.c:(.text+0x116): undefined reference to `acs_map'
 checklist.c:(.text+0x127): undefined reference to `acs_map'
 scripts/kconfig/lxdialog/checklist.o:checklist.c:(.text+0x138): more
 undefined references to `acs_map' follow
 scripts/kconfig/lxdialog/checklist.o: In function `dialog_checklist':
 checklist.c:(.text+0x46d): undefined reference to `stdscr'
 checklist.c:(.text+0x4c3): undefined reference to `COLS'
 checklist.c:(.text+0x4d7): undefined reference to `LINES'
 /usr/lib/gcc/i686-linux-gnu/4.6/../../../i386-linux-gnu/libncursesw.a(hashmap.o):(.text+0x9c2):
 more undefined references to `SP' follow
 /usr/lib/gcc/i686-linux-gnu/4.6/../../../i386-linux-gnu/libncursesw.a(lib_beep.o):
 In function `beep':
 (.text+0x5): undefined reference to `cur_term'
 /usr/lib/gcc/i686-linux-gnu/4.6/../../../i386-linux-gnu/libncursesw.a(lib_beep.o):
 In function `beep':
 (.text+0x1b): undefined reference to `putp'
 /usr/lib/gcc/i686-linux-gnu/4.6/../../../i386-linux-gnu/libncursesw.a(lib_beep.o):
 In function `beep':
 (.text+0x22): undefined reference to `_nc_flush'
 /usr/lib/gcc/i686-linux-gnu/4.6/../../../i386-linux-gnu/libncursesw.a(lib_hline.o):
 In function `whline':
I google for this problem, it says i didn't install the /ncurses.
/
 i libncurses5 - shared libraries for terminal handling
 i libncurses5-dbg - debugging/profiling libraries for ncurses
 i libncurses5-dev - developer's libraries for ncurses
But after I install the lib , it doesn't change.

The script /linux/scripts/kconfig/lxdialog///check-lxdialog.sh/ contain
these messages:
 ldflags()
 {
 for ext in so a dylib ; do
 for lib in ncursesw ncurses curses ; do
 $cc -print-file-name=lib${lib}.${ext} | grep -q /
 if [ $? -eq 0 ]; then
 echo -l${lib}
 exit
 fi
 done
 done
 exit 1
 }

 # Where is ncurses.h?
 ccflags()
 {
 if [ -f /usr/include/ncurses/ncurses.h ]; then
 echo '-I/usr/include/ncurses -DCURSES_LOC=ncurses.h'
 elif [ -f /usr/include/ncurses/curses.h ]; then
 echo '-I/usr/include/ncurses -DCURSES_LOC=ncurses/curses.h'
 elif [ -f /usr/include/ncurses.h ]; then
 echo '-DCURSES_LOC=ncurses.h'
 else
 echo '-DCURSES_LOC=curses.h'
 fi
 }
libncurses appear in /usr/lib ,and the head file appear in /usr/include.
 kiongf@ubuntu:/usr/lib$ ls | grep curse
 libncurses_g.a
 libncurses++_g.a
 libncurses.so.5.7
 libncurses++w_g.a
 libncursesw_g.a
 kiongf@ubuntu:/usr/include$ ls | grep ncurse
 ncurses_dll.h
 ncurses.h
 ncursesw
I have trapped in this problem for several days, please help me if you
have any good ideas.

Thanks.




___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies