Skip to content

Add stack size validation in SecureContext_AllocateContext#1402

Merged
patrzhan merged 1 commit intoFreeRTOS:mainfrom
patrzhan:dev/alloc
Apr 16, 2026
Merged

Add stack size validation in SecureContext_AllocateContext#1402
patrzhan merged 1 commit intoFreeRTOS:mainfrom
patrzhan:dev/alloc

Conversation

@patrzhan
Copy link
Copy Markdown
Member

Validate that ulSecureStackSize + securecontextSTACK_SEAL_SIZE does not overflow before calling pvPortMalloc in the ARMv8-M secure context ports.

Reported by Jordan Mecom (Block, Inc.)

Test Steps

Change is validated on a LPCXpresso55S69 (NXP LPC55S69, Cortex-M33 with TrustZone) board.

Checklist:

  • [ X ] I have tested my changes. No regression in existing tests.
  • I have modified and/or added unit-tests to cover the code changes in this Pull Request.

Related Issue

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@codecov
Copy link
Copy Markdown

codecov bot commented Apr 16, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.37%. Comparing base (386c1bc) to head (1616e67).
⚠️ Report is 40 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1402      +/-   ##
==========================================
- Coverage   91.46%   91.37%   -0.09%     
==========================================
  Files           6        6              
  Lines        3256     3259       +3     
  Branches      899      902       +3     
==========================================
  Hits         2978     2978              
  Misses        132      132              
- Partials      146      149       +3     
Flag Coverage Δ
unittests 91.37% <ø> (-0.09%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

kstribrnAmzn
kstribrnAmzn previously approved these changes Apr 16, 2026
Comment thread portable/ARMv8M/secure/context/secure_context.c Outdated
kstribrnAmzn
kstribrnAmzn previously approved these changes Apr 16, 2026
Comment on lines +216 to +224
/* Allocate the stack space if possible. */
if( ulSecureStackSize > ( UINT32_MAX - securecontextSTACK_SEAL_SIZE ) )
{
pucStackMemory = NULL;
}
else
{
pucStackMemory = pvPortMalloc( ulSecureStackSize + securecontextSTACK_SEAL_SIZE );
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Formatting is incorrect across all the changes. We are probably not running formatter for ports. Can you please fix this?

Suggested change
/* Allocate the stack space if possible. */
if( ulSecureStackSize > ( UINT32_MAX - securecontextSTACK_SEAL_SIZE ) )
{
pucStackMemory = NULL;
}
else
{
pucStackMemory = pvPortMalloc( ulSecureStackSize + securecontextSTACK_SEAL_SIZE );
}
/* Allocate the stack space if possible. */
if( ulSecureStackSize > ( UINT32_MAX - securecontextSTACK_SEAL_SIZE ) )
{
pucStackMemory = NULL;
}
else
{
pucStackMemory = pvPortMalloc( ulSecureStackSize + securecontextSTACK_SEAL_SIZE );
}

Validate that ulSecureStackSize + securecontextSTACK_SEAL_SIZE does not
overflow before calling pvPortMalloc in the ARMv8-M secure context ports.

Reported by Jordan Mecom (Block, Inc.)
@sonarqubecloud
Copy link
Copy Markdown

@patrzhan patrzhan merged commit 7c0c890 into FreeRTOS:main Apr 16, 2026
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants