[BUG] DHCPv6 socket-allocation failure crashes with assertions disabled; CBMC stubs hide the path
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Idoneità per principianti
- 65/100
- Tipo di issue
- Bug
- Chiarezza
- Specificata chiaramente
- Stato di attività
- Attiva
- Stack tecnologico
- c
- Ambito
- networking
Direzione di ricerca
Start in source/FreeRTOS_DHCPv6.c at prvCreateDHCPv6Socket (lines 893-906) and compare it with the DHCPv4 path, which guards the bind with xSocketValid and keeps the socket NULL on failure; the dereference happens in vSocketBind at source/FreeRTOS_Sockets.c:1903-1906. Build the host reproducer from the issue first to confirm the ASan failure, then check whether the existing DHCPv6 fallback to the static address is reached once the failed socket is reset to NULL. The CBMC side lives in test/cbmc/proofs/DHCPv6/DHCPv6Process/DHCPv6Process_harness.c (lines 102-126) and its Makefile.json; done means the reproducer returns normally and the adjusted proof still passes.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Describe the bug
With DHCPv6 enabled and configASSERT undefined, socket-allocation failure reaches vSocketBind with FREERTOS_INVALID_SOCKET and crashes the Linux host reproducer. The original DHCPv6Process CBMC proof passes because its socket stubs exclude or accept this invalid value.
prvCreateDHCPv6Socket checks socket creation only with configASSERT, then binds it. vSocketBind dereferences the socket after another assertion. With assertions compiled out, neither check handles allocation failure. DHCPv4 already guards binding with xSocketValid and leaves the socket NULL on failure.
Target
- Development board: none; this is a host reproduction. Target hardware was not tested.
- Instruction Set Architecture: x86-64.
- IDE and version: command-line build; no IDE used.
- Toolchain and version: GCC 11.4.0 with AddressSanitizer/UndefinedBehaviorSanitizer, plus a separate
-O2build without sanitizers.
Host
- Host OS: Ubuntu Linux.
- Version: 22.04.5 LTS.
To Reproduce
Required conditions: ipconfigUSE_IPv6=1, ipconfigUSE_DHCPv6=1, no configASSERT definition, and FreeRTOS_socket failure. The test simulates heap exhaustion via pvPortMalloc; DHCP and socket implementations are unmodified. Kernel/timer stand-ins are local, and unexpected calls abort.
Tested on Linux x86_64, GCC 11.4.0, at V4.4.2 / b86ad086e9870099bb0ac18a75dcb7f6dd508cc7, still current main on 2026-11-15; pinned kernel dbf70559b27d39c1fdb68dfb9a32140b6a6777a0. Target hardware was not tested.
Host reproducer: save these four files alongside the checkout
dhcpv6-test/config/FreeRTOSIPConfig.h:
/* FreeRTOS-Plus-TCP configuration for this host test: IPv4 + IPv6 with DHCPv6 enabled.
* Everything else uses the defaults from FreeRTOSIPConfigDefaults.h. */
#ifndef FREERTOS_IP_CONFIG_H
#define FREERTOS_IP_CONFIG_H
#define ipconfigUSE_IPv4 ( 1 )
#define ipconfigUSE_IPv6 ( 1 )
#define ipconfigUSE_DHCPv6 ( 1 )
#define ipconfigBYTE_ORDER pdFREERTOS_LITTLE_ENDIAN
#define ipconfigHAS_PRINTF ( 1 )
#define FreeRTOS_printf( X ) printf X
#endif
dhcpv6-test/config/FreeRTOSConfig.h:
/* The kernel configuration used by the project's unit tests
* (test/unit-test/ConfigFiles/FreeRTOSConfig.h), but without configASSERT. */
#include_next "FreeRTOSConfig.h"
#undef configASSERT
dhcpv6-test/dhcpv6_socket_fail.c:
/* Host test: one DHCPv6 start (vDHCPv6Process( pdTRUE, ... ), as the IP task does when an
* end-point comes up) while the heap is exhausted. FreeRTOS_DHCPv6.c and FreeRTOS_Sockets.c
* are the unmodified library sources; only the kernel/heap/timer functions below are stand-ins. */
#include <stdio.h>
#include <stdlib.h>
#include "FreeRTOS.h"
#include "FreeRTOS_IP.h"
#include "FreeRTOS_IP_Private.h"
#include "FreeRTOS_DHCP.h"
#include "FreeRTOS_DHCPv6.h"
static int xHeapExhausted = 0;
void * pvPortMalloc( size_t xSize )
{
return xHeapExhausted ? NULL : malloc( xSize );
}
void vPortFree( void * pv )
{
free( pv );
}
BaseType_t xIPIsNetworkTaskReady( void )
{
return pdTRUE; /* DHCPv6 runs in the IP task. */
}
void vPortEnterCritical( void )
{
}
void vPortExitCritical( void )
{
}
TickType_t xTaskGetTickCount( void )
{
return 0;
}
void vDHCP_RATimerReload( NetworkEndPoint_t * pxEndPoint,
TickType_t uxClockTicks )
{
}
void vIPSetDHCP_RATimerEnableState( NetworkEndPoint_t * pxEndPoint,
BaseType_t xEnableState )
{
}
eDHCPCallbackAnswer_t xApplicationDHCPHook_Multi( eDHCPCallbackPhase_t eDHCPPhase,
struct xNetworkEndPoint * pxEndPoint,
IP_Address_t * pxIPAddress )
{
return eDHCPContinue;
}
void vIPNetworkUpCalls( NetworkEndPoint_t * pxEndPoint )
{
printf( "vIPNetworkUpCalls(): DHCPv6 gave up, using the static address\n" );
}
int main( void )
{
static NetworkEndPoint_t xEndPoint;
static DHCPMessage_IPv6_t xDHCPMessage;
setvbuf( stdout, NULL, _IONBF, 0 );
xEndPoint.bits.bIPv6 = pdTRUE_UNSIGNED;
xEndPoint.bits.bWantDHCP = pdTRUE_UNSIGNED;
xEndPoint.pxDHCPMessage = &xDHCPMessage;
vNetworkSocketsInit();
xHeapExhausted = 1;
printf( "configASSERT %s, heap exhausted\n", configASSERT_DEFINED ? "defined" : "not defined" );
printf( "vDHCPv6Process( pdTRUE ) ...\n" );
vDHCPv6Process( pdTRUE, &xEndPoint );
printf( "returned; xDHCPSocket = %p\n", ( void * ) xEndPoint.xDHCPData.xDHCPSocket );
/* Next cycle of the state machine (the IP task does this on the DHCP timer event). */
xEndPoint.xDHCPData.eExpectedState = xEndPoint.xDHCPData.eDHCPState;
vDHCPv6Process( pdFALSE, &xEndPoint );
printf( "returned; DHCP state = %d (eNotUsingLeasedAddress = %d)\n",
( int ) xEndPoint.xDHCPData.eDHCPState, ( int ) eNotUsingLeasedAddress );
return 0;
}
dhcpv6-test/not_called.c:
/* Functions and data that FreeRTOS_DHCPv6.c and FreeRTOS_Sockets.c refer to but that this
* test does not reach. Each function aborts if it is called. */
#include <stdio.h>
#include <stdlib.h>
#define NOT_CALLED( f ) \
void f( void ) \
{ \
fprintf( stderr, "unexpected call: %s\n", # f ); \
abort(); \
}
void * pxNetworkEndPoints = NULL;
int xTCPWindowLoggingLevel = 0;
NOT_CALLED( FreeRTOS_FindEndPointOnIP_IPv4 ) NOT_CALLED( FreeRTOS_GetTCPStateName )
NOT_CALLED( FreeRTOS_inet_ntop4 ) NOT_CALLED( FreeRTOS_inet_ntop6 )
NOT_CALLED( FreeRTOS_inet_pton4 ) NOT_CALLED( FreeRTOS_inet_pton6 )
NOT_CALLED( FreeRTOS_max_size_t ) NOT_CALLED( FreeRTOS_min_int32 )
NOT_CALLED( FreeRTOS_min_size_t ) NOT_CALLED( FreeRTOS_ReleaseUDPPayloadBuffer )
NOT_CALLED( FreeRTOS_round_up ) NOT_CALLED( pxGetNetworkBufferWithDescriptor )
NOT_CALLED( pxTCPSocketLookup_IPv6 ) NOT_CALLED( pxUDPPayloadBuffer_to_NetworkBuffer )
NOT_CALLED( ulApplicationTimeHook ) NOT_CALLED( uxGetMinimumFreeNetworkBuffers )
NOT_CALLED( uxGetNumberOfFreeNetworkBuffers ) NOT_CALLED( uxIPHeaderSizePacket )
NOT_CALLED( vEventGroupDelete ) NOT_CALLED( vReleaseNetworkBufferAndDescriptor )
NOT_CALLED( vReleaseSinglePacketFromUDPSocket ) NOT_CALLED( vTaskSetTimeOutState )
NOT_CALLED( vTaskSuspendAll ) NOT_CALLED( vTCPStateChange ) NOT_CALLED( vTCPWindowDestroy )
NOT_CALLED( xApplicationGetRandomNumber )
NOT_CALLED( xEventGroupCreate ) NOT_CALLED( xEventGroupSetBits ) NOT_CALLED( xEventGroupWaitBits )
NOT_CALLED( xIsCallingFromIPTask ) NOT_CALLED( xRecv_Update_IPv4 ) NOT_CALLED( xRecv_Update_IPv6 )
NOT_CALLED( xSendEventStructToIPTask ) NOT_CALLED( xSendEventToIPTask )
NOT_CALLED( xSend_UDP_Update_IPv4 ) NOT_CALLED( xSend_UDP_Update_IPv6 )
NOT_CALLED( xTaskCheckForTimeOut ) NOT_CALLED( xTaskResumeAll ) NOT_CALLED( xTCPSocketCheck )
git clone https://github.com/FreeRTOS/FreeRTOS-Plus-TCP.git
git -C FreeRTOS-Plus-TCP checkout b86ad086e9870099bb0ac18a75dcb7f6dd508cc7
git -C FreeRTOS-Plus-TCP submodule update --init --checkout test/FreeRTOS-Kernel
T="$PWD/FreeRTOS-Plus-TCP"
gcc -std=gnu99 -g -fsanitize=address,undefined \
-I dhcpv6-test/config -I "$T/test/unit-test/ConfigFiles" \
-I "$T/source/include" -I "$T/source/portable/Compiler/GCC" \
-I "$T/test/FreeRTOS-Kernel/include" \
dhcpv6-test/dhcpv6_socket_fail.c dhcpv6-test/not_called.c \
"$T/source/FreeRTOS_DHCPv6.c" "$T/source/FreeRTOS_Sockets.c" \
"$T/source/FreeRTOS_BitConfig.c" "$T/source/FreeRTOS_Stream_Buffer.c" \
"$T/test/FreeRTOS-Kernel/list.c" -o repro
ASAN_OPTIONS=detect_leaks=0 ./repro
ASan/UBSan reports an invalid access in vSocketBind at FreeRTOS_Sockets.c:1906, called from prvCreateDHCPv6Socket:906. An -O2 build without sanitizers also terminates with SIGSEGV. Enabling configASSERT stops at the socket-creation assertion instead. Under the same heap-failure condition, DHCPv4 returns normally and falls back to the static address.
Expected behavior
Handle invalid socket creation before setting options or binding. A local patch that follows DHCPv4's validity check and resets the failed socket to NULL lets DHCPv6 use its existing static-address fallback.
Screenshots
Not applicable; the failure is reported by ASan/UBSan in the terminal.
Wireshark logs
Not applicable; this local allocation-failure test does not exchange network packets.
Additional context
The CBMC harness has two modeling gaps: xSocketValid assumes its argument is valid before checking it, and the vSocketBind stub requires only non-NULL, allowing FREERTOS_INVALID_SOCKET.
| CBMC 6.3.1 configuration | Result |
|---|---|
| Original proof | Pass, 257 properties |
| Remove validity assumptions | Fail at socket-creation assertion |
Also compile out configASSERT |
Pass, 255 properties |
| Also require a valid socket in the bind stub | Fail at vSocketBind.assertion.1 |
| Source validity-check fix, with all three model changes | Pass, 254 properties |
Three proof changes, applied in order
proof-1-xsocketvalid.diff:
--- a/test/cbmc/proofs/DHCPv6/DHCPv6Process/DHCPv6Process_harness.c
+++ b/test/cbmc/proofs/DHCPv6/DHCPv6Process/DHCPv6Process_harness.c
@@ -101,9 +101,5 @@
*/
BaseType_t xSocketValid( const ConstSocket_t xSocket )
{
- /* The assumption is needed to make sure prvCreateDHCPv6Socket is
- * creating a valid socket. */
- __CPROVER_assume( xSocket != FREERTOS_INVALID_SOCKET );
- __CPROVER_assume( xSocket != NULL );
return( ( xSocket != FREERTOS_INVALID_SOCKET ) && ( xSocket != NULL ) );
}
proof-2-no-configassert.diff:
--- a/test/cbmc/proofs/DHCPv6/DHCPv6Process/Makefile.json
+++ b/test/cbmc/proofs/DHCPv6/DHCPv6Process/Makefile.json
@@ -15,6 +15,7 @@
"DEF":
[
"ipconfigUSE_DHCPv6=1",
+ "'configASSERT(X)='",
"FR_RECV_FROM_SUCCESS_COUNT={LOOP_UNWIND_COUNT}",
"ENDPOINT_DNS_ADDRESS_COUNT={ENDPOINT_DNS_ADDRESS_COUNT}"
],
proof-3-vsocketbind.diff:
--- a/test/cbmc/proofs/DHCPv6/DHCPv6Process/DHCPv6Process_harness.c
+++ b/test/cbmc/proofs/DHCPv6/DHCPv6Process/DHCPv6Process_harness.c
@@ -116,4 +116,4 @@
- __CPROVER_assert( pxSocket != NULL,
- "FreeRTOS precondition: pxSocket != NULL" );
+ __CPROVER_assert( ( pxSocket != NULL ) && ( pxSocket != FREERTOS_INVALID_SOCKET ),
+ "FreeRTOS precondition: xSocketValid( pxSocket )" );
__CPROVER_assert( pxBindAddress != NULL,
"FreeRTOS precondition: pxBindAddress != NULL" );
From the checkout root, after saving the three files there:
git apply proof-1-xsocketvalid.diff
git apply proof-2-no-configassert.diff
git apply proof-3-vsocketbind.diff
cd test/cbmc/proofs
python3 prepare.py
cd DHCPv6/DHCPv6Process
make -B veryclean goto
make -s cbmc
Use CBMC 6.3.1 and the 32-bit libc headers required by the project's proof build. Inspect cbmc.xml for the failing vSocketBind.assertion.1; the make target can exit successfully even when the XML reports failure.
- Lingua principale
- C
- Stelle
- 215
- Fork
- 222
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di FreeRTOS/FreeRTOS-Plus-TCP
-
bug
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 63/100
FreeRTOS/FreeRTOS-Plus-TCP#1395 ·
-
bug
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 95/100
FreeRTOS/FreeRTOS-Plus-TCP#1389 ·
-
bug
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 88/100
FreeRTOS/FreeRTOS-Plus-TCP#1388 ·
-
[BUG] PhyHandling incorrectly lists LAN8742A as having 19 PHYCRForse già presa @StitchLilo626 l’ha presa 41 giorni fa. Apertabug
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 78/100
FreeRTOS/FreeRTOS-Plus-TCP#1361 ·
-
bug
Difficoltà 3/5 1-2 giorni Idoneità per principianti 66/100
FreeRTOS/FreeRTOS-Plus-TCP#1392 · 1 commento ·
Tutte le issue di FreeRTOS/FreeRTOS-Plus-TCP
Issue simili
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
qoretechnologies/qore#8222 ·
I maintainer di solito rispondono entro 1 giorno
-
c easy first-contributor first-contributors good first issue help wanted up-for-grabs
Difficoltà 1/5 1-3 ore Idoneità per principianti 96/100
fork-commit-merge/fork-commit-merge#8696 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
libsdl-org/SDL#16873 ·
I maintainer di solito rispondono entro 1 giorno