
Rapport et PoC d'un débordement de tampon sur le tas dans Pepper Language avant la version 0.1.1, commit 961a5d9988c5986d563310275adad3fd181b2bb7
Pepper Language est un langage de programmation interprété rapide pour la simplicité et la verbosité. Il est typé dynamiquement et prend en charge le ramasse-miettes.
Créez un fichier contenant plus de 65 nombres dans une colonne. Par exemple,
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
Cela ferait planter le compilateur pepper du langage Pepper compilé. Ci-dessous le résultat du crash avec AddressSanitizer.
=================================================================
==319391==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x619000000980 at pc 0x5d0c243bf4f5 bp 0x7fff8342bf10 sp 0x7fff8342bf08
WRITE of size 4 at 0x619000000980 thread T0
#0 0x5d0c243bf4f4 in add_constant /home/ch1keen/fuzz/pepper-lang/src/compiler.c:91:50
#1 0x5d0c243bf4f4 in compile_expression /home/ch1keen/fuzz/pepper-lang/src/compiler.c:445:45
#2 0x5d0c243bc551 in compile_statement /home/ch1keen/fuzz/pepper-lang/src/compiler.c:212:19
#3 0x5d0c243bc28d in compile_program /home/ch1keen/fuzz/pepper-lang/src/compiler.c:180:15
#4 0x5d0c243a82dc in run_script /home/ch1keen/fuzz/pepper-lang/src/pepper.c:129:12
#5 0x5d0c243a82dc in main /home/ch1keen/fuzz/pepper-lang/src/pepper.c:161:9
#6 0x768a81e2a1c9 in __libc_start_call_main csu/../sysdeps/nptl/libc_start_call_main.h:58:16
#7 0x768a81e2a28a in __libc_start_main csu/../csu/libc-start.c:360:3
#8 0x5d0c242e8434 in _start (/home/ch1keen/fuzz/pepper-lang/bin/pepper+0x29434) (BuildId: b8341ebeb041c31389178ec76172705c296f6f5d)
0x619000000980 is located 0 bytes to the right of 1024-byte region [0x619000000580,0x619000000980)
allocated by thread T0 here:
#0 0x5d0c2436be42 in __interceptor_malloc (/home/ch1keen/fuzz/pepper-lang/bin/pepper+0xace42) (BuildId: b8341ebeb041c31389178ec76172705c296f6f5d)
#1 0x5d0c243c39fb in make_object_list /home/ch1keen/fuzz/pepper-lang/src/object.c:187:37
#2 0x5d0c243b945d in compiler_new /home/ch1keen/fuzz/pepper-lang/src/compiler.c:37:20
#3 0x5d0c243a82ce in run_script /home/ch1keen/fuzz/pepper-lang/src/pepper.c:128:30
#4 0x5d0c243a82ce in main /home/ch1keen/fuzz/pepper-lang/src/pepper.c:161:9
#5 0x768a81e2a1c9 in __libc_start_call_main csu/../sysdeps/nptl/libc_start_call_main.h:58:16
#6 0x768a81e2a28a in __libc_start_main csu/../csu/libc-start.c:360:3
#7 0x5d0c242e8434 in _start (/home/ch1keen/fuzz/pepper-lang/bin/pepper+0x29434) (BuildId: b8341ebeb041c31389178ec76172705c296f6f5d)
SUMMARY: AddressSanitizer: heap-buffer-overflow /home/ch1keen/fuzz/pepper-lang/src/compiler.c:91:50 in add_constant
Shadow bytes around the buggy address:
0x0c327fff80e0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0c327fff80f0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0c327fff8100: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0c327fff8110: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0c327fff8120: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
=>0x0c327fff8130:[fa]fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c327fff8140: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c327fff8150: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c327fff8160: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c327fff8170: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c327fff8180: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
Shadow byte legend (one shadow byte represents 8 application bytes):
Addressable: 00
Partially addressable: 01 02 03 04 05 06 07
Heap left redzone: fa
Freed heap region: fd
Stack left redzone: f1
Stack mid redzone: f2
Stack right redzone: f3
Stack after return: f5
Stack use after scope: f8
Global redzone: f9
Global init order: f6
Poisoned by user: f7
Container overflow: fc
Array cookie: ac
Intra object redzone: bb
ASan internal: fe
Left alloca redzone: ca
Right alloca redzone: cb
==319391==ABORTING
La structure du compilateur possède une variable scopes, qui est un tableau de taille fixe pouvant contenir 64 structures compiler_scope.
// src/compiler.h
struct compiler {
struct object_list *constants;
struct symbol_table *symbol_table;
uint32_t scope_index;
struct compiler_scope scopes[64];
};
Lorsque le fichier de preuve de concept est passé au compilateur, le fichier est d'abord analysé lexicalement et syntaxiquement. Chaque constante est convertie en variables de type compiler_scope. Mais comme la structure compiler ne peut stocker que 64 compiler_scopes, plus de 65 compiler_scopes dans un fichier provoque un débordement de tampon tas.
Remarque : Comme le mainteneur n'a pas répondu à un courriel concernant une préoccupation de sécurité — Voir la chronologie pour référence — et l'onglet des problèmes du dépôt du langage Pepper est fermé, cela ne peut être confirmé.
Le débordement de tampon tas peut permettre aux attaquants non seulement de modifier le contenu d'autres objets tas, qui peut être le contenu d'autres constantes dans Pepper, mais aussi de permettre aux attaquants d'exécuter du code arbitraire dans le programme.