系統調用表(System call Table),是一張由指向實現各種系統調用的核心函式的函式指針組成的表,該表可以基於系統調用編號進行索引,來定位函式地址,完成系統調用。
掛載驅動通過修改系統調用表的函式地址可對常用處理函式進行Hook,從而實現對一些核心的系統動作進行過濾、監控的目的。
基本介紹
- 中文名:系統調用表
- 外文名:System Call Table
- 定義:系統調用編號索引,定位地址
- 系統:Linux
- 套用學科:計算機科學
概述
核心源碼定義
const sys_call_ptr_t sys_call_table[] ____cacheline_aligned = { /* * Smells like a compiler bug -- it doesn't work * when the & below is removed. */ [0 ... __NR_syscall_max] = &sys_ni_syscall,#include <asm/syscalls_64.h>};
#define __NR_restart_syscall 0#define __NR_exit 1#define __NR_fork 2#define __NR_read 3#define __NR_write 4#define __NR_open 5#define __NR_close 6#define __NR_waitpid 7#define __NR_creat 8#define __NR_link 9#define __NR_unlink 10#define __NR_execve 11#define __NR_chdir 12#define __NR_time 13#define __NR_mknod 14#define __NR_chmod 15#define __NR_lchown 16 /* 17 was sys_break */#define __NR_oldstat 18#define __NR_lseek 19#define __NR_getpid 20#define __NR_mount 21#define __NR_umount 22#define __NR_setuid 23#define __NR_getuid 24#define __NR_stime 25#define __NR_ptrace 26#define __NR_alarm 27#define __NR_oldfstat 28#define __NR_pause 29#define __NR_utime 30
獲取系統調用表地址
cat /proc/kallsyms| grep sys_call_table
cat /boot/System.map-xx
系統調用表掛鈎
unsigned int close_cr(void){ unsigned int cr0 = 0; unsigned int ret; asm volatile("movq %%cr0,%%rax":"=a"(cr0)); ret = cr0; cr0 &= 0xfffeffff; asm volatile("movq %%rax,%%cr0"::"a"(cr0)); return ret;}void open_cr(unsigned int oldval){ asm volatile("movq %%rax,%%cr0"::"a"(oldval));}