iavf: fix potential deadlock on allocation failure
Subsystems (2)
PATCH 1/2 iavf: fix potential deadlock on allocation failure
In iavf_adminq_task(), if kzalloc() fails to allocate the event.msg_buf, the function will exit without releasing the adapter->crit_lock.
This is unlikely, but if it happens, the next access to that mutex will deadlock.
Fix this by moving the unlock to the end of the function, and adding a new label to allow jumping to the unlock portion of the function exit flow.
--- drivers/net/ethernet/intel/iavf/iavf_main.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/net/ethernet/intel/iavf/iavf_main.c +3 -2
@@ -3264,7 +3264,7 @@ static void iavf_adminq_task(struct work_struct *work) event.buf_len =IAVF_MAX_AQ_BUF_SIZE ; event.msg_buf =kzalloc (event.buf_len,GFP_KERNEL );if (!event.msg_buf) - goto out; + goto unlock; do { ret = iavf_clean_arq_element(hw, &event, &pending);
@@ -3279,7 +3279,6 @@ static void iavf_adminq_task(struct work_struct *work)if (pending !=0 )memset (event.msg_buf,0 ,IAVF_MAX_AQ_BUF_SIZE ); }while (pending); -mutex_unlock (&adapter->crit_lock);if (iavf_is_reset_in_progress (adapter)) goto freedom;
@@ -3323,6 +3322,8 @@ static void iavf_adminq_task(struct work_struct *work) freedom:kfree (event.msg_buf); +unlock: +mutex_unlock (&adapter->crit_lock); out:/* re-enable Admin queue interrupt cause */ iavf_misc_irq_enable (adapter);
base-commit: b4e87f37b7fc4e0408a1a67b60839c4f2e6fa40f
Signature · 6 lines
2.41.0.1.g9857a21e0017.dirty _______________________________________________ Intel-wired-lan mailing list [email protected] https://lists.osuosl.org/mailman/listinfo/intel-wired-lan
PATCH 2/2 iavf: check for removal state before IAVF_FLAG_PF_COMMS_FAILED
In iavf_adminq_task(), if the function can't acquire the adapter->crit_lock, it checks if the driver is removing. If so, it simply exits without re-enabling the interrupt. This is done to ensure that the task stops processing as soon as possible once the driver is being removed.
However, if the IAVF_FLAG_PF_COMMS_FAILED is set, the function checks this before attempting to acquire the lock. In this case, the function exits early and re-enables the interrupt. This will happen even if the driver is already removing.
Avoid this, by moving the check to after the adapter->crit_lock is acquired. This way, if the driver is removing, we will not re-enable the interrupt.
--- drivers/net/ethernet/intel/iavf/iavf_main.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/net/ethernet/intel/iavf/iavf_main.c +3 -3
@@ -3250,9 +3250,6 @@ static void iavf_adminq_task(struct work_struct *work)u32 val, oldval;u16 pending; -if (adapter->flags &IAVF_FLAG_PF_COMMS_FAILED ) - goto out; -if (!mutex_trylock (&adapter->crit_lock)) {if (adapter->state == __IAVF_REMOVE)return ;
@@ -3261,6 +3258,9 @@ static void iavf_adminq_task(struct work_struct *work) goto out; } +if (adapter->flags &IAVF_FLAG_PF_COMMS_FAILED ) + goto unlock; + event.buf_len =IAVF_MAX_AQ_BUF_SIZE ; event.msg_buf =kzalloc (event.buf_len,GFP_KERNEL );if (!event.msg_buf)
Signature · 6 lines
2.41.0.1.g9857a21e0017.dirty _______________________________________________ Intel-wired-lan mailing list [email protected] https://lists.osuosl.org/mailman/listinfo/intel-wired-lan
Re: [Intel-wired-lan] [PATCH iwl-net 2/2] iavf: check for removal state before IAVF_FLAG_PF_COMMS_FAILED
drivers/net/ethernet/intel/iavf/iavf_main.c
Quoted 35 lines
-----Original Message-----
From: Intel-wired-lan <[email protected]> On Behalf Of Jacob Keller
Sent: poniedziałek, 10 lipca 2023 22:41
To: Intel Wired LAN <[email protected]>; Chittim, Madhu <[email protected]>; Nguyen, Anthony L <[email protected]>
Subject: [Intel-wired-lan] [PATCH iwl-net 2/2] iavf: check for removal state beforeIAVF_FLAG_PF_COMMS_FAILEDIn
iavf_adminq_task(), if the function can't acquire theadapter->crit_lock, it checks if the driver is removing. If so, itadapter->simply
exits without re-enabling the interrupt. This is done to ensure that the task stops processing as soon as possible once the driver is being removed.However, if the
IAVF_FLAG_PF_COMMS_FAILEDis set, the function checks this before attempting to acquire the lock. In this case, the function exits early and re-enables the interrupt. This will happen even if the driver is already removing.Avoid this, by moving the check to after the
adapter->crit_lockis acquired. This way, if the driver is removing, we will not re-enable the interrupt.Fixes fc2e6b3b132a ("iavf: Rework mutexes for better synchronisation")Signed-off-by Jacob Keller <[email protected]>--- drivers/net/ethernet/intel/iavf/iavf_main.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)drivers/net/ethernet/intel/iavf/iavf_main.c +0
-0
_______________________________________________
Intel-wired-lan mailing list
[email protected]
https://lists.osuosl.org/mailman/listinfo/intel-wired-lan
drivers/net/ethernet/intel/iavf/iavf_main.c static void iavf_adminq_task(struct work_struct
Quoted 30 lines
-----Original Message-----
From: Intel-wired-lan <[email protected]> On Behalf Of Jacob Keller
Sent: poniedziałek, 10 lipca 2023 22:41
To: Intel Wired LAN <[email protected]>; Chittim, Madhu <[email protected]>; Nguyen, Anthony L <[email protected]>
Subject: [Intel-wired-lan] [PATCH iwl-net 1/2] iavf: fix potential deadlock on allocation failureIn
iavf_adminq_task(), ifkzalloc()fails to allocate the event.msg_buf, the function will exit without releasing theadapter->crit_lock.This is unlikely, but if it happens, the next access to that mutex will deadlock.
Fix this by moving the unlock to the end of the function, and adding a new label to allow jumping to the unlock portion of the function exit flow.
Fixes fc2e6b3b132a ("iavf: Rework mutexes for better synchronisation")Signed-off-by Jacob Keller <[email protected]>--- drivers/net/ethernet/intel/iavf/iavf_main.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)drivers/net/ethernet/intel/iavf/iavf_main.c +0
-0@@ -3264,7 +3264,7 @@ static void iavf_adminq_task(struct work_struct
_______________________________________________
Intel-wired-lan mailing list
[email protected]
https://lists.osuosl.org/mailman/listinfo/intel-wired-lan