-
Notifications
You must be signed in to change notification settings - Fork 13
/
syscall_hook.s
66 lines (61 loc) · 1.54 KB
/
syscall_hook.s
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/*
* syscall_hook.s
* Brandon Azad
*
* x86-64 assembly for kernel_dispatch, the function we will shove into the kernel.
*/
#include "syscall_code.h"
#define SYSCALL_CLASS_UNIX 2
#define SYSCALL_CLASS_SHIFT 24
#define SYSCALL_CLASS_MASK (0xFF << SYSCALL_CLASS_SHIFT)
#define SYSCALL_NUMBER_MASK (~SYSCALL_CLASS_MASK)
#define SYSCALL_CONSTRUCT_UNIX(syscall_number) \
((SYSCALL_CLASS_UNIX << SYSCALL_CLASS_SHIFT) | \
(SYSCALL_NUMBER_MASK & (syscall_number)))
/*
* _kernel_dispatch
*
* Description:
* The function we will shove into the kernel to be called by our syscall hook. This function
* transfers control to the first syscall argument, passing the remaining five syscall
* arguments to the called function.
*/
.globl _kernel_dispatch
.align 4
_kernel_dispatch:
pushq %rbx
movq %rdx, %rbx
movq (%rsi), %rax
shrq $48, %rax
cmpq $0xffff, %rax
jne _kernel_dispatch_abort
movq %rsi, %rax
movq 0x8(%rax), %rdi
movq 0x10(%rax), %rsi
movq 0x18(%rax), %rdx
movq 0x20(%rax), %rcx
movq 0x28(%rax), %r8
callq *(%rax)
movq %rax, (%rbx)
_kernel_dispatch_abort:
xorl %eax, %eax
popq %rbx
retq
/*
* _kernel_dispatch_end
*
* Description:
* A marker for the end of _kernel_dispatch so that we can determine its size.
*/
.globl _kernel_dispatch_end
_kernel_dispatch_end:
.globl _kernel_call
.align 4
_kernel_call:
pushq %rbp
movq %rsp, %rbp
movl $ SYSCALL_CONSTRUCT_UNIX(SYSCALL_CODE), %eax
movq %rcx, %r10
syscall
popq %rbp
retq