# Open a file in kernel space and read some text



## samisecure (Jan 13, 2014)

Hi all,

I want to open _a_ file in kernel space and read some text from it and store it into a character array. How can I do that? Is there any code example that can guide me? I'm _a_ newbie in kernel programming and was confused from search result in Google.


----------



## j4ck (Jan 20, 2014)

Please let us know what exactly you want to do? Maybe we could find some other solutions.


----------



## saif (Apr 16, 2014)

I want to open a file, read/write from the file byte-by-byte. How can I do that?


----------



## StreamThreader (May 22, 2014)

Reading some file in kernel space is secure?


----------



## kpa (May 22, 2014)

StreamThreader said:
			
		

> Reading some file in kernel space is secure?



It could be secure if the reading mechanism is implemented properly. However, reading files directly from kernel space is not recommended because it introduces a dependency going in the wrong direction, from kernel to userland. Most often used solutions are like the one used by the PF firewall. The userland utility pfctl(8) handles reading and validation of the ruleset file(s) and it converts the rules into a binary representation that is fed to the kernel side of PF trough a special device, /dev/pf.


----------

