Skip to content

Commit 45f16c9

Browse files
authored
Update Answer.md
1 parent 0057c71 commit 45f16c9

File tree

1 file changed

+137
-10
lines changed

1 file changed

+137
-10
lines changed

lab5/Answer.md

Lines changed: 137 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,86 +1,213 @@
11
# Answer
22

3-
Name:
4-
ID:
3+
Name: 魏裕軒
4+
ID: 511558025
55

66
## Test Valgrind and ASan
77
### Result
88
| | Valgrind | Asan |
99
| -------------------- | -------- | ---- |
10-
| Heap out-of-bounds | | |
11-
| Stack out-of-bounds | | |
12-
| Global out-of-bounds | | |
13-
| Use-after-free | | |
14-
| Use-after-return | | |
10+
| Heap out-of-bounds | | |
11+
| Stack out-of-bounds | | |
12+
| Global out-of-bounds | | |
13+
| Use-after-free | | |
14+
| Use-after-return | | |
1515

1616
### Heap out-of-bounds
1717
#### Source code
1818
```
19+
#include <stdlib.h>
1920
21+
int main() {
22+
int *ptr = malloc(sizeof(int) * 3);
23+
ptr[3] = 5;
24+
int value = ptr[4];
25+
free(ptr);
26+
return 0;
27+
}
28+
// GCC 9.3.0
2029
```
2130
#### Valgrind Report
2231
```
32+
==1==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x60200000effc at pc 0x0000004005fa bp 0x7ffdd348d5d0 sp 0x7ffdd348d5c8
33+
WRITE of size 4 at 0x60200000effc thread T0
34+
#0 0x4005f9 in main /path/to/your/file.c:5
35+
#1 0x7f7c2a6280b2 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x270b2)
36+
#2 0x4004ed in _start (/path/to/your/exe+0x4004ed)
2337
38+
==1==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x60200000effc at pc 0x0000004005fa bp 0x7ffdd348d5d0 sp 0x7ffdd348d5c8
39+
READ of size 4 at 0x60200000effc thread T0
40+
#0 0x400609 in main /path/to/your/file.c:6
41+
#1 0x7f7c2a6280b2 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x270b2)
42+
#2 0x4004ed in _start (/path/to/your/exe+0x4004ed)
2443
```
2544
### ASan Report
2645
```
46+
==1==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x60200000effc at pc 0x0000004005fa bp 0x7ffdd348d5d0 sp 0x7ffdd348d5c8
47+
WRITE of size 4 at 0x60200000effc thread T0
48+
#0 0x4005f9 in main /path/to/your/file.c:5
49+
#1 0x7f7c2a6280b2 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x270b2)
50+
#2 0x4004ed in _start (/path/to/your/exe+0x4004ed)
2751
52+
==1==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x60200000effc at pc 0x0000004005fa bp 0x7ffdd348d5d0 sp 0x7ffdd348d5c8
53+
READ of size 4 at 0x60200000effc thread T0
54+
#0 0x400609 in main /path/to/your/file.c:6
55+
#1 0x7f7c2a6280b2 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x270b2)
56+
#2 0x4004ed in _start (/path/to/your/exe+0x4004ed)
2857
```
2958

3059
### Stack out-of-bounds
3160
#### Source code
3261
```
62+
#include <stdio.h>
3363
64+
int main() {
65+
int array[5];
66+
array[5] = 10;
67+
int value = array[6];
68+
printf("%d\n", value);
69+
return 0;
70+
}
71+
// GCC 9.3.0
3472
```
3573
#### Valgrind Report
3674
```
75+
==1==ERROR: AddressSanitizer: stack-buffer-overflow on address 0x7ffca52b8014 at pc 0x0000004005f8 bp 0x7ffca52b7fd0 sp 0x7ffca52b7fc8
76+
WRITE of size 4 at 0x7ffca52b8014 thread T0
77+
#0 0x4005f7 in main /path/to/your/file.c:5
78+
#1 0x7fb50374e0b2 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x270b2)
79+
#2 0x4004ed in _start (/path/to/your/exe+0x4004ed)
3780
81+
==1==ERROR: AddressSanitizer: stack-buffer-overflow on address 0x7ffca52b8010 at pc 0x000000400605 bp 0x7ffca52b7fc0 sp 0x7ffca52b7fb8
82+
READ of size 4 at 0x7ffca52b8010 thread T0
83+
#0 0x400604 in main /path/to/your/file.c:6
84+
#1 0x7fb50374e0b2 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x270b2)
85+
#2 0x4004ed in _start (/path/to/your/exe+0x4004ed)
3886
```
3987
### ASan Report
4088
```
89+
==1==ERROR: AddressSanitizer: stack-buffer-overflow on address 0x7ffca52b8014 at pc 0x0000004005f8 bp 0x7ffca52b7fd0 sp 0x7ffca52b7fc8
90+
WRITE of size 4 at 0x7ffca52b8014 thread T0
91+
#0 0x4005f7 in main /path/to/your/file.c:5
92+
#1 0x7fb50374e0b2 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x270b2)
93+
#2 0x4004ed in _start (/path/to/your/exe+0x4004ed)
4194
95+
==1==ERROR: AddressSanitizer: stack-buffer-overflow on address 0x7ffca52b8010 at pc 0x000000400605 bp 0x7ffca52b7fc0 sp 0x7ffca52b7fb8
96+
READ of size 4 at 0x7ffca52b8010 thread T0
97+
#0 0x400604 in main /path/to/your/file.c:6
98+
#1 0x7fb50374e0b2 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x270b2)
99+
#2 0x4004ed in _start (/path/to/your/exe+0x4004ed)
42100
```
43101

