Message ID | 1d34425a0ea8a553a66dcf4f22ca55cc920dbb42.1649913521.git.duoming@zju.edu.cn (mailing list archive) |
---|---|
State | Changes Requested |
Delegated to: | Netdev Maintainers |
Headers | show |
Series | Fix double free bugs and UAF bug in nfcmrvl module | expand |
Hello there,
Sorry here but actually I didn't "review" this patch but only offer some suggestions.
It seems that the current version of patch mainly focus on solving the data race. However, I'd prefer to make sure this function
> static void fw_dnld_over(struct nfcmrvl_private *priv, u32 error)
never be able to be called more than once. Maybe add some additional flag with lock is more appropriate.
Regards
Lin
diff --git a/drivers/nfc/nfcmrvl/fw_dnld.c b/drivers/nfc/nfcmrvl/fw_dnld.c index e83f65596a8..c22a4556db5 100644 --- a/drivers/nfc/nfcmrvl/fw_dnld.c +++ b/drivers/nfc/nfcmrvl/fw_dnld.c @@ -92,12 +92,14 @@ static struct sk_buff *alloc_lc_skb(struct nfcmrvl_private *priv, uint8_t plen) static void fw_dnld_over(struct nfcmrvl_private *priv, u32 error) { + spin_lock_irq(&priv->fw_dnld.lock); if (priv->fw_dnld.fw) { release_firmware(priv->fw_dnld.fw); priv->fw_dnld.fw = NULL; priv->fw_dnld.header = NULL; priv->fw_dnld.binary_config = NULL; } + spin_unlock_irq(&priv->fw_dnld.lock); atomic_set(&priv->ndev->cmd_cnt, 0); @@ -451,6 +453,7 @@ int nfcmrvl_fw_dnld_init(struct nfcmrvl_private *priv) if (!priv->fw_dnld.rx_wq) return -ENOMEM; skb_queue_head_init(&priv->fw_dnld.rx_q); + spin_lock_init(&priv->fw_dnld.lock); return 0; } diff --git a/drivers/nfc/nfcmrvl/fw_dnld.h b/drivers/nfc/nfcmrvl/fw_dnld.h index 7c4d91b0191..6974c307947 100644 --- a/drivers/nfc/nfcmrvl/fw_dnld.h +++ b/drivers/nfc/nfcmrvl/fw_dnld.h @@ -75,6 +75,8 @@ struct nfcmrvl_fw_dnld { struct sk_buff_head rx_q; struct timer_list timer; + /* To synchronize among different threads that call firmware.*/ + spinlock_t lock; }; int nfcmrvl_fw_dnld_init(struct nfcmrvl_private *priv);