[BUG] Potential bug when size of free Heap is too large and sets allocation-bit mask
I maintainer di solito rispondono entro 3 giorni
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 2/5
- Tempo stimato
- 1-3 ore
- Idoneità per principianti
- 62/100
- Tipo di issue
- Bug
- Chiarezza
- Abbastanza chiara
- Stato di attività
- Attiva
- Stack tecnologico
- c
- Ambito
- operating-systems
Direzione di ricerca
Inizia in portable/MemMang/heap_4.c con le definizioni di heapBLOCK_ALLOCATED_BITMASK e heapBLOCK_SIZE_IS_VALID, poi leggi prvHeapInit(), dove pxFirstFreeBlock->xBlockSize viene impostato a partire da uxEndAddress. Decidi se aggiungere un configASSERT sulla dimensione calcolata o limitarti a documentare il vincolo, dato che la issue propone entrambe le opzioni. Il lavoro è completo quando il controllo o la nota sono in atto e i test dell'heap nel repository continuano a passare.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Describe the bug
heap_4.c reserves the most significant bit of BlockLink_t.xBlockSize as an allocation-status flag:
#define heapBLOCK_ALLOCATED_BITMASK \
( ( ( size_t ) 1 ) << ( ( sizeof( size_t ) * heapBITS_PER_BYTE ) - 1 ) )
prvHeapInit() does not explicitly validate the computed size of the initial free block:
pxFirstFreeBlock->xBlockSize = ( size_t ) ( uxEndAddress - ( portPOINTER_SIZE_TYPE ) pxFirstFreeBlock );
If an implementation permitted a heap whose usable size was greater than or equal to heapBLOCK_ALLOCATED_BITMASK (i.e. 0x8000000 in 32 bit systems), the initial free block would already have the allocation-status bit set as part of its size.
The allocator would then be unable to distinguish that size bit from the allocation flag.
Similarly, coalescing free blocks assumes that the resulting size remains below heapBLOCK_ALLOCATED_BITMASK. That assumption follows from the initial-heap-size, but that is not checked explicitly.
Target
- Development board: N/A; source-level and compile-time investigation
- Instruction Set Architecture: Armv7E-M/Thumb-2, 32-bit
size_t - IDE and version: N/A; command-line Makefile
- Toolchain and version: Arm GNU Toolchain 15.2.Rel1, GCC 15.2.1
Host
- Host OS: Linux under WSL2
- Version: Debian GNU/Linux 13 (trixie) Linux 6.18.33.2-microsoft-standard-WSL2, x86_64
To Reproduce
- Use
portable/MemMang/heap_4.cfrom latest FreeRTOS-Kernel commit. - Select a 32-bit Arm port where
sizeof(size_t) == 4. - Observe that bit 31 is reserved by
heapBLOCK_ALLOCATED_BITMASK. - Observe that
prvHeapInit()assigns the initial free-block size without applyingheapBLOCK_SIZE_IS_VALID()to the result. - Attempt to configure a heap large enough for the initial usable block to be at least
0x80000000bytes.
The concern would apply only to a compiler or nonstandard heap-placement mechanism that permits an object large enough to use the reserved
bit.
If tried using standard heap allocation
extern uint8_t ucHeap[ 0x80000000ULL ];
Would produce the following compiler output:
error: size of array 'ucHeap' is too large
Expected behavior
The size limitation should either be documented explicitly or checked by the implementation. For example, after calculating the initial free-block size, prvHeapInit() could assert the representation invariant:
configASSERT( heapBLOCK_SIZE_IS_VALID( pxFirstFreeBlock->xBlockSize ) != 0);
Screenshots
Not applicable
Additional context
On a target with 32-bit size_t:
heapBLOCK_ALLOCATED_BITMASK = 0x80000000
maximum representable block size without the flag = 0x7fffffff
The invalid condition is specifically when computed initial usable block size >= heapBLOCK_ALLOCATED_BITMASK
- Lingua principale
- C
- Stelle
- 4.6k
- Fork
- 1.6k
- Merge medio
- 2g 22h
- PR unite (30g)
- 4
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-Kernel
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
FreeRTOS/FreeRTOS-Kernel#1542 ·
I maintainer di solito rispondono entro 3 giorni
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
FreeRTOS/FreeRTOS-Kernel#1520 ·
I maintainer di solito rispondono entro 3 giorni
-
enhancement
Difficoltà 5/5 Più di una settimana Idoneità per principianti 25/100
FreeRTOS/FreeRTOS-Kernel#1554 ·
I maintainer di solito rispondono entro 3 giorni
-
[BUG] event_wait_timed can't return falseForse già presa @TedLyngmo l’ha presa 39 giorni fa. Apertabug
Difficoltà 2/5 1-3 ore Idoneità per principianti 38/100
FreeRTOS/FreeRTOS-Kernel#1546 ·
I maintainer di solito rispondono entro 3 giorni
-
bug
Difficoltà 4/5 3-5 giorni Idoneità per principianti 22/100
FreeRTOS/FreeRTOS-Kernel#1545 ·
I maintainer di solito rispondono entro 3 giorni
Tutte le issue di FreeRTOS/FreeRTOS-Kernel
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
-
bug
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 63/100
FreeRTOS/FreeRTOS-Plus-TCP#1395 ·
-
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