All of lore.kernel.org
 help / color / mirror / Atom feed
* [Intel-wired-lan] [PATCH v2 net] ice: Avoid crash from unnecessary IDA free
@ 2021-10-04 12:15 Dave Ertman
  2021-10-13 23:15 ` Jesse Brandeburg
  0 siblings, 1 reply; 2+ messages in thread
From: Dave Ertman @ 2021-10-04 12:15 UTC (permalink / raw)
  To: intel-wired-lan

In the remove path, there is an attempt to free the aux_idx IDA whether
it was allocated or not.  This can potentially cause a crash when
unloading the driver on systems that do not initialize support for RDMA.
But, this free cannot be gated by the status bit for RDMA, since it is
allocated if the driver detects support for RDMA at probe time, but the
driver can enter into a state where RDMA is not supported after the IDA
has been allocated at probe time and this would lead to a memory leak.

Initialize aux_idx to an invalid value and check for a valid value when
unloading to determine if an IDA free is necessary.

Fixes: d25a0fc41c1f9 ("ice: Initialize RDMA support")
Reported-by: Jun Miao <jun.miao@windriver.com>
Signed-off-by: Dave Ertman <david.m.ertman@intel.com>
---
 drivers/net/ethernet/intel/ice/ice_main.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/intel/ice/ice_main.c b/drivers/net/ethernet/intel/ice/ice_main.c
index 0d6c143f6653..94037881bfd8 100644
--- a/drivers/net/ethernet/intel/ice/ice_main.c
+++ b/drivers/net/ethernet/intel/ice/ice_main.c
@@ -4224,6 +4224,9 @@ ice_probe(struct pci_dev *pdev, const struct pci_device_id __always_unused *ent)
 	if (!pf)
 		return -ENOMEM;
 
+	/* initialize Auxiliary index to invalid value */
+	pf->aux_idx = -1;
+
 	/* set up for high or low DMA */
 	err = dma_set_mask_and_coherent(dev, DMA_BIT_MASK(64));
 	if (err)
@@ -4615,7 +4618,8 @@ static void ice_remove(struct pci_dev *pdev)
 
 	ice_aq_cancel_waiting_tasks(pf);
 	ice_unplug_aux_dev(pf);
-	ida_free(&ice_aux_ida, pf->aux_idx);
+	if (pf->aux_idx >= 0)
+		ida_free(&ice_aux_ida, pf->aux_idx);
 	set_bit(ICE_DOWN, pf->state);
 
 	mutex_destroy(&(&pf->hw)->fdir_fltr_lock);
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* [Intel-wired-lan] [PATCH v2 net] ice: Avoid crash from unnecessary IDA free
  2021-10-04 12:15 [Intel-wired-lan] [PATCH v2 net] ice: Avoid crash from unnecessary IDA free Dave Ertman
@ 2021-10-13 23:15 ` Jesse Brandeburg
  0 siblings, 0 replies; 2+ messages in thread
From: Jesse Brandeburg @ 2021-10-13 23:15 UTC (permalink / raw)
  To: intel-wired-lan

On 10/4/2021 5:15 AM, Dave Ertman wrote:
> In the remove path, there is an attempt to free the aux_idx IDA whether
> it was allocated or not.  This can potentially cause a crash when
> unloading the driver on systems that do not initialize support for RDMA.
> But, this free cannot be gated by the status bit for RDMA, since it is
> allocated if the driver detects support for RDMA at probe time, but the
> driver can enter into a state where RDMA is not supported after the IDA
> has been allocated at probe time and this would lead to a memory leak.
> 
> Initialize aux_idx to an invalid value and check for a valid value when
> unloading to determine if an IDA free is necessary.
> 
> Fixes: d25a0fc41c1f9 ("ice: Initialize RDMA support")
> Reported-by: Jun Miao <jun.miao@windriver.com>
> Signed-off-by: Dave Ertman <david.m.ertman@intel.com>

Please send upstream!
With this patch applied I can now rmmod my ice driver without a panic!

Tested-by: Jesse Brandeburg <jesse.brandeburg@intel.com>



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-10-13 23:15 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-04 12:15 [Intel-wired-lan] [PATCH v2 net] ice: Avoid crash from unnecessary IDA free Dave Ertman
2021-10-13 23:15 ` Jesse Brandeburg

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.