/dev/greet: Invading Kernel Space

If you’ve ever looked in /dev you will have seen devices like cdrom and sda to denote storage mediums. You’ll have also seen tty and com devices. These all act as a bridge between OS and hardware. You may also have seen pseudo-devices such as /dev/urandom and /dev/null which like to think and act like a real device, but in reality are just files playing pretend. We’re going to play pretend too by building a kernel module and pseudo-device which will allow us to get the approriate greeting for the time of day.

A lot of the heavy lifting for this project comes from this blog post

The code for this monstrosity can be found here, should you want to build along. If so, you’ll need to get the linux kernel source for your distro. I decided to experiment with this kernel module on Linux (Debian in particular) rather than my default OpenBSD, because the barrier to entry for loading random shit into the kernel is too high on OpenBSD. Make of that what you will. The code compiles with a few warnings that only real programmers care about.

You can install the kernel module by running

% make
% make install

After this has been done, you can verify that it works by examining the contents of the file

% cat /dev/greet
Good morning

The most important command is to remove the module from your system, which is done by running make uninstall.


Do you have a comment to make on this post? Start a discussion in my public inbox by emailing ~ols/public-inbox@lists.sr.ht. You can see the inbox here.