[1/1] net/txgbe: fix use-after-free on remove

Message ID 06a89892aa1b37996e5e629b3488c59d565393bd.1684393730.git.wangyunjian@huawei.com (mailing list archive)
State Accepted, archived
Delegated to: Ferruh Yigit
Headers
Series [1/1] net/txgbe: fix use-after-free on remove |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/loongarch-compilation success Compilation OK
ci/loongarch-unit-testing success Unit Testing PASS
ci/Intel-compilation fail Compilation issues
ci/github-robot: build fail github build: failed
ci/intel-Testing fail Testing issues
ci/iol-mellanox-Performance success Performance Testing PASS
ci/iol-intel-Performance success Performance Testing PASS
ci/iol-broadcom-Functional success Functional Testing PASS
ci/iol-intel-Functional success Functional Testing PASS
ci/iol-broadcom-Performance success Performance Testing PASS
ci/iol-aarch64-unit-testing success Testing PASS
ci/iol-unit-testing success Testing PASS
ci/iol-abi-testing success Testing PASS
ci/intel-Functional success Functional PASS
ci/iol-aarch64-compile-testing success Testing PASS
ci/iol-x86_64-compile-testing success Testing PASS
ci/iol-testing success Testing PASS
ci/iol-x86_64-unit-testing success Testing PASS

Commit Message

Yunjian Wang May 18, 2023, 7:11 a.m. UTC
  When cleaning up NIC's interrupts, it is possible to add some alarms
at the same time. However, if these alarms are not canceled, it may
cause use-after-free problems. Therefore, after cleaning up NIC's
interrupts, these alarms should also be canceled.

Fixes: d3bb4a04eac1 ("net/txgbe: add SFP hotplug identification")
Fixes: e0d876ef6bbc ("net/txgbe: support device stop and close")
Cc: stable@dpdk.org

Reported-by: Pengfei Sun <sunpengfei16@huawei.com>
Signed-off-by: Yunjian Wang <wangyunjian@huawei.com>
---
 drivers/net/txgbe/txgbe_ethdev.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
  

Comments

Jiawen Wu May 18, 2023, 7:46 a.m. UTC | #1
> When cleaning up NIC's interrupts, it is possible to add some alarms
> at the same time. However, if these alarms are not canceled, it may
> cause use-after-free problems. Therefore, after cleaning up NIC's
> interrupts, these alarms should also be canceled.
> 
> Fixes: d3bb4a04eac1 ("net/txgbe: add SFP hotplug identification")
> Fixes: e0d876ef6bbc ("net/txgbe: support device stop and close")
> Cc: stable@dpdk.org
> 
> Reported-by: Pengfei Sun <sunpengfei16@huawei.com>
> Signed-off-by: Yunjian Wang <wangyunjian@huawei.com>
> ---
>  drivers/net/txgbe/txgbe_ethdev.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/net/txgbe/txgbe_ethdev.c b/drivers/net/txgbe/txgbe_ethdev.c
> index a502618bc5..a3d7461951 100644
> --- a/drivers/net/txgbe/txgbe_ethdev.c
> +++ b/drivers/net/txgbe/txgbe_ethdev.c
> @@ -2032,8 +2032,10 @@ txgbe_dev_close(struct rte_eth_dev *dev)
>  		rte_delay_ms(100);
>  	} while (retries++ < (10 + TXGBE_LINK_UP_TIME));
> 
> -	/* cancel the delay handler before remove dev */
> +	/* cancel all alarm handler before remove dev */
>  	rte_eal_alarm_cancel(txgbe_dev_interrupt_delayed_handler, dev);
> +	rte_eal_alarm_cancel(txgbe_dev_detect_sfp, dev);
> +	rte_eal_alarm_cancel(txgbe_dev_setup_link_alarm_handler, dev);
> 
>  	/* uninitialize PF if max_vfs not zero */
>  	txgbe_pf_host_uninit(dev);
> --
> 2.33.0
> 
> 

Reviewed-by: Jiawen Wu <jiawenwu@trustnetic.com>
  
Ferruh Yigit May 18, 2023, 5:49 p.m. UTC | #2
On 5/18/2023 8:46 AM, Jiawen Wu wrote:
>> When cleaning up NIC's interrupts, it is possible to add some alarms
>> at the same time. However, if these alarms are not canceled, it may
>> cause use-after-free problems. Therefore, after cleaning up NIC's
>> interrupts, these alarms should also be canceled.
>>
>> Fixes: d3bb4a04eac1 ("net/txgbe: add SFP hotplug identification")
>> Fixes: e0d876ef6bbc ("net/txgbe: support device stop and close")
>> Cc: stable@dpdk.org
>>
>> Reported-by: Pengfei Sun <sunpengfei16@huawei.com>
>> Signed-off-by: Yunjian Wang <wangyunjian@huawei.com>
>> ---
>>  drivers/net/txgbe/txgbe_ethdev.c | 4 +++-
>>  1 file changed, 3 insertions(+), 1 deletion(-)
>>
>> diff --git a/drivers/net/txgbe/txgbe_ethdev.c b/drivers/net/txgbe/txgbe_ethdev.c
>> index a502618bc5..a3d7461951 100644
>> --- a/drivers/net/txgbe/txgbe_ethdev.c
>> +++ b/drivers/net/txgbe/txgbe_ethdev.c
>> @@ -2032,8 +2032,10 @@ txgbe_dev_close(struct rte_eth_dev *dev)
>>  		rte_delay_ms(100);
>>  	} while (retries++ < (10 + TXGBE_LINK_UP_TIME));
>>
>> -	/* cancel the delay handler before remove dev */
>> +	/* cancel all alarm handler before remove dev */
>>  	rte_eal_alarm_cancel(txgbe_dev_interrupt_delayed_handler, dev);
>> +	rte_eal_alarm_cancel(txgbe_dev_detect_sfp, dev);
>> +	rte_eal_alarm_cancel(txgbe_dev_setup_link_alarm_handler, dev);
>>
>>  	/* uninitialize PF if max_vfs not zero */
>>  	txgbe_pf_host_uninit(dev);
>> --
>> 2.33.0
>>
>>
> 
> Reviewed-by: Jiawen Wu <jiawenwu@trustnetic.com>
> 
> 

Applied to dpdk-next-net/main, thanks.
  

Patch

diff --git a/drivers/net/txgbe/txgbe_ethdev.c b/drivers/net/txgbe/txgbe_ethdev.c
index a502618bc5..a3d7461951 100644
--- a/drivers/net/txgbe/txgbe_ethdev.c
+++ b/drivers/net/txgbe/txgbe_ethdev.c
@@ -2032,8 +2032,10 @@  txgbe_dev_close(struct rte_eth_dev *dev)
 		rte_delay_ms(100);
 	} while (retries++ < (10 + TXGBE_LINK_UP_TIME));
 
-	/* cancel the delay handler before remove dev */
+	/* cancel all alarm handler before remove dev */
 	rte_eal_alarm_cancel(txgbe_dev_interrupt_delayed_handler, dev);
+	rte_eal_alarm_cancel(txgbe_dev_detect_sfp, dev);
+	rte_eal_alarm_cancel(txgbe_dev_setup_link_alarm_handler, dev);
 
 	/* uninitialize PF if max_vfs not zero */
 	txgbe_pf_host_uninit(dev);