Modified Version of Linux Kernel
ajmi@burner:~$ uname -mrs
Linux 5.13.0-1031-azure x86_64
sudo apt update
sudo apt upgrade
sudo apt install build-essential libncurses-dev bison flex libssl-dev libelf-dev dwarves zstd
git clone https://github.com/JameelKaisar/linux-kernel.git
cd linux-kernel
cp -v /boot/config-$(uname -r) .config
sudo make menuconfig
- Save and Exit
sudo nano .config
- Set CONFIG_SYSTEM_TRUSTED_KEYS to ""
- Set CONFIG_SYSTEM_REVOCATION_KEYS to ""
sudo make -j$(nproc)
sleep 5 && echo start > ~/start.txt && sudo make -j$(nproc) > ~/logs.txt 2> ~/errors.txt && echo success > ~/success.txt || echo fail > ~/fail.txt & disown
- Turns out we can use
screen
window manager instead of using the so-called Secret Command.screen
can be installed usingsudo apt install screen
.
sudo make modules_install -j$(nproc)
sudo make install -j$(nproc)
sudo update-initramfs -c -k 5.19.0-rc3
sudo update-grub
sudo reboot
ajmi@burner:~$ uname -mrs
Linux 5.19.0-rc3 x86_64
Return number from a system call
#include <stdio.h>
#include <linux/kernel.h>
#include <sys/syscall.h>
#include <unistd.h>
int main()
{
long int n = syscall(451);
printf("System Call sys_retint Returned: %ld\n", n);
return 0;
}
System Call sys_retint Returned: 2022
Swap numbers using a system call
#include <stdio.h>
#include <linux/kernel.h>
#include <sys/syscall.h>
#include <unistd.h>
int main()
{
int a = 1;
int b = 2;
printf("Before Swapping: a = %d, b = %d\n", a, b);
syscall(452, &a, &b);
printf("After Swapping: a = %d, b = %d\n", a, b);
return 0;
}
Before Swapping: a = 1, b = 2
After Swapping: a = 2, b = 1
Reverse string using a system call
#include <stdio.h>
#include <linux/kernel.h>
#include <sys/syscall.h>
#include <unistd.h>
int main()
{
char s[10] = "abcdefg";
printf("Before Reversing: %s\n", s);
syscall(453, s, 10);
printf("After Reversing: %s\n", s);
return 0;
}
Before Reversing: abcdefg
After Reversing: gfedcba
Copy array using a system call
#include <stdio.h>
#include <linux/kernel.h>
#include <sys/syscall.h>
#include <unistd.h>
int main()
{
int a[7] = {1, 2, 3, 4, 5, 6, 7};
int b[7];
printf("Initial Array: ");
for (int i=0; i<7; i++)
printf("%d ", a[i]);
printf("\n");
syscall(454, a, b, 7);
printf("Copied Array: ");
for (int i=0; i<7; i++)
printf("%d ", b[i]);
printf("\n");
return 0;
}
Initial Array: 1 2 3 4 5 6 7
Copied Array: 1 2 3 4 5 6 7
Swap members of structure using a system call
#include <stdio.h>
#include <linux/kernel.h>
#include <sys/syscall.h>
#include <unistd.h>
struct swap_srt {
int a;
int b;
};
int main()
{
struct swap_srt s;
s.a = 1;
s.b = 2;
printf("Before Swapping: s.a = %d, s.b = %d\n", s.a, s.b);
syscall(455, &s);
printf("After Swapping: s.a = %d, s.b = %d\n", s.a, s.b);
return 0;
}
Before Swapping: s.a = 1, s.b = 2
After Swapping: s.a = 2, s.b = 1
Reverse array in structure using a system call
#include <stdio.h>
#include <stdlib.h>
#include <linux/kernel.h>
#include <sys/syscall.h>
#include <unistd.h>
struct reverse_srt {
int *arr;
int n;
};
int main()
{
struct reverse_srt s;
s.n = 7;
s.arr = malloc(s.n * sizeof(int));
for (int i=0; i<s.n; i++)
s.arr[i] = i+1;
printf("Before Reversing: ");
for (int i=0; i<7; i++)
printf("%d ", s.arr[i]);
printf("\n");
syscall(456, &s);
printf("After Reversing: ");
for (int i=0; i<7; i++)
printf("%d ", s.arr[i]);
printf("\n");
return 0;
}
Before Reversing: 1 2 3 4 5 6 7
After Reversing: 7 6 5 4 3 2 1