A3 - Add a new syscall 🤫

Add a new system call to the kernel

Outcomes:

Procedure:

  1. Using the appropriate SYSCALL_DEFINE* macro, define a function that behaves as follows:

    a) The function takes two arguments, a userspace pointer to a buffer of type char *, an integer specifying the size of the buffer of type size_t.

b) The function copies a string into the userspace buffer containing the student’s name and the name of the executable binary that is running.
c) The function returns the length of the string copied upon sucess. If there is an issue with the size of the provided buffer, checked by proxy of the `size_t` argument, then the function returns `-EFAULT` to the user.

d) The function should take care to prevent any possibility of a buffer overflow.
  1. Add an asmlinkage declaration of your syscall in include/linux/syscalls.h. There are numerous examples of other syscalls in that file for ample student inspiration.

  2. Add an entry to the syscall table for your architecture. On x86_64, this is arch/x86/entry/syscalls/syscall_64.tbl and on aarch64 this is include/uapi/asm-generic/unistd.h. Take inspiration from the other syscalls.

  3. Write an assembly language program that invokes your syscall and prints the string that is placed in the buffer by the kernel to standard output using the write syscall.

  4. Write a C program that does exactly the same thing as the previous step.

  5. Compile and reboot into the newly modified kernel. Make sure your C and assembly language programs work correctly. Include the output in your cover letter.

The following pages will be of interest to a student:

Conventions:

  1. Assembly files that must be pre-processed use the extension *.S

  2. Assembly files that are ready to be assembled use the extension *.s

Refer to the Linux kernel documentation for further guidance.

What to submit: