Re: [PATCH 4.4 026/124] iwlwifi: pcie: fix race in Rx buffer allocator

From: Ben Hutchings
Date: Wed Sep 05 2018 - 14:39:26 EST


On Sat, 2018-08-04 at 11:00 +0200, Greg Kroah-Hartman wrote:
> 4.4-stable review patch.ÂÂIf anyone has any objections, please let me know.
>
> ------------------
>
> From: Shaul Triebitz <shaul.triebitz@xxxxxxxxx>
>
> [ Upstream commit 0f22e40053bd5378ad1e3250e65c574fd61c0cd6 ]
>
> Make sure the rx_allocator worker is canceled before running the
> rx_init routine.ÂÂrx_init frees and re-allocates all rxb's pages.ÂÂThe
> rx_allocator worker also allocates pages for the used rxb's.ÂÂRunning
> rx_init and rx_allocator simultaniously causes a kernel panic.ÂÂFix
> that by canceling the work in rx_init.
>
> Signed-off-by: Shaul Triebitz <shaul.triebitz@xxxxxxxxx>
> Signed-off-by: Luca Coelho <luciano.coelho@xxxxxxxxx>
> Signed-off-by: Sasha Levin <alexander.levin@xxxxxxxxxxxxx>
> Signed-off-by: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx>
> ---
> Âdrivers/net/wireless/iwlwifi/pcie/rx.c |ÂÂÂÂ2 ++
> Â1 file changed, 2 insertions(+)
>
> --- a/drivers/net/wireless/iwlwifi/pcie/rx.c
> +++ b/drivers/net/wireless/iwlwifi/pcie/rx.c
> @@ -713,6 +713,8 @@ int iwl_pcie_rx_init(struct iwl_trans *t
> Â WQ_HIGHPRI | WQ_UNBOUND, 1);
> Â INIT_WORK(&rba->rx_alloc, iwl_pcie_rx_allocator_work);
> Â
> + cancel_work_sync(&rba->rx_alloc);
> +
> Â spin_lock(&rba->lock);
> Â atomic_set(&rba->req_pending, 0);
> Â atomic_set(&rba->req_ready, 0);

This seems to be an incomplete fix. INIT_WORK() will overwrite the
list pointers in the work item, so there is still a race condition.

I think that the RX initialisation and reinitialisation/reset cases
need to be explicitly distinguished. In the initialisation case the
driver should do only INIT_WORK() and in the reset case it should do
only cancel_work_sync() (although it would be safe to do INIT_WORK()
*after* that).

Ben.

--
Ben Hutchings, Software Developer  Codethink Ltd
https://www.codethink.co.uk/ Dale House, 35 Dale Street
Manchester, M1 2HF, United Kingdom