heap-use-after-free
A heap-use-after-free vulnerability exists in airpig2011 IEC104 thru Commit be6d841 (2019-07-08). During multi-threaded client execution, the function Iec10x_Scheduled can access memory that has already been freed, potentially causing program crashes or undefined behavior. This may be exploited to trigger a denial-of-service or memory corruption.
./iec104_monitor -m client -n 100 -p 10000 (-m: client mode; -n: 100 threads to trigger race conditions; -p: port 10000)=================================================================
==7243==ERROR: AddressSanitizer: heap-use-after-free on address 0x606000000020 at pc 0x0000004d08d1 bp 0x7a40f171ce30 sp 0x7a40f171ce28
READ of size 2 at 0x606000000020 thread T96
#0 0x4d08d0 in Iec10x_Scheduled /IEC104-master/test/..//IEC10X/Iec10x.c:136:9
#1 0x4d1495 in Iec104_Task /IEC104-master/test/main.c:65:9
#2 0x7a4125529183 in start_thread (/lib/x86_64-linux-gnu/libpthread.so.0+0x8183)
#3 0x7a412492e03c in clone (/lib/x86_64-linux-gnu/libc.so.6+0xfe03c)
0x606000000020 is located 0 bytes inside of 53-byte region [0x606000000020,0x606000000055)
freed by thread T74 here:
#0 0x492eed in free /tmp/final/llvm.src/projects/compiler-rt/lib/asan/asan_malloc_linux.cc:123:3
#1 0x4cf134 in IEC10X_Prio_ClearQueue /IEC104-master/test/..//IEC10X/PRIO_QUEUE_Iec10x.c:135:9
previously allocated by thread T7 here:
#0 0x49316d in malloc /tmp/final/llvm.src/projects/compiler-rt/lib/asan/asan_malloc_linux.cc:145:3
#1 0x4cfd9a in IEC10X_Enqueue /IEC104-master/test/..//IEC10X/Iec10x.c:72:34
Thread T96 created by T94 here:
#0 0x47d8fa in pthread_create /tmp/final/llvm.src/projects/compiler-rt/lib/asan/asan_interceptors.cc:209:3
#1 0x4d237d in Iec104_Client /IEC104-master/test/main.c:168:9
#2 0x7a4125529183 in start_thread (/lib/x86_64-linux-gnu/libpthread.so.0+0x8183)
Thread T94 created by T0 here:
#0 0x47d8fa in pthread_create /tmp/final/llvm.src/projects/compiler-rt/lib/asan/asan_interceptors.cc:209:3
#1 0x4d34bb in main /IEC104-master/test/main.c:311:11
#2 0x7a4124851f44 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21f44)
Thread T74 created by T67 here:
#0 0x47d8fa in pthread_create /tmp/final/llvm.src/projects/compiler-rt/lib/asan/asan_interceptors.cc:209:3
#1 0x4d237d in Iec104_Client /IEC104-master/test/main.c:168:9
#2 0x7a4125529183 in start_thread (/lib/x86_64-linux-gnu/libpthread.so.0+0x8183)
Thread T67 created by T0 here:
#0 0x47d8fa in pthread_create /tmp/final/llvm.src/projects/compiler-rt/lib/asan/asan_interceptors.cc:209:3
#1 0x4d34bb in main /IEC104-master/test/main.c:311:11
#2 0x7a4124851f44 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21f44)
Thread T7 created by T4 here:
#0 0x47d8fa in pthread_create /tmp/final/llvm.src/projects/compiler-rt/lib/asan/asan_interceptors.cc:209:3
#1 0x4d237d in Iec104_Client /IEC104-master/test/main.c:168:9
#2 0x7a4125529183 in start_thread (/lib/x86_64-linux-gnu/libpthread.so.0+0x8183)
Thread T4 created by T0 here:
#0 0x47d8fa in pthread_create /tmp/final/llvm.src/projects/compiler-rt/lib/asan/asan_interceptors.cc:209:3
#1 0x4d34bb in main /IEC104-master/test/main.c:311:11
#2 0x7a4124851f44 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21f44)
SUMMARY: AddressSanitizer: heap-use-after-free /IEC104-master/test/..//IEC10X/Iec10x.c:136:9 in Iec10x_Scheduled
Shadow bytes around the buggy address:
0x0c0c7fff7fb0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0c0c7fff7fc0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0c0c7fff7fd0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0c0c7fff7fe0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0c0c7fff7ff0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
=>0x0c0c7fff8000: fa fa fa fa[fd]fd fd fd fd fd fd fa fa fa fa fa
0x0c0c7fff8010: fd fd fd fd fd fd fd fa fa fa fa fa fa fa fa fa
0x0c0c7fff8020: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c0c7fff8030: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c0c7fff8040: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c0c7fff8050: 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
Shadow gap: cc
==7243==ABORTING