esp_wifi, bt: fix task stack ownership and sizing #661
All Vouch review confidence checks passed
Residual risk 0.16 = Change Risk (0.36) × (1 − Review Confidence (0.57)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.36 · 207 lines diff across 2 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.319
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #661"
general
weight: 0.35
raffarost
With CONFIG_USERSPACE enabled, the Wi-Fi adapters allocated their task stacks with k_thread_stack_alloc(..., K_USER). That turns each stack into a dynamic kernel object whose lifetime is tied to thread permissions, so the kernel frees it as soon as no thread holds a permission on it anymore. The Wi-Fi thread structs are not kernel objects, so only the creating thread held one, and the stack went back to the heap when main() returned: it then got reused for received frames, and the task crashed with heap corruption or a jump into packet data. A K_USER stack is only needed by a thread that enters user mode, and the Wi-Fi tasks always run in supervisor mode, so they now get plain kernel stacks on every SoC, owned by the adapter until the task is deleted. For the same reason K_INHERIT_PERMS is dropped: permissions are only checked on system calls from user mode, so the flag never had any effect on these tasks.
The BT controllers run their task on one static stack each, and two of them sized it wrong. The ESP32 wrapper passed the size requested by the controller library instead of the buffer size, and ESP32-C3/S3 sized the buffer from a Kconfig option that does not exist on those SoCs, so CONFIG_ESP32_BT_CONTROLLER_STACK_SIZE had no effect. Both now use the buffer size and the right option. ESP32 and ESP32-C3 also move to a kernel stack with no thread options, like the other controllers, since the controller task never enters user mode either. Finally, every controller now rejects a stack request larger than its buffer, with an error that names the Kconfig option to increase, instead of starting the task on a stack that is too small.