Re: Begginer in LKM doubts...

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

 



Danett song wrote:
Hello,
hi ,

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 ?
yes, it is.

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

yes, u would get that error because, you should be using sys_getuid() rather than getuid() , since the kernel doesnt know what getuid() is since, it is a userspace function, and after insmod or rather during insmod your module is being linked with the kernel ,libc would internally call sys_getuid() which is transparent to the user.


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 ? :)

int uid;
mm_segment_t old_fs;

old_fs = get_fs();
set_fs(get_ds());
uid = sys_getuid(); // kernel knows about sys_getuid() only !

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

set_fs(old_fs);


cheers,
Amith


[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