Skip to content

Commit a2c4324

Browse files
krish2718kartben
authored andcommitted
drivers: wifi: nrf_wifi: Validate PS event TWT flow count and length
Reject malformed nrf_wifi_umac_event_power_save_info payloads before copying TWT entries into struct wifi_ps_config. The handler previously trusted num_twt_flows and indexed twt_flow_info[] without checking WIFI_MAX_TWT_FLOWS or event_len, which could overflow the fixed Zephyr twt_flows buffer and read past the event buffer. Fix issue zephyrproject-rtos#108848. Signed-off-by: Chaitanya Tata <Chaitanya.Tata@nordicsemi.no> Assisted-by: Cursor:Auto
1 parent 71e7b15 commit a2c4324

1 file changed

Lines changed: 25 additions & 0 deletions

File tree

drivers/wifi/nrf_wifi/src/wifi_mgmt.c

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
* for the Zephyr OS.
1010
*/
1111

12+
#include <stddef.h>
1213
#include <stdlib.h>
1314

1415
#include <zephyr/kernel.h>
@@ -383,13 +384,37 @@ void nrf_wifi_event_proc_get_power_save_info(void *vif_ctx,
383384
unsigned int event_len)
384385
{
385386
struct nrf_wifi_vif_ctx_zep *vif_ctx_zep = NULL;
387+
size_t twt_bytes;
388+
size_t required_len;
386389

387390
if (!vif_ctx || !ps_info) {
388391
return;
389392
}
390393

391394
vif_ctx_zep = vif_ctx;
392395

396+
if (!vif_ctx_zep->ps_info) {
397+
LOG_ERR("%s: caller ps_config pointer is NULL", __func__);
398+
return;
399+
}
400+
401+
if (ps_info->num_twt_flows > WIFI_MAX_TWT_FLOWS) {
402+
LOG_ERR("%s: num_twt_flows %u exceeds WIFI_MAX_TWT_FLOWS",
403+
__func__, ps_info->num_twt_flows);
404+
return;
405+
}
406+
407+
twt_bytes = (size_t)ps_info->num_twt_flows *
408+
sizeof(struct nrf_wifi_umac_config_twt_info);
409+
required_len = offsetof(struct nrf_wifi_umac_event_power_save_info, twt_flow_info) +
410+
twt_bytes;
411+
412+
if ((size_t)event_len < required_len) {
413+
LOG_ERR("%s: event_len %u < required %zu (num_twt_flows %u)",
414+
__func__, event_len, required_len, ps_info->num_twt_flows);
415+
return;
416+
}
417+
393418
vif_ctx_zep->ps_info->ps_params.mode = ps_info->ps_mode;
394419
vif_ctx_zep->ps_info->ps_params.enabled = ps_info->enabled;
395420
vif_ctx_zep->ps_info->num_twt_flows = ps_info->num_twt_flows;

0 commit comments

Comments
 (0)