Skip to content

Potential thread stack overflow in pmTask #1632

Description

@k6dpvrmm8z-glitch

Issue details

While some detailed build configuration, There are potential stack overflow in thread function named pmTask

#define FREERTOS_MIN_STACK_SIZE 150 // M4-FPU register setup is bigger so stack needs to be bigger

#define configMINIMAL_STACK_SIZE ( ( unsigned short ) FREERTOS_MIN_STACK_SIZE )

#define PM_TASK_STACKSIZE configMINIMAL_STACK_SIZE

STATIC_MEM_TASK_ALLOC(pmTask, PM_TASK_STACKSIZE);

STATIC_MEM_TASK_CREATE(pmTask, pmTask, PM_TASK_NAME, NULL, PM_TASK_PRI);

In this line, pmTask Allows 600(150 * 4) stack size.

However, after checking the stack using our internally developed tool, it might have 612 Bytes in with some detailed configurations.

Steps to produce

1. In Makefile, add this line:

USE_OPT += -fstack-usage

This will help you automatically calculating stack size of each function.

2. Build normally, using this configurations:

(make cf2_defconfig ->) make

Now we can get stack usage file (*.su) for each source file, So we can manually check stack size of each function.

In case of pmTask :

There are large call stack with this flow:

pmTask (pmTask) => 104 bytes
ledseqRunBlocking (ledseqRunBlocking) => 24 bytes
runLedseq (runLedseq) => 56 bytes
updateActive (updateActive) => 16 bytes
ledSet (ledSet) => 16 bytes
ledSetForce.part.0 (ledSetForce.part.0) => 88 bytes
syslinkSendPacket (syslinkSendPacket) => 24 bytes
uartslkSendDataDmaBlocking (uartslkSendDataDmaBlocking) => 24 bytes
xQueueGenericSend (xQueueGenericSend) => 40 bytes
xTaskResumeAll (xTaskResumeAll) => 32 bytes
xTaskIncrementTick (xTaskIncrementTick) => 48 bytes
assertFail (assertFail) => 8 bytes
eprintf (eprintf) => 12 bytes
evprintf (evprintf) => 48 bytes
itoa10 (itoa10) => 32 bytes
itoa10Unsigned (itoa10Unsigned) => 40 bytes

SUM => 612 bytes

So, there are potentially occur stack overflow in pmTask Thread function.

Environment

Version
Commit a5c3837

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions