Simple kernel module for Linux & Windows that can accept a string from the user-space application and then return the string in reverse.
sudo apt-get install build-essential linux-headers-$(uname -r)
- Clone the source code
git clone git@github.com:nguyenhien1994/simple-kernel-module.git
cd simple-kernel-module
-
Build kernel module and test program with
make
-
Insert kernel module into the Linux Kernel
sudo insmod module/reverse_string.ko
-
Update your test string to
./test/test.txt
-
Run the test program with
sudo ./test/test ./test/test.txt
-
Remove module after using
sudo rmmod module/reverse_string.ko
-
All above steps are done via
run.sh
script. Just run this script withbash run.sh
- With small string size:
hiennm@hiennm-sb-virt:~/projects/github/simple-kernel-module$ sudo ./test/test ./test/test.txt
Input: Hien Nguyen Minh
Output: hniM neyugN neiH
- With large string size (2KB):
hiennm@hiennm-sb-virt:~/projects/github/simple-kernel-module$ sudo ./test/test ./test/test.txt
Input: GPEXUPKGBrWHVNEhHE8joM6fK6Diyb9VUAIEp06fC4B2AYZSh0HpbYN1LCUXRkXsvgTrmNN0hwjp1kFy6wPIrqxQRyy1xcdkIO1oVgHZYk2sU0IljQGfgsk9QEcFWhR6UP4aZ3H46NCyldYkhsH9PNPFGACqbXbFNVYp7BfJR3H9JdoPokgbutFewlNg0N8IBnN3yMSFDtLhuH1hoavhi6hMtj5XyUMfXDLtfjgu0rNa7DryVKpIrOukGNRSZkHhObTu637sGAkIoUjooWZnUfeHHGh2GlBbl6REFJODLPOCbnBAuWZQmIvVKsvoMLdyH0BA06QUqS2yV18CiuDHZM23IKK7AvfMtbJd3Jun56YoEup2zDuqOLkzdAIVKXfXzgRdmq39l5IJMLb0aDDadXPYnoffbGo2IN9v4s8KdBIl9Pl5Pk9Lmom5rWPttV2Bm2u8e1arTTO6hNuprH09SJCbQ2yDFpsRw3h9VK2vTitAWFCMnKhq9BGVa1ItPZrbbCwMvWGdTWNEq2CVyzzPY9X92J5RqYS6G2QmsOaSVqR1AeO6m0efZ8cgTko7P36h5jBoZaex7DiMtkgGpmuqEFmTqcSHuHkaRlSxNJwo3fpFlUSikVh2Fsktxndj8n3g5fO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aoh1HuhLtDFSMy3NnBI8N0gNlweFtubgkoPodJ9H3RJfB7pYVNFbXbqCAGFPNP9HshkYdlyCN64H3Za4PU6RhWFcEQ9ksgfGQjlI0Us2kYZHgVo1OIkdcx1yyRQxqrIPw6yFk1pjwh0NNmrTgvsXkRXUCL1NYbpH0hSZYA2B4Cf60pEIAUV9byiD6Kf6Moj8EHhENVHWrBGKPUXEPG
- Handle file with multiple lines?
- Load/unload in the userspace program with
system()
/libkmod
- Use mmap or netlink?
- Since the module is only test on
4.19.0-17-amd64
, so maybe a bug on other kernel versions.