-
Notifications
You must be signed in to change notification settings - Fork 66
Description
Issue Summary
- Running the DTLS server under Valgrind and AddressSanitizer detected multiple memory access violations, including double-free and heap-use-after-free errors.
- These errors occur when both the SIGINT handler and server context cleanup routines attempt to free the same memory. While this issue may not be directly exploitable, it can cause undefined behavior, potentially destabilizing the server/client.
How to reproduce
- I fixed a random/cookie generation routine for easily understanding and writing Proof-of-Concept.
- I add a
raise(2)routine for easily triggering race condition - I hope you understand.
cd tests
valgrind --leak-check=full ./dtls-server
python3 reproduce.py
Double-Free-Bugs
Function: SIGINT handler and server/client cleanup routines.
Description: Memory for a context is freed twice, once during signal handling and once during normal cleanup.
=================================================================
==55548==ERROR: AddressSanitizer: attempting double-free on 0x615000002d80 in thread T0:
#0 0x4948fd (/home/sangjun/tinydtls/tests/dtls-server+0x4948fd)
#1 0x4efbd4 (/home/sangjun/tinydtls/tests/dtls-server+0x4efbd4)
#2 0x4fe244 (/home/sangjun/tinydtls/tests/dtls-server+0x4fe244)
#3 0x4d7245 (/home/sangjun/tinydtls/tests/dtls-server+0x4d7245)
#4 0x4c645c (/home/sangjun/tinydtls/tests/dtls-server+0x4c645c)
Heap-Use-After-Free
Function: dtls_handle_message and handle_alert.
Description: Freed memory is accessed during message handling, leading to undefined behavior.
==85957==ERROR: AddressSanitizer: heap-use-after-free on address 0x615000003b60 at pc 0x0000004c8f9f bp 0x7fffffffcbe0 sp 0x7fffffffcbd8
READ of size 8 at 0x615000003b60 thread T0
#0 0x4c8f9e (/home/sangjun/tinydtls/tests/dtls-server+0x4c8f9e)
#1 0x4d50bf (/home/sangjun/tinydtls/tests/dtls-server+0x4d50bf)
#2 0x4d7245 (/home/sangjun/tinydtls/tests/dtls-server+0x4d7245)
#3 0x4c645c (/home/sangjun/tinydtls/tests/dtls-server+0x4c645c)
Attachments:
- ASAN & valgrind Log
log.txt - Codes
tinydtls.zip
Root Cause Analysis
The SIGINT handler and the server/client's main execution flow both attempt to free the same context.
In the case of an interrupt (e.g., SIGINT), the cleanup routine may execute concurrently with other server logic, resulting in double-free or use-after-free errors.
Impact Assessment
While this issue is unlikely to be directly exploitable (due to ASLR and modern memory protections), it can:
-
Cause server/Client crashes.
-
Result in undefined behavior, impacting server reliability.
-
Make debugging and further development more complex.
Conclusion
- This memory management issue highlights a
race conditionbetween signal handling and normal server/client cleanup. Implementingsynchronization mechanismsand refactoring signal handling can prevent these errors, ensuring server/client stability and reliability.