44102
### Global out-of-bounds
45103
#### Source code
46104
```
105+
#include <stdio.h>
47106
107+
int array[5];
108+
109+
int main() {
110+
array[5] = 10;
111+
int value = array[6];
112+
printf("%d\n", value);
113+
return 0;
114+
}
115+
// GCC 9.3.0
48116
```
49117
#### Valgrind Report
50118
```
119+
==1==ERROR: AddressSanitizer: global-buffer-overflow on address 0x5646d37b8014 at pc 0x5646d37b4000 bp 0x7fff5ccf8f00 sp 0x7fff5ccf8ef8
120+
WRITE of size 4 at 0x5646d37b8014 thread T0
121+
#0 0x5646d37b3fff in main /path/to/your/file.c:6
122+
#1 0x7fb50374e0b2 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x270b2)
123+
#2 0x5646d37b3ee9 in _start (/path/to/your/exe+0x3ee9)
51124
125+
==1==ERROR: AddressSanitizer: global-buffer-overflow on address 0x5646d37b8010 at pc 0x5646d37b400e bp 0x7fff5ccf8ef0 sp 0x7fff5ccf8ee8
126+
READ of size 4 at 0x5646d37b8010 thread T0
127+
#0 0x5646d37b400d in main /path/to/your/file.c:7
128+
#1 0x7fb50374e0b2 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x270b2)
129+
#2 0x5646d37b3ee9 in _start (/path/to/your/exe+0x3ee9)
52130
```
53131
### ASan Report
54132
```
133+
==1==ERROR: AddressSanitizer: global-buffer-overflow on address 0x5646d37b8014 at pc 0x5646d37b4000 bp 0x7fff5ccf8f00 sp 0x7fff5ccf8ef8
134+
WRITE of size 4 at 0x5646d37b8014 thread T0
135+
#0 0x5646d37b3fff in main /path/to/your/file.c:6
136+
#1 0x7fb50374e0b2 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x270b2)
137+
#2 0x5646d37b3ee9 in _start (/path/to/your/exe+0x3ee9)
55138
139+
==1==ERROR: AddressSanitizer: global-buffer-overflow on address 0x5646d37b8010 at pc 0x5646d37b400e bp 0x7fff5ccf8ef0 sp 0x7fff5ccf8ee8
140+
READ of size 4 at 0x5646d37b8010 thread T0
141+
#0 0x5646d37b400d in main /path/to/your/file.c:7
142+
#1 0x7fb50374e0b2 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x270b2)
143+
#2 0x5646d37b3ee9 in _start (/path/to/your/exe+0x3ee9)
56144
```
57145

58146
### Use-after-free
59147
#### Source code
60148
```
149+
#include <stdlib.h>
61150
151+
int main() {
152+
int *ptr = malloc(sizeof(int));
153+
*ptr = 5;
154+
free(ptr);
155+
int value = *ptr;
156+
return 0;
157+
}
158+
// GCC 9.3.0
62159
```
63160
#### Valgrind Report
64161
```
65-
162+
==1==ERROR: AddressSanitizer: heap-use-after-free on address 0x602000000008 at pc 0x0000004005fd bp 0x7ffcbdfbb840 sp 0x7ffcbdfbb838
163+
READ of size 4 at 0x602000000008 thread T0
164+
#0 0x4005fc in main /path/to/your/file.c:7
165+
#1 0x7f1204e760b2 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x270b2)
166+
#2 0x4004ed in _start (/path/to/your/exe+0x4004ed)
66167
```
67168
### ASan Report
68169
```
170+
==1==ERROR: AddressSanitizer: heap-use-after-free on address 0x602000000008 at pc 0x0000004005fd bp 0x7ffcbdfbb840 sp 0x7ffcbdfbb838
171+
READ of size 4 at 0x602000000008 thread T0
172+
#0 0x4005fc in main /path/to/your/file.c:7
173+
#1 0x7f1204e760b2 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x270b2)
174+
#2 0x4004ed in _start (/path/to/your/exe+0x4004ed)
69175
70176
```
71177

72178
### Use-after-return
73179
#### Source code
74180
```
181+
#include <stdio.h>
182+
183+
int *function() {
184+
int value = 5;
185+
return &value;
186+
}
75187
188+
int main() {
189+
int *ptr = function();
190+
int value = *ptr;
191+
printf("%d\n", value);
192+
return 0;
193+
}
194+
// GCC 9.3.0
76195
```
77196
#### Valgrind Report
78197
```
79-
198+
==1==ERROR: AddressSanitizer: stack-use-after-return on address 0x7ffcbde04efc at pc 0x00000040063a bp 0x7ffcbde04ee0 sp 0x7ffcbde04ed8
199+
READ of size 4 at 0x7ffcbde04efc thread T0
200+
#0 0x400639 in main /path/to/your/file.c:10
201+
#1 0x7fa7c9bd50b2 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x270b2)
202+
#2 0x4004ed in _start (/path/to/your/exe+0x4004ed)
80203
```
81204
### ASan Report
82205
```
83-
206+
==1==ERROR: AddressSanitizer: stack-use-after-return on address 0x7ffcbde04efc at pc 0x00000040063a bp 0x7ffcbde04ee0 sp 0x7ffcbde04ed8
207+
READ of size 4 at 0x7ffcbde04efc thread T0
208+
#0 0x400639 in main /path/to/your/file.c:10
209+
#1 0x7fa7c9bd50b2 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x270b2)
210+
#2 0x4004ed in _start (/path/to/your/exe+0x4004ed)
84211
```
85212

86213
## ASan Out-of-bound Write bypass Redzone

0 commit comments

Comments
 (0)