-
Notifications
You must be signed in to change notification settings - Fork 60
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Invalid Heap Memory Access in DTLS Server/Client #245
Comments
That happens only on shutdown an only with the simple examples, right? |
The issue occurs exclusively during shutdown when a SIGINT signal is triggered. However, it is not confined to simple examples. As evidenced in the actual ASAN logs, the problem is reproducible even in scenarios where SIGINT is programmatically triggered without relying on a direct raise call. |
Shutdown bugs might appear trivial, but they often reveal underlying issues in memory management or resource cleanup. Such issues can compromise system stability and security, while neglecting them may lead to more complex debugging and maintenance challenges. Proactively addressing these bugs enhances system reliability and mitigates potential risks. For further details, please refer to CWE-364: Signal Handler Race Condition. |
My point is more, that this affects the shutdown only of the simple test examples. I'm not sure what the current grants about the usage with multiple threads are. |
In general interrupt handlers should not be free'ing off information that will get freed off elsewhere. Set a flag in the interrupt handler and then process the flag in the main general loop as per:
|
Thank you for your clarification. You are correct that this issue primarily affects the shutdown phase in the provided test examples. And it can only affect on example. However, these test examples are indeed one problem as Issue#98 mentioned Regarding your point about single-threaded usage, the current implementation indeed assumes single-threaded execution works well in normal operations. However, the interaction between the SIGINT handler and the main execution flow introduces a race condition even in single-threaded contexts, primarily because SIGINT signals and their handlers are processed asynchronously. Issues like race conditions or something like this issue, caused by shared code or resources, can arise when multiple execution paths—whether in multithreaded or single-threaded contexts—access shared data or resources without proper synchronization. The key point is that it can also occur in single-threaded environments.
To ensure robust operation, this can resolve the problem of the test client/sever.
This approach would eliminate the race condition and enhance reliability. Best Regards |
Please retest with the merged PR. |
It appears that this bug is fixed in #246. Thank you. |
Issue Summary
How to reproduce
raise(2)
routine for easily triggering race conditionDouble-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.
Heap-Use-After-Free
Function: dtls_handle_message and handle_alert.
Description: Freed memory is accessed during message handling, leading to undefined behavior.
Attachments:
log.txt
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
race condition
between signal handling and normal server/client cleanup. Implementingsynchronization mechanisms
and refactoring signal handling can prevent these errors, ensuring server/client stability and reliability.The text was updated successfully, but these errors were encountered: