[Ilugc] Communicating From User Space to Kernel Space

  • From: ilugsuman@xxxxxxxxx (Suman Adak)
  • Date: Mon Sep 11 11:18:42 2006

hi Shakthi and all ,

Yes before that i read this article and implemented some bad coding which
has been showing on that article. Don't try this code in vendor's
kernel.InFC5 doesn't  export sys_open,sys_write system call. But a
fresh vanilla
kernel could do. The question was how to read file from user space to kernel
space efficiently .  And more ever i used to wonder how many configuration
files are being read by kernel? I tried to give answer as per my knowledge.
Please correct me

. More ever i and amit submitted one paper at ILUG-Delhi annual festival
Freedel 2006. It has been selected and amit is going to give talk. We have
proposed one host based intrusion detection and prevention system. Our
approach is like , User space will act as a detection system and gather
intrusion knowledge. After some time it will pass this info to kernel where
packets with intrusion would be blocked at IP layer.We are not thinking
about performance now. We just want to implement it. And yes i could read
the file using sys_open(), sys_read() kernel system call. But AFIK we had
several solution to do that job.
Might be amit has posted this to know better solution from other kernel
programmer.
1) implementing a char device and  ioctl() system call and creating /proc
entry
2) using kernel system call which has been exported by kernel
3)  create and use sysfs files within a kernel module.
4) using netlink socket.
[Sorry: All solutions have been suggested by other member. Thanks to all. I
just wrote it to summarize the whole things to keep in mind that later
anybody could get help from that].

But the question is that why we shouldn't read or write files in kernel
space? And what is the efficient way to do that?does kernel actually reads
or writes files?

The only one reason that i could find , "where" and "how" files would be
located and loaded . and it is policy decision in the linux community that
we shouldn't do. The problem is , where this config file lives? Is there any
particular location where all config file can stay and read by kernel. If i
am correct, the various same config file location could be different in
different distribution. So one my kernel module can run only one
distribution. It is not guaranteed that it will run in different
distribution.

And yes how to load the config files. May today u r using very simple file
but tomorrow you could use very complex database file and in that case
kernel doesn't have more flexibility to handle such file.

So many kernel hackers suggest not to read and write file in kernel space.
But what is the solution?

Yes as per my knowledge, We could do like
1) Implement file reading and writing in user space
2) communicate vis /proc entry.

 I can give some example
1.Mounting file system [ mount program reads config file /etc/fstab and
issue mount system call]

2.Netfilter filrewalls gets rule from user space application[iptables which
read the configuration file and communication with kernel via socket]
3. Many more.....


I think i should write one article with example.....hope i will finish as
early as possible..

Thanks
Suman



On 9/10/06, Shakthi Kannan <cyborg4k@xxxxxxxxx> wrote:


Hi Amit,

--- amit saha <dandolls@xxxxxxxxxxx> wrote:
Now I would like to read the same file in
kernel space by a
kernel module

Don't do that. Please read:

"Driving Me Nuts - Things You Never Should Do in the
Kernel"
By Greg Kroah-Hartman

http://www.linuxjournal.com/article/8110

SK

--
Shakthi Kannan
http://www.shakthimaan.com

__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
_______________________________________________
To unsubscribe, email ilugc-request@xxxxxxxxxxxxx with
"unsubscribe <password> <address>"
in the subject or body of the message.
http://www.ae.iitm.ac.in/mailman/listinfo/ilugc

Other related posts: