forked from kernelslacker/trinity
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tables-uniarch.c
178 lines (136 loc) · 3.48 KB
/
tables-uniarch.c
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
/*
* Functions for handling the system call tables.
* These functions are only used by architectures that have either 32 or 64 bit syscalls, but not both.
*/
#include <string.h>
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include "arch.h"
#include "syscall.h"
#include "params.h"
#include "random.h"
#include "shm.h"
#include "tables.h"
const struct syscalltable *syscalls;
unsigned int max_nr_syscalls;
void activate_syscall(unsigned int calln)
{
activate_syscall_in_table(calln, &shm->nr_active_syscalls, syscalls, shm->active_syscalls);
}
void deactivate_syscall_uniarch(unsigned int calln)
{
deactivate_syscall_in_table(calln, &shm->nr_active_syscalls, syscalls, shm->active_syscalls);
}
void toggle_syscall_n(int calln, bool state, const char *arg, const char *arg_name)
{
struct syscallentry *entry;
if (calln == -1) {
outputerr("No idea what syscall (%s) is.\n", arg);
exit(EXIT_FAILURE);
}
validate_specific_syscall(syscalls, calln);
entry = syscalls[calln].entry;
if (state == TRUE) {
entry->flags |= ACTIVE;
activate_syscall(calln);
} else {
entry->flags |= TO_BE_DEACTIVATED;
}
output(0, "Marking syscall %s (%d) as to be %sabled.\n",
arg_name, calln,
state ? "en" : "dis");
}
void enable_random_syscalls_uniarch(void)
{
unsigned int call;
struct syscallentry *entry;
retry:
call = rnd() % max_nr_syscalls;
entry = syscalls[call].entry;
if (validate_specific_syscall_silent(syscalls, call) == FALSE)
goto retry;
/* if we've set this to be disabled, don't enable it! */
if (entry->flags & TO_BE_DEACTIVATED)
goto retry;
toggle_syscall_n(call, TRUE, entry->name, entry->name);
}
int setup_syscall_group_uniarch(unsigned int group)
{
unsigned int i;
for_each_syscall(i) {
if (syscalls[i].entry->group == group)
activate_syscall(i);
}
if (shm->nr_active_syscalls == 0) {
outputstd("No syscalls found in group\n");
return FALSE;
} else {
outputstd("Found %d syscalls in group\n", shm->nr_active_syscalls);
}
return TRUE;
}
void mark_all_syscalls_active_uniarch(void)
{
unsigned int i;
for_each_syscall(i) {
struct syscallentry *entry = syscalls[i].entry;
if (entry == NULL)
continue;
entry->flags |= ACTIVE;
activate_syscall(i);
}
}
void init_syscalls_uniarch(void)
{
unsigned int i;
for_each_syscall(i) {
struct syscallentry *entry = syscalls[i].entry;
if (entry == NULL)
continue;
if (entry->flags & ACTIVE)
if (entry->init)
entry->init();
}
}
void deactivate_disabled_syscalls_uniarch(void)
{
unsigned int i;
for_each_syscall(i) {
struct syscallentry *entry = syscalls[i].entry;
if (entry == NULL)
continue;
if (entry->flags & TO_BE_DEACTIVATED) {
entry->flags &= ~(ACTIVE|TO_BE_DEACTIVATED);
deactivate_syscall_uniarch(i);
output(0, "Marked syscall %s (%d) as deactivated.\n",
entry->name, entry->number);
}
}
}
void dump_syscall_tables_uniarch(void)
{
unsigned int i;
outputstd("syscalls: %d\n", max_nr_syscalls);
for_each_syscall(i) {
struct syscallentry *entry = syscalls[i].entry;
if (entry == NULL)
continue;
outputstd("entrypoint %d %s : ", entry->number, entry->name);
show_state(entry->flags & ACTIVE);
if (entry->flags & AVOID_SYSCALL)
outputstd(" AVOID");
outputstd("\n");
}
}
void display_enabled_syscalls_uniarch(void)
{
unsigned int i;
for_each_syscall(i) {
struct syscallentry *entry = syscalls[i].entry;
if (entry == NULL)
continue;
if (entry->flags & ACTIVE)
output(0, "syscall %d:%s enabled.\n", i, entry->name);
}
}