LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Kernel (https://www.linuxquestions.org/questions/linux-kernel-70/)
-   -   how to avoid write file from a kernel module (https://www.linuxquestions.org/questions/linux-kernel-70/how-to-avoid-write-file-from-a-kernel-module-660565/)

xiaozhe2000 08-05-2008 04:33 AM

how to avoid write file from a kernel module
 
There are lots of data I want to output from my module. Generally, I'll use the method that write these data to a file. But It seems that kernel developer don't recommend this way.
So I want to know whether we have a better method to deal with that case, if not write file from kernel module.
Thanks!

jiml8 08-05-2008 02:44 PM

You cannot do a write from a kernel module.

Look into the copy_to_user() command. You might also want to consider memory mapping.

You do your writes from a user program, not a kernel module. The user program first reads the data using your module, then writes it as required.

xiaozhe2000 08-05-2008 09:43 PM

thanks, and could you please explain more about "memory mapping"? May be I could write my data to kernel space memory and map it to user space. I think that is the thing I need. Is there a good article depicting that technique?

liri 09-17-2008 07:09 AM

performing file operations from within a kernel driver
 
Quote:

Originally Posted by jiml8 (Post 3237779)
You cannot do a write from a kernel module.

Look into the copy_to_user() command. You might also want to consider memory mapping.

Well, I wouldn't say that it's impossible.
But I'm now finding myself in the same situation where I need to perform some file operations from within my kernel driver.


I was pondering about performing file operations from inside the
kernel. Say we talk about a driver that is compiled within the kernel or an LKM which is loadable - it is possible to perform file operations such as open, read and write from inside the kernel using the provided sys_* functions such as sys_open and the rest.


My question is, how is it possible to specify to the open syscall upon
which user permissions to use?
If you investigate the sys_open function you'll see that at some point
(allocation) it uses the current pointer to grab the uid and gid upon which to check for permissions.


How is this a problem?
Well if the sys_open is called from a user process then that's normal
because the user process has been interrupted and THAT process will be what the current pointer address to, but if we're doing it all in kernel then the current point will be of some random process which we have no affiliation with...


So, what do you think? is it possible to explicitly provide a
task_struct of a dummy process which I created on my own to functions like sys_open?


I'd be happy to hear your thoughts and ideas about this.


Regards,
Liran.


All times are GMT -5. The time now is 08:15 PM.