Total Score: 110 Points
#I. Introduction: The purpose of this project is to let you configure and modify the kernel by yourself. In this project you will learn: Some data structures that Linux kernel uses to maintain virtual addresses and physical addresses of a process. Some functions and macros related to virtual addresses, physical addresses, and processes.
In the following project description, you can use Google to find the meanings of words or phrases prefixed with the tag.
###II. Project Description :
####1. Add a new system call in Linux kernel. (10 points in this part)
New system call prototype : int sys_project(long pid)
;
: Add a new system call in Linux
The following tasks need to be done inside your new system call which is in the kernel address space.
####2. Find the process according to the pid parameter. Print the image name of the process. (10 points) For example, if you execute an executable file called “project.out,” the result that you print out should be “project.out”.
: struct task_struct
####3. Dump the process virtual address space areas. The output may be similar to the following figure.
Print the vm_start and vm_end of all virtual address areas of the process. (15 points). If a file is associated with a virtual address area, print the name of the file. (15 points)
: struct mm_struct, struct vm_area_struct : you can use the /proc/$pid/maps to verify your result.
####4. Dump the physical frame addresses that the process is using (15 points).
: struct page and related functions and macro.
####5. Optional Bonus Point: (10 points) Add a new system call int nonwritable(unsigned long begin, unsigned long end)which specifies a virtual address range between begin and end as non-writable. You can use program project_user_2.c in appendix to verify your code.
: Change a page table entry from read-write to read-only.
: struct vm_area_struct, vm_flag, page fault
#include <stdio.h>
#include <stdlib.h>
int main()
{
char *ptr = (char *)malloc(0x1000);
unsigned int i;
for(i = 0; i < 0x1000; i++)
ptr[i] = 'a';
for( i = 0; i < 10; i++)
printf("%c ", ptr[i]);
nonwritable(ptr, ptr+0x1000-1);
/* verify read permission */
for( i = 0; i < 10; i++)
printf("%c ", ptr[i]);
/* write permission */
ptr[0] = 'w';
printf("if u see this message, you missed 15 points\n");
}
###III. TA Q & A ( 20 points) : ####1. Describe how you finished the project and the problems you encountered. ####2. Describe how you verify the result in step 4.
###IV. Report Content ( 15 points):
We first trying to modify the pte and it actually change after "pte_wrprotect(*pte)" but it resume after doing any assignment even if assign other value not "ptr" in c code.
Then we add "ptep_set_wrprotect(mm, PtrToUlong((void *)ptr), &pte);", pte becomes not resuming but "ptr[0]='w';" are still not being affect.
So we guess there were an mechanism in Linux kernel to avoid pte fault and found an approach calls "copy on write" after trace code in function "handle_mm_fault handle_pte_fault do_page_fault" we thought if we change the page protect and rewrite the vm_flags like above can make cow not effect, but we still not get "segmentation fault" on 3.14.25 . Maybe we miss something and will keep finding it.
我英文真的好爛,拜託幫我改進一下…