-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
A heap-based buffer overflow in function read_io_status in src/modbus.c #683
Comments
Hi, what's the status of this bug? Do you need more details from me? If so, what details should I provide? Thanks. |
Apparently CVE-2023-26793 was assigned for this issue. |
I was going to take a look at this due to the CVE. |
Yes, exactly right. |
Ok, I haven't yet been able to work out how to do that, so if you have more info ... |
Doesn't this issue just boil down to this line in the unit test? rc = modbus_read_bits(ctx, UT_BITS_ADDRESS, UT_BITS_NB + 1, tab_rp_bits); The buffer tab_rp_bits was been allocated to be UT_BITS_NB and the caller is lying and saying it is allocated for UT_BITS_NB + 1. So of course the buffer can overflow, because the caller lied about the length in the first place. So when the server returns a bunch of data and it is processed, the loop in the client fills more bytes than there is space. IMO this is not a bug in the implementation, rather it is a bug in the unit test and user error for not ensuring the size of the buffer matches with its actual size. |
libmodbus version
latest commit b25629bfb508bdce7d519884c0fa9810b7d98d44
OS and/or distribution
Debian GNU/Linux 11 (bullseye)
Environment
x86_64
Description
There is a heap-based buffer overflow in the function read_io_status in src/modbus.c.
Actual behavior if applicable
Heap-buffer-overflow
Expected behavior or suggestion
no crash
Steps to reproduce the behavior (commands or source code)
Build with ASan
Asan traceback
I found a heap-buffer-overflow bug via the utility
tests/unit-test-client
, here is the stderr output:PoC
This bug is triggered when the client executing
modbus_read_bits
:libmodbus/tests/unit-test-client.c
Line 363 in b25629b
For this operation, the corresponding normal response to
tests/unit-test-client
(collected by launchingtests/unit-test-server
) is001100000006ff0101300026
, with structure:However, if mutating this packet by manipulating the field
unitId
:with hex stream
0011000000067c0101300023
, thetests/unit-test-client
crashed due to heap buffer overflow.The text was updated successfully, but these errors were encountered: