[BUG] Potential bug when size of free Heap is too large and sets allocation-bit mask
维护者通常 3 天内回复
还没有人认领这个 Issue。
评估
- 难度
- 2/5
- 预计耗时
- 1-3 小时
- 新手友好度
- 62/100
- Issue 类型
- 缺陷
- 描述清晰度
- 基本清楚
- 活跃度
- 活跃
- 技术栈
- c
调研方向
从 portable/MemMang/heap_4.c 开始,先查看 heapBLOCK_ALLOCATED_BITMASK 和 heapBLOCK_SIZE_IS_VALID 的定义,然后阅读 prvHeapInit(),其中 pxFirstFreeBlock->xBlockSize 是根据 uxEndAddress 设置的。由于该 issue 提供了两种方案,请决定是对计算出的大小添加 configASSERT,还是只记录这一限制。完成标准是检查或说明已就位,并且仓库中的堆测试仍然通过。
由索引模型根据 Issue 内容生成。
描述
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
- 主要语言
- C
- 星标
- 4.6k
- 派生
- 1.6k
- 平均合并
- 2 天 22 小时
- 30 天内合并 PR
- 4
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
FreeRTOS/FreeRTOS-Kernel 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 78/100
FreeRTOS/FreeRTOS-Kernel#1542 ·
维护者通常 3 天内回复
-
bug
难度 2/5 1-3 小时 新手友好度 72/100
FreeRTOS/FreeRTOS-Kernel#1520 ·
维护者通常 3 天内回复
-
enhancement
难度 5/5 一周以上 新手友好度 25/100
FreeRTOS/FreeRTOS-Kernel#1554 ·
维护者通常 3 天内回复
-
[BUG] event_wait_timed can't return false可能已有人在做 @TedLyngmo 于 39 天前认领。 未关闭bug
难度 2/5 1-3 小时 新手友好度 38/100
FreeRTOS/FreeRTOS-Kernel#1546 ·
维护者通常 3 天内回复
-
bug
难度 4/5 3-5 天 新手友好度 22/100
FreeRTOS/FreeRTOS-Kernel#1545 ·
维护者通常 3 天内回复
查看 FreeRTOS/FreeRTOS-Kernel 的全部 Issue
相似的 Issue
-
bug
难度 2/5 1-3 小时 新手友好度 72/100
-
难度 2/5 1-3 小时 新手友好度 72/100
-
bug
难度 1/5 1 小时以内 新手友好度 63/100
FreeRTOS/FreeRTOS-Plus-TCP#1395 ·
-
难度 2/5 1-3 小时 新手友好度 72/100
qoretechnologies/qore#8222 ·
维护者通常 1 天内回复
-
c easy first-contributor first-contributors good first issue help wanted up-for-grabs
难度 1/5 1-3 小时 新手友好度 96/100
fork-commit-merge/fork-commit-merge#8696 ·
维护者通常 1 天内回复