Square Galaxy

Tag: Kernel

Death by writing files from the kernel

by Jacob on Mar.21, 2008, under Technical

I’ve written my first semi-major Linux device driver. I won’t say exactly what it does other than write data out to hardware.

Generally, it is well NOT accepted to write to files from the kernel. If you ask how, people will tell you “don’t.” I completely agree with all of the reasons provided, but I decided to do it anyway.

The hardware I’m writing data to isn’t readily available. I wanted to be able to test my code well without having to have the hardware available. So I wrote in some non-release, non-production code that writes data to a file instead of to hardware, but only for testing purposes. When in this simulation mode, the user can interact with the driver and data gets written to the file instead of to hardware, and then the file can be checked for accuracy.

User writes to driver -> kernel driver handles write -> driver writes to file

Easy enough? I thought so until I tried writing to the driver as a regular system user. I chmod’ed the driver so that the user had full privileges to read and write to the file. When root would write to the driver, everything worked, when the regular user would write to the driver, the kernel would crash.

The problem was that the user didn’t have write permissions to the test file that the driver was writing to. I thought the kernel level driver could write to any file it wanted, but apparently, the user’s permissions to the file permeated through the kernel driver. Changing the files permissions fixed things so they didn’t crash any more.

The caps lock and scroll lock lights blink on the keyboard when the kernel crashes. Not quite fireworks, but still kind of cool. Development in a virtual machine is key, so that you really don’t crash your computer, just the virtual machine.

Leave a Comment :linux, Software Engineering more...

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!

 

November 2008
M T W T F S S
« Oct    
 12
3456789
10111213141516
17181920212223
24252627282930