-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Potential buffer overflow in dtls-sock #12905
Comments
Or, if not happening on |
Why don't you just point pkg/tinydtls to the head of the develop branch which contains the needed bugfix? |
If you as one of the developer of |
I agree with your general assessment but for tinydtls, there has not yet been any release while under the roof of the Eclipse organization. Therefore, the current tinydtls master is deemed not more stable than the development branch. |
Can someone confirm that this issue is fixed by #12912 ? |
Confirmed fixed with #12912 using the steps described in OP. With the PR (9cfdadc), the application does not crash anymore and the shell is still responsive - Using the commit before the PR (26a1348), the application crash:
|
Has it also been fixed on the latest release branch yet? |
Also confirmed fixed on current RIOT master (9198fbd). |
@fjmolinas will this be pulled into the 2020.1 release branch? |
If it's already in master, the fix will be part of the next release. |
What about the current release? Shouldn't this be backported? |
We are still not in feature freeze so there is no release branch yet. |
@kb2ma this is your release what do you think?. IMO we should just cherry-pick both commits if it fixes the issue without need for more refactoring then backport, if it does not then I would just wait for 2020.01. |
Sounds like a good plan to me. I'll try the cherry-pick in the next day or so. |
I can't recreate the issue in release 2019.10. dtls-sock was not included with that release; it was added with #11943 on 2019-12-05. I tried to recreate the issue with the dtls-echo example from around that time, but it does not crash when sending the large packet in this issue's description. Also FWIW, the tinydtls pkg at the time of 2019.10 used an older commit from tinydtls (dcac93f from 2019-03-27). If @nmeum can provide a failing test case from the head of 2019.10-branch, I can revisit. |
The issue has been confirmed as fixed. |
@kb2ma Just FYI: As such all RIOT versions which ship some variant of TinyDTLS should be vulnerable to this.
Are you sure? Because the commit adding
You might not be able to reproduce the issue with the exact same packet, but as I said: The underlying issue in the TinyDTLS code is also present in RIOT release 2019.10. Please correct me if my observations are wrong. |
#11909 added the API (header) for dtls_sock in 2019.10. #11943 added the first implementation for dtls_sock, which will appear in 2020.01. After some experimentation I found a way to alter the dtls-echo example, which uses only the tinydtls package, to recreate the issue by using the packet in this issue's description. I plan to follow-up with a couple of PRs in the next day or so. |
Closing this again without the update to 2019.10 because I actually cannot recreate the problem there. TLDR; based on my original exchange with @fjmolinas, the solution is to wait for the 2020.01 release which should be days away. What I reported yesterday was the ability to recreate the problem in dtls-echo at commit 6e53e28, which was when the dtls-sock implementation was merged in PR #11943. The key to recreation of the problem in the dtls-echo example was the use of a 512 byte receive buffer in However, when I tried to recreate the problem today in 2019.10-branch, I was unable. The likely reason is tinydtls commit 68a1cda, which also changed
So does the issue @nmeum describes here exist in 2019.10? The same block of code was changed in 68a1cda and 7a0420b. So without a failing test case, I can't say. However, if anyone really wants an update to 2019.10 with the commits in PR #12912, see my personal 2019.10-branch. My next and final step in this follow-up is to create a PR that changes the size of the receive buffer in the dtls-sock example to use |
I would personally propose creating a |
The RIOT module
dtls-sock
is potentially vulnerable to a stack-based buffer overflow. The root cause of this issue is that the current tinyDTLS version, used by RIOT, does not perform any sanity checks on the DTLS fragment length.This has been fixed on the tinydtls develop branch [1], the tinyDTLS master branch doesn't include this fix yet. Neither does the tinyDTLS version used by RIOT.
Maybe the aforementioned fix should be cherry-picked to the tinyDTLS master branch (CC: @obgm)?
Steps to reproduce
On native:
In a different terminal:
This package should crash the RIOT process with a SIGSEGV as it contains a large (invalid) DTLS fragment size which causes an invalid memory access.
Impact
I did not write a POC but I consider this to be an exploitable stack-based buffer overflow. The invalid fragment size is passed to
sha256_update
. This function contains variousmemcpy
invocations with the attacker controlledlen
parameter. For example:RIOT/sys/hashes/sha256.c
Line 248 in d6390b3
The buffer this function copies data to is the
buf
member from thesha256_context_t
:RIOT/sys/include/hashes/sha256.h
Line 77 in e296f69
The
sha256_context_t
is embedded in the tinyDTLS typedtls_hmac_context_t
as thedata
member:https://github.com/eclipse/tinydtls/blob/865ca387cd9d05e52943e5641ad0eefafef218a3/hmac.h#L104
dtls_hash_ctx
is a typedef forsha256_context_t
:https://github.com/eclipse/tinydtls/blob/865ca387cd9d05e52943e5641ad0eefafef218a3/hmac.h#L30
The
dtls_hmac_context_t
type is located on the stack of thedtls_create_cookie
tinyDTLS function:https://github.com/eclipse/tinydtls/blob/865ca387cd9d05e52943e5641ad0eefafef218a3/dtls.c#L364
In the worst case this potentially allows an attacker to overwrite the return address of the
dtls_create_cookie
function or some other stack frame using thememcpy
invocation fromsha256_update
. But as I said before I didn't write a POC.The text was updated successfully, but these errors were encountered: