Commit 7a765a5e authored by Zekun Shen's avatar Zekun Shen Committed by Kelsey Skunberg

net: alx: fix race condition in alx_remove

BugLink: https://bugs.launchpad.net/bugs/1885932

[ Upstream commit e89df5c4 ]

There is a race condition exist during termination. The path is
alx_stop and then alx_remove. An alx_schedule_link_check could be called
before alx_stop by interrupt handler and invoke alx_link_check later.
Alx_stop frees the napis, and alx_remove cancels any pending works.
If any of the work is scheduled before termination and invoked before
alx_remove, a null-ptr-deref occurs because both expect alx->napis[i].

This patch fix the race condition by moving cancel_work_sync functions
before alx_free_napis inside alx_stop. Because interrupt handler can call
alx_schedule_link_check again, alx_free_irq is moved before
cancel_work_sync calls too.
Signed-off-by: default avatarZekun Shen <bruceshenzk@gmail.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
Signed-off-by: default avatarKamal Mostafa <kamal@canonical.com>
Signed-off-by: default avatarKelsey Skunberg <kelsey.skunberg@canonical.com>
parent d530908f
...@@ -872,8 +872,12 @@ static int __alx_open(struct alx_priv *alx, bool resume) ...@@ -872,8 +872,12 @@ static int __alx_open(struct alx_priv *alx, bool resume)
static void __alx_stop(struct alx_priv *alx) static void __alx_stop(struct alx_priv *alx)
{ {
alx_halt(alx);
alx_free_irq(alx); alx_free_irq(alx);
cancel_work_sync(&alx->link_check_wk);
cancel_work_sync(&alx->reset_wk);
alx_halt(alx);
alx_free_rings(alx); alx_free_rings(alx);
} }
...@@ -1406,9 +1410,6 @@ static void alx_remove(struct pci_dev *pdev) ...@@ -1406,9 +1410,6 @@ static void alx_remove(struct pci_dev *pdev)
struct alx_priv *alx = pci_get_drvdata(pdev); struct alx_priv *alx = pci_get_drvdata(pdev);
struct alx_hw *hw = &alx->hw; struct alx_hw *hw = &alx->hw;
cancel_work_sync(&alx->link_check_wk);
cancel_work_sync(&alx->reset_wk);
/* restore permanent mac address */ /* restore permanent mac address */
alx_set_macaddr(hw, hw->perm_addr); alx_set_macaddr(hw, hw->perm_addr);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment