summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'driver/gator_cookies.c')
-rw-r--r--driver/gator_cookies.c67
1 files changed, 31 insertions, 36 deletions
diff --git a/driver/gator_cookies.c b/driver/gator_cookies.c
index d7d8e84..21dc4eb 100644
--- a/driver/gator_cookies.c
+++ b/driver/gator_cookies.c
@@ -12,7 +12,7 @@
12#define MAX_COLLISIONS 2 12#define MAX_COLLISIONS 2
13 13
14static uint32_t *gator_crc32_table; 14static uint32_t *gator_crc32_table;
15static uint32_t translate_buffer_mask; 15static unsigned int translate_buffer_mask;
16 16
17static DEFINE_PER_CPU(char *, translate_text); 17static DEFINE_PER_CPU(char *, translate_text);
18static DEFINE_PER_CPU(uint32_t, cookie_next_key); 18static DEFINE_PER_CPU(uint32_t, cookie_next_key);
@@ -20,9 +20,9 @@ static DEFINE_PER_CPU(uint64_t *, cookie_keys);
20static DEFINE_PER_CPU(uint32_t *, cookie_values); 20static DEFINE_PER_CPU(uint32_t *, cookie_values);
21static DEFINE_PER_CPU(int, translate_buffer_read); 21static DEFINE_PER_CPU(int, translate_buffer_read);
22static DEFINE_PER_CPU(int, translate_buffer_write); 22static DEFINE_PER_CPU(int, translate_buffer_write);
23static DEFINE_PER_CPU(unsigned int *, translate_buffer); 23static DEFINE_PER_CPU(void * *, translate_buffer);
24 24
25static inline uint32_t get_cookie(int cpu, int buftype, struct task_struct *task, struct vm_area_struct *vma, struct module *mod, bool in_interrupt); 25static inline uint32_t get_cookie(int cpu, struct task_struct *task, struct vm_area_struct *vma, struct module *mod, bool in_interrupt);
26static void wq_cookie_handler(struct work_struct *unused); 26static void wq_cookie_handler(struct work_struct *unused);
27DECLARE_WORK(cookie_work, wq_cookie_handler); 27DECLARE_WORK(cookie_work, wq_cookie_handler);
28static struct timer_list app_process_wake_up_timer; 28static struct timer_list app_process_wake_up_timer;
@@ -40,16 +40,16 @@ static uint32_t cookiemap_code(uint64_t value64) {
40 40
41static uint32_t gator_chksum_crc32(char *data) 41static uint32_t gator_chksum_crc32(char *data)
42{ 42{
43 register unsigned long crc; 43 register unsigned long crc;
44 unsigned char *block = data; 44 unsigned char *block = data;
45 int i, length = strlen(data); 45 int i, length = strlen(data);
46 46
47 crc = 0xFFFFFFFF; 47 crc = 0xFFFFFFFF;
48 for (i = 0; i < length; i++) { 48 for (i = 0; i < length; i++) {
49 crc = ((crc >> 8) & 0x00FFFFFF) ^ gator_crc32_table[(crc ^ *block++) & 0xFF]; 49 crc = ((crc >> 8) & 0x00FFFFFF) ^ gator_crc32_table[(crc ^ *block++) & 0xFF];
50 } 50 }
51 51
52 return (crc ^ 0xFFFFFFFF); 52 return (crc ^ 0xFFFFFFFF);
53} 53}
54 54
55/* 55/*
@@ -104,15 +104,15 @@ static void cookiemap_add(uint64_t key, uint32_t value) {
104 values[0] = value; 104 values[0] = value;
105} 105}
106 106
107static void translate_buffer_write_int(int cpu, unsigned int x) 107static void translate_buffer_write_ptr(int cpu, void * x)
108{ 108{
109 per_cpu(translate_buffer, cpu)[per_cpu(translate_buffer_write, cpu)++] = x; 109 per_cpu(translate_buffer, cpu)[per_cpu(translate_buffer_write, cpu)++] = x;
110 per_cpu(translate_buffer_write, cpu) &= translate_buffer_mask; 110 per_cpu(translate_buffer_write, cpu) &= translate_buffer_mask;
111} 111}
112 112
113static unsigned int translate_buffer_read_int(int cpu) 113static void * translate_buffer_read_ptr(int cpu)
114{ 114{
115 unsigned int value = per_cpu(translate_buffer, cpu)[per_cpu(translate_buffer_read, cpu)++]; 115 void * value = per_cpu(translate_buffer, cpu)[per_cpu(translate_buffer_read, cpu)++];
116 per_cpu(translate_buffer_read, cpu) &= translate_buffer_mask; 116 per_cpu(translate_buffer_read, cpu) &= translate_buffer_mask;
117 return value; 117 return value;
118} 118}
@@ -129,9 +129,9 @@ static void wq_cookie_handler(struct work_struct *unused)
129 if (gator_started != 0) { 129 if (gator_started != 0) {
130 commit = per_cpu(translate_buffer_write, cpu); 130 commit = per_cpu(translate_buffer_write, cpu);
131 while (per_cpu(translate_buffer_read, cpu) != commit) { 131 while (per_cpu(translate_buffer_read, cpu) != commit) {
132 task = (struct task_struct *)translate_buffer_read_int(cpu); 132 task = (struct task_struct *)translate_buffer_read_ptr(cpu);
133 vma = (struct vm_area_struct *)translate_buffer_read_int(cpu); 133 vma = (struct vm_area_struct *)translate_buffer_read_ptr(cpu);
134 cookie = get_cookie(cpu, BACKTRACE_BUF, task, vma, NULL, false); 134 cookie = get_cookie(cpu, task, vma, NULL, false);
135 } 135 }
136 } 136 }
137 137
@@ -163,13 +163,13 @@ static int translate_app_process(char** text, int cpu, struct task_struct * task
163 // Check if already in buffer 163 // Check if already in buffer
164 ptr = per_cpu(translate_buffer_read, cpu); 164 ptr = per_cpu(translate_buffer_read, cpu);
165 while (ptr != per_cpu(translate_buffer_write, cpu)) { 165 while (ptr != per_cpu(translate_buffer_write, cpu)) {
166 if (per_cpu(translate_buffer, cpu)[ptr] == (int)task) 166 if (per_cpu(translate_buffer, cpu)[ptr] == (void *)task)
167 goto out; 167 goto out;
168 ptr = (ptr + 2) & translate_buffer_mask; 168 ptr = (ptr + 2) & translate_buffer_mask;
169 } 169 }
170 170
171 translate_buffer_write_int(cpu, (unsigned int)task); 171 translate_buffer_write_ptr(cpu, (void *)task);
172 translate_buffer_write_int(cpu, (unsigned int)vma); 172 translate_buffer_write_ptr(cpu, (void *)vma);
173 173
174 mod_timer(&app_process_wake_up_timer, jiffies + 1); 174 mod_timer(&app_process_wake_up_timer, jiffies + 1);
175 goto out; 175 goto out;
@@ -222,7 +222,7 @@ out:
222 return retval; 222 return retval;
223} 223}
224 224
225static inline uint32_t get_cookie(int cpu, int buftype, struct task_struct *task, struct vm_area_struct *vma, struct module *mod, bool in_interrupt) 225static inline uint32_t get_cookie(int cpu, struct task_struct *task, struct vm_area_struct *vma, struct module *mod, bool in_interrupt)
226{ 226{
227 unsigned long flags, cookie; 227 unsigned long flags, cookie;
228 struct path *path; 228 struct path *path;
@@ -232,10 +232,13 @@ static inline uint32_t get_cookie(int cpu, int buftype, struct task_struct *task
232 if (mod) { 232 if (mod) {
233 text = mod->name; 233 text = mod->name;
234 } else { 234 } else {
235 if (!vma || !vma->vm_file) { 235 if (vma && vma->vm_file) {
236 path = &vma->vm_file->f_path;
237 } else if (task && task->mm && task->mm->exe_file) {
238 path = &task->mm->exe_file->f_path;
239 } else {
236 return INVALID_COOKIE; 240 return INVALID_COOKIE;
237 } 241 }
238 path = &vma->vm_file->f_path;
239 if (!path || !path->dentry) { 242 if (!path || !path->dentry) {
240 return INVALID_COOKIE; 243 return INVALID_COOKIE;
241 } 244 }
@@ -271,29 +274,21 @@ static inline uint32_t get_cookie(int cpu, int buftype, struct task_struct *task
271 return cookie; 274 return cookie;
272} 275}
273 276
274static int get_exec_cookie(int cpu, int buftype, struct task_struct *task) 277static int get_exec_cookie(int cpu, struct task_struct *task)
275{ 278{
276 unsigned long cookie = NO_COOKIE; 279 unsigned long cookie = NO_COOKIE;
277 struct mm_struct *mm = task->mm; 280 struct mm_struct *mm = task->mm;
278 struct vm_area_struct *vma;
279 281
280 // kernel threads have no address space 282 // kernel threads have no address space
281 if (!mm) 283 if (!mm)
282 return cookie; 284 return cookie;
283 285
284 for (vma = mm->mmap; vma; vma = vma->vm_next) { 286 cookie = get_cookie(cpu, task, NULL, NULL, true);
285 if (!vma->vm_file)
286 continue;
287 if (!(vma->vm_flags & VM_EXECUTABLE))
288 continue;
289 cookie = get_cookie(cpu, buftype, task, vma, NULL, true);
290 break;
291 }
292 287
293 return cookie; 288 return cookie;
294} 289}
295 290
296static unsigned long get_address_cookie(int cpu, int buftype, struct task_struct *task, unsigned long addr, off_t *offset) 291static unsigned long get_address_cookie(int cpu, struct task_struct *task, unsigned long addr, off_t *offset)
297{ 292{
298 unsigned long cookie = NO_COOKIE; 293 unsigned long cookie = NO_COOKIE;
299 struct mm_struct *mm = task->mm; 294 struct mm_struct *mm = task->mm;
@@ -307,7 +302,7 @@ static unsigned long get_address_cookie(int cpu, int buftype, struct task_struct
307 continue; 302 continue;
308 303
309 if (vma->vm_file) { 304 if (vma->vm_file) {
310 cookie = get_cookie(cpu, buftype, task, vma, NULL, true); 305 cookie = get_cookie(cpu, task, vma, NULL, true);
311 *offset = (vma->vm_pgoff << PAGE_SHIFT) + addr - vma->vm_start; 306 *offset = (vma->vm_pgoff << PAGE_SHIFT) + addr - vma->vm_start;
312 } else { 307 } else {
313 /* must be an anonymous map */ 308 /* must be an anonymous map */
@@ -350,7 +345,7 @@ static int cookies_initialize(void)
350 } 345 }
351 memset(per_cpu(cookie_values, cpu), 0, size); 346 memset(per_cpu(cookie_values, cpu), 0, size);
352 347
353 per_cpu(translate_buffer, cpu) = (unsigned int *)kmalloc(translate_buffer_size, GFP_KERNEL); 348 per_cpu(translate_buffer, cpu) = (void * *)kmalloc(translate_buffer_size, GFP_KERNEL);
354 if (!per_cpu(translate_buffer, cpu)) { 349 if (!per_cpu(translate_buffer, cpu)) {
355 err = -ENOMEM; 350 err = -ENOMEM;
356 goto cookie_setup_error; 351 goto cookie_setup_error;