← Back to Pull requests

esp_wifi, bt: fix task stack ownership and sizing #661

Closed
unknown closed this pull request without merging on Sep 29, 2026 18:52 UTC
View on GitHub
unknown unknown commented on Sep 24, 2026 03:19 UTC
Author

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.

Diff: 207 lines (+155 / -52) across 2 files Reviewer: raffarost Review duration: 8133m
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
0.36
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
0.17
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
56%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq
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
Reviewers
Assignees
Unassigned
Labels
risk: low confidence: 56.8% reviewed
Vouch Risk Breakdown
AI-powered review risk analysis
Change Risk
Change Risk · Model 1 (XGBoost)
Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
Score: 36.4% (MEDIUM) · Higher = larger blast radius
36.4%
Review Confidence
Review Confidence · Models 2 & 3
Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
Score: 56.8% · Lower = rushed or shallow review
56.8%
Residual Risk
Residual Risk · Core Equation
Residual = Change × (1 − Confidence)
Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
Score: 15.7% · Safe to merge
15.7%