Add heap protector to allocted heap blocks #1125
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
When a block was allocated to the user by
pvPortMalloc
, itspxNextFreeBlock
was set to NULL and not XORed with the canary (whenconfigENABLE_HEAP_PROTECTOR
was set to 1). As a result, a memory corruption which setspxNextFreeBlock
to zero wont be detected.This PR XORs
pxNextFreeBlock
with the canary before returning the block to the user. This would ensure that a memory corruption would get detected ifpxNextFreeBlock
is modified. The only time it won't be caught is whenpxNextFreeBlock
is updated to the canary value. Since canary values changes on every run, it is unlikely that a memory corruption would setpxNextFreeBlock
to the canary value on every run.Test Steps
I have tested the FreeRTOS/Demo test on the RISCV platform for heap_4 and heap_5.
Checklist:
Related Issue
https://forums.freertos.org/t/queuestion-about-configenable-heap-protector-in-heap-5/21229
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.