Closed dqp10515 closed 7 months ago
Given that the hexstream is being sent to the running server, this is not getting done by the examples client, so I am not able to reproduce the client issue.
However, one of the hexstream values is invalid, which the examples server correctly reports there are issues with the data, but the Sanitizer does not complain. The bad hexstream entry is
hexstream 13:
d50301b831e281a9616578616d706c6532e4000c91425634
Thank you for your reply. The hexstream was sent to the server using the following command: echo -n "hexstream" | xxd -r -p | nc -u 127.0.0.1 5783
Doing that only exercises the server logic (the -u
option is invalid for nc
as the data is larger that a UDP packet size), and not the client logic where you were reporting the error. The server rightly complains about the hexstream 13 record.
The issue in the coap_update_token()
function is only likely to occur on the client side logic and that needs to be reproducible somehow.
Please see #1352 for a fix. Please confirm this fixes what you are trying to do as I cannot reproduce your client side actual issue with the information you have given us.
Please note that this is a false positive that is reported.
I tried to reproduce the crash again and no error was found. Thanks for the fix.
Thanks for the feedback. Changes now merged into the develop branch.
Hello, when I tried to reproduce this vulnerability, I sent the data packet to the server through the following script
import subprocess
import time
with open('hexstream.txt', 'r') as file:
hexstreams = file.readlines()
hexstreams = [hexstream.strip() for hexstream in hexstreams]
for hexstream in hexstreams:
if hexstream:
command = f"echo -n {hexstream} | xxd -r -p | nc -u 127.0.0.1 5783"
print(f"Executing: {command}")
#time.sleep(2)
process = subprocess.Popen(command, shell=True)
I have observed that the server is constantly creating new sessions, which seems inconsistent with the behavior recorded in client.log.
Oct 17 01:21:11.504 DEBG ***127.0.0.1:5783 <-> 127.0.0.1:50912 (if1) UDP : session 0x617000006600: new incoming session
Oct 17 01:21:11.504 DEBG ***EVENT: COAP_EVENT_SERVER_SESSION_NEW
Oct 17 01:21:11.504 DEBG * 127.0.0.1:5783 <-> 127.0.0.1:50912 (if1) UDP : netif: recv 7 bytes
v:1 t:NON c:CSM i:2380 {} [ 0:, Max-Message-Size:0 ]
Oct 17 01:21:11.504 INFO coap_dispatch: Received invalid PDU code (7.01)
Oct 17 01:21:11.504 DEBG ***EVENT: COAP_EVENT_BAD_PACKET
Oct 17 01:21:13.507 DEBG ***127.0.0.1:5783 <-> 127.0.0.1:40207 (if1) UDP : session 0x617000006980: new incoming session
Oct 17 01:21:13.507 DEBG ***EVENT: COAP_EVENT_SERVER_SESSION_NEW
Oct 17 01:21:13.507 DEBG * 127.0.0.1:5783 <-> 127.0.0.1:40207 (if1) UDP : netif: recv 24 bytes
Oct 17 01:21:13.507 DEBG coap_pdu_parse: UDP version not supported
Oct 17 01:21:13.507 DEBG ***EVENT: COAP_EVENT_BAD_PACKET
Oct 17 01:21:13.507 WARN discard malformed PDU
Oct 17 01:21:13.507 DEBG * 127.0.0.1:5783 <-> 127.0.0.1:40207 (if1) UDP : netif: sent 4 bytes
Is there something wrong with my sending script?
If you look at the server output, you will see that the source port (50912 40207) is changing per nc
execution.
Try using the -p por
t nc
option to keep the source port the same.
Environment
libcoap Configuration Summary
libcoap package version : "4.3.4" libcoap package source : "v4.3.4-82-g0a39b6c0" libcoap API version : "3" libcoap ABI version : "3.1.2" libcoap libtool SO version : "4.2.1" libcoap DTLS lib extn : "-gnutls" host system : "x86_64-pc-linux-gnu" build with server support : "yes" build with client support : "yes" build with IPv4 support : "yes" build with IPv6 support : "yes" build with Unix socket support : "yes" build with TCP support : "yes" build DTLS support : "yes" --> GnuTLS around : "yes" (found GnuTLS 3.6.13) GNUTLS_CFLAGS : "-I/usr/include/p11-kit-1" GNUTLS_LIBS : "-lgnutls" add default names : "yes" build Observe Persist : "yes" build using epoll : "yes" enable small stack size : "no" enable separate responses : "yes" enable OSCORE support : "yes" enable Q-Block support : "yes" enable max logging level : "none" enable thread safe code : "yes" enable recursive lock check : "yes" build doxygen pages : "no" build man pages : "no" build unit test binary : "no" build examples : "yes" install examples source : "yes" build with gcov support : "no" build shared library : "no" build static library : "yes"
Problem Description
After sending a sequence of messages to the CoAP server, a runtime error was reported by UndefinedBehaviorSanitizer (UBSan). The error indicated an unsigned integer overflow occurred in
coap_pdu.c
at the line where an address calculation was being performed. Specifically, an unsigned offset addition to a base address resulted in an overflow, indicating that the calculated address wrapped around to a lower value than the original address. This is a sign of undefined behavior due to integer overflow during pointer arithmetic. This suggests that the resulting address calculation wrapped around, which is indicative of undefined behavior in the program.Expected Behavior
The server is expected to handle a sequence of incoming messages reliably without encountering arithmetic overflows or other undefined behaviors during address calculations. Memory operations should remain within their allocated bounds, and all pointer arithmetic should result in valid memory addresses that are within the expected range.
Actual Behavior
The server exhibited undefined behavior after processing a sequence of messages, indicating a potential flaw in the address calculation within the coap_update_token function.
Steps to reproduce
libcoap
project:libcoap
directory and clear any previous configurations:Debug Logs
log of client : client log.txt
Here is the UBSan report: