Re: sys_create_module...

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Mon, 24 Mar 2003 19:06:52 +0530
"Omanakuttan" <omanakuttan@tataelxsi.co.in> wrote:

> Hi,
> I am trying to debug some code I have written. I could not understand some
> code in the kernel.
> function sys_create_module() in module.c
> As far as I understand the functionality is as follows.
> 
> in this mod is defined as a struct module *.
> checks the user is capable of loading the module.
> locks the kernel.
> the module name is taken from userspace into the variable 'name', defined
> locally. 
> memset the vmalloc-ed (module_map) pointer with zeros.
> set the size_of_struct to size of the module structure.
> Next statement 
> mod->name = (char *) (mod + 1) ; puzzles me.
> what does this statement do?
> if my knowledge of C is corrrect, since mod is a pointer of type struct module
> , mod+1 will point to ((void *) &mod)+(sizeof (*mod)), which is an invalid
> pointer here.
> Then how does this piece of code work?
> any idea?

Quite simple. Let's see it..
[..]
	if ((namelen = get_mod_name(name_user, &name)) < 0) {
                error = namelen;
                goto err0;
        }
        if (size < sizeof(struct module)+namelen) {
                error = -EINVAL;
                goto err1;
        }

As you can see, size can't be less than sizeof(struct module)+ namelen so you are
vmalloc'ing enough space for a (struct module) and LKM name.

[..]
	memset(mod, 0, sizeof(*mod));
        mod->size_of_struct = sizeof(*mod);
        mod->name = (char *)(mod + 1);

Now mod->name points to the first char below struct module....

        mod->size = size;
        memcpy((char*)(mod+1), name, namelen+1);

.... and you memcpy module name just there.

-- 
Regards,

Angelo Dell'Aera 'buffer' 
Emails : <buffer@antifork.org> 
	 <buffer@users.sourceforge.net>

Antifork Research, Inc.     
http://www.antifork.org
--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive:       http://mail.nl.linux.org/kernelnewbies/
FAQ:           http://kernelnewbies.org/faq/


[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux