Re: How to access a regular file from within a module ?

From: Ben Nizette
Date: Mon Jan 12 2009 - 17:26:30 EST


On Mon, 2009-01-12 at 07:51 -0800, Jose Luis Marchetti wrote:

> OK, that is clear now.
> From all I read, it is possible to access files from within inside the kernel, but it would not be a good practice, thanks for the insights.
> >

I don't know why no-one's brought this up already but no, it usually
isn't even possible. As previously mentioned, you will hijack the
current user context to do your file operations. That context may be in
a different filesystem namespace (eg due to chroot'ing) and as such
*won't even be able to see the file you're trying to hit*.

Even if you create a new kernel thread which is parented to init you'll
get a consistent view of files but it's still very hard to know it's the
*right* view of files.

http://kernelnewbies.org/FAQ/WhyWritingFilesFromKernelIsBad

--Ben.


--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/