bcmf_driver: add ioctl_mutex to restrict ioctl from reentrant

avoiding resource race conditions

Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
This commit is contained in:
zhanghongyu 2023-12-18 11:33:08 +08:00 committed by Xiang Xiao
parent 518f130ad3
commit 009a1eba7c
3 changed files with 17 additions and 13 deletions

View File

@ -1143,7 +1143,6 @@ int bcmf_wl_get_interface(FAR struct bcmf_dev_s *priv, FAR struct iwreq *iwr)
FAR struct bcmf_dev_s *bcmf_allocate_device(void)
{
int ret;
FAR struct bcmf_dev_s *priv;
/* Allocate a bcmf device structure */
@ -1160,25 +1159,20 @@ FAR struct bcmf_dev_s *bcmf_allocate_device(void)
/* Init control frames mutex and timeout signal */
if ((ret = nxsem_init(&priv->control_mutex, 0, 1)) != OK)
{
goto exit_free_priv;
}
nxsem_init(&priv->control_mutex, 0, 1);
nxsem_init(&priv->control_timeout, 0, 0);
if ((ret = nxsem_init(&priv->control_timeout, 0, 0)) != OK)
{
goto exit_free_priv;
}
/* Init ioctl mutex */
#ifdef CONFIG_NETDEV_IOCTL
nxmutex_init(&priv->ioctl_mutex);
#endif
/* Init scan timeout timer */
priv->scan_status = BCMF_SCAN_DISABLED;
return priv;
exit_free_priv:
kmm_free(priv);
return NULL;
}
/****************************************************************************

View File

@ -82,6 +82,9 @@ struct bcmf_dev_s
uint16_t control_rxdata_len; /* Received control frame out buffer length */
FAR uint8_t *control_rxdata; /* Received control frame out buffer */
uint32_t control_status; /* Last received frame status */
#ifdef CONFIG_NETDEV_IOCTL
mutex_t ioctl_mutex; /* Avoid handle multiple ioctl requests */
#endif
/* AP Scan state machine.
* During scan, control_mutex is locked to prevent control requests

View File

@ -936,6 +936,11 @@ static int bcmf_ioctl(FAR struct net_driver_s *dev, int cmd,
return -EPERM;
}
if ((ret = nxmutex_lock(&priv->ioctl_mutex)) < 0)
{
return ret;
}
#ifdef CONFIG_IEEE80211_BROADCOM_LOWPOWER
bcmf_lowpower_poll(priv);
#endif
@ -1072,6 +1077,8 @@ static int bcmf_ioctl(FAR struct net_driver_s *dev, int cmd,
break;
}
nxmutex_unlock(&priv->ioctl_mutex);
return ret;
}
#endif