Begginer in LKM doubts...

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

 



Hello,

I started to read docs and examples about LKM, and i
have some doubts, if someone could help me. :)

1 - In the nowsday is necessary use  get_user(),
put_user(), copy_from_user(),copy_to_user() to
transform from kernel to user memory and vice-versa ?
Or it's automatically actually ? I'm asking it because
i can manipulate normal data received directilly as
argument from syscall without use this functions (as
described in text that i'm reading). :)

2 -  I saw that i must use get_fs() and set_fs() to
access DS (data segment) from kernel or User space,
and in article it's describe that it can be used to
"execute" libc functions over kernel. So i tryed it:

int uid;
mm_segment_t old_fs;

old_fs = get_fs();
set_fs(get_ds());
uid  = getuid();

printk("\nUID %d",uid);

set_fs(old_fs);

But when i try insmod it:

libc-set_fs.o: unresolved symbol getuid

Ok, i know that i can get my uid via current struct,
but i want to know how to i execute libc functions
over kernel. How to do it ? Can someone give me a
example ? :)

3 - In the article we created a basic device driver
like that:

/*just a dummy for demonstration*/
static int driver_open(struct inode *i, struct file
*f){
 printk("<1>Open Function\n");
 return 0;
}

/*register every function which will be provided by
our driver*/
static struct file_operations fops = {
NULL,                 /*lseek*/
NULL,                 /*read*/
NULL,                 /*write*/
NULL,                 /*readdir*/
NULL,                 /*select*/
NULL,                 /*ioctl*/
NULL,                 /*mmap*/
driver_open,          /*open, take a look at my dummy
open function*/
NULL,                 /*release*/
NULL                  /*fsync...*/
};

int init_module(void){
 /*register driver with major 40 and the name driver*/
 if(register_chrdev(40, "driver", &fops)) return -EIO;
  return 0;
}

void cleanup_module(void){
 /*unregister our driver*/
 unregister_chrdev(40, "driver");
}

So i created the device with mknod and tryed "open"
with cat, echo, etc, but it never print the  "Open
Function" from printk(), why ?

4 - Other intersting thing is that we can re-use
exported symbols, so i tryed to test and import the
vfat_rmdir and do it return 0 to doesn't remove my dir
over fat (only to test, to learn how to work import a
exported symbol), i done like that:

/* Get vfat_rmdir exported function */
extern int *vfat_rmdir_Rc0ad670e;

/* Our faked vfat_mkdir */
int *new_vfat_rmdir(struct inode *dir, struct dentry
*dentry){

 return 0;

}

int init_module(void) {

 vfat_rmdir_Rc0ad670e=new_vfat_rmdir;
 return 0;

}

void cleanup_module(void){

}

And it really can't remove dir under fat with "rm",
but when i type "rm" i receive a dump from kernel, and
i can't access more fat fs! :(

Why ? What i done wrong ? 

5 - Relax, this is the last dummy question! :)
I went to define my module over GPL, then i setted:

#include <asm/unistd.h>
#include <stdio.h>
#include <errno.h>

MODULE_LICENSE("GPL");

But, when i insmod it say that i "tainted the kernel".
:/ What is wrong ?

Thkz a lot and sorry for idiot questions.

Regards


	
	
		
_______________________________________________________
Yahoo! Mail agora com 100MB, anti-spam e antivírus grátis!
http://br.info.mail.yahoo.com/

--
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