Loading...
Creating an interactive char driver is surprisingly simple, but there are a few traps along the way.
This is by far the hardest part to understand, but honestly a full understanding isn't really necessary. The new intro_init
function looks like this:
A major number is essentially the unique identifier to the kernel module. You can specify it using the first parameter of register_chrdev
, but if you pass 0
it is automatically assigned an unused major number.
We then have to register the class and the device. In complete honesty, I don't quite understand what they do, but this code exposes the module to /dev/intro
.
Note that on an error it calls class_destroy
and unregister_chrdev
:
These additional classes and devices have to be cleaned up in the intro_exit
function, and we mark the major number as available:
In intro_init
, the first line may have been confusing:
The third parameter fops
is where all the magic happens, allowing us to create handlers for operations such as read
and write
. A really simple one would look something like:
The parameters to intro_read
may be a bit confusing, but the 2nd and 3rd ones line up to the 2nd and 3rd parameters for the read()
function itself:
We then use the function copy_to_user
to write QWERTY
to the buffer passed in as a parameter!
Create a really basic exploit.c
:
If the module is successfully loaded, the read()
call should read QWERTY
into buffer
:
Success!
Loading...