Thread (11 messages) 11 messages, 5 authors, 2012-10-21

where are the bug ?

From: Rohan Puri <hidden>
Date: 2012-10-20 14:53:17

On Sat, Oct 20, 2012 at 7:35 AM, Fan Yang [off-list ref] wrote:

2012/10/19 Rohan Puri [off-list ref]
quoted

On Fri, Oct 19, 2012 at 7:38 PM, Anuz Pratap Singh Tomar <
chambilkethakur at gmail.com> wrote:
quoted

On Fri, Oct 19, 2012 at 2:46 PM, Fan Yang [off-list ref] wrote:
quoted

2012/10/19 Arun KS [off-list ref]
quoted
Hi Fan,

On Fri, Oct 19, 2012 at 6:50 PM, Fan Yang [off-list ref]
wrote:
quoted
quoted
HI ALL:
    I just run a module on my machine, but it  can't work. When the
module run the kernel will painc. I don't know where is wrong. This is my
code:
quoted
quoted
 1 #include<linux/module.h>
  2 #include<linux/kernel.h>
  3 #include<linux/init.h>
  4 #include<linux/sched.h>
  5
  6 int input = 1;
  7 module_param (input, int, S_IRUGO);
  8
  9 static int __init printvma_init (void)
 10 {
 11     struct vm_area_struct *p, *start;
 12     int i;
 13     struct task_struct *thread;
quoted
quoted
 14
 15     thread = current;
 16
 17     while (1)
 18     {
 19         if (thread->pid == input)
 20             break;
 21         thread = list_entry (thread->tasks.next, struct
task_struct, tasks);
quoted
quoted
 22     }
 23     p = thread->mm->mmap;
 24
 25     do{
 26         printk ("%lx\t%lx\t%s\n", p->vm_start,\
 27                 p->vm_end, p->vm_file->f_path.dentry->d_iname);
 28         p = p->vm_next;
 29     }while (p != NULL);
 30
 31     printk ("vm_file address is:%d\tf_path address is:%d\
 32             \tname is:%s",& p->vm_file->f_path,\
 33             p->vm_file->f_path.dentry->d_iname);
 34
 35     printk ("info from the kernel space:%s\n", thread->comm);
 36     return 0;
 37 }
 38
 39 static void __exit printvma_exit (void)
 40 {
 41     printk ("the module will leave the kernel space..\n");
 42 }
 43
 44 module_init (printvma_init);
 45 module_exit (printvma_exit);
 46 MODULE_LICENSE ("GPL");


what's wrong?

It would be good if you paste your crash log here.

Thanks,
Arun
quoted

thanks

_______________________________________________
Kernelnewbies mailing list
Kernelnewbies at kernelnewbies.org
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
The module run in a virtual machine, I can't control the machine when
it crashed, so I just got a picture when the kernel panic.

you can run the module under uml, it wont be hard to copy  the crash
log from terminal in uml.
quoted



Thanks
Fan

_______________________________________________
Kernelnewbies mailing list
Kernelnewbies at kernelnewbies.org
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
_______________________________________________
Kernelnewbies mailing list
Kernelnewbies at kernelnewbies.org
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
Hi Fan,

See the issue is thread->mm is NULL in your case. The simplest way to
test this in your case is by the following : -

Put these statements after the while loop

if(!thread->mm) { printk("thread->mm is NULL\n"); return 0; }

After this compile and load the module, you will see this statement
printed in dmesg command output.


General programming practice : -

Always make checks for NULL pointer in your code, before dereferencing
your code.

- Rohan
Hi Rohan,

I don't think the thread->mm is NULL, because when I print the several
vm_area_struct of the thread->mm it work well, but if put the code in the
loop to print all the vma, it crashed.

Thinks
Fan
Hi Fan,

Yes Fan, you are right, its NOT thread->mm NULL, but p->vm_file is NULL, to
verify put the following as the fist statement in do {}while; loop

if(!p->vm_file) { printk("p->vm_file NULL\n"); return 0;}


This message gets printed to kernel log buffer.

Also, you still need to NULL check pointer before dereferencing them. Let
me know, whats the result on your system.

- Rohan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20121020/18595f45/attachment-0001.html 
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help