Skip to contentSkip to conversation

octeontx2-pf: Fix several bugs in exception paths

PATCH Superseded Ziyang Xuan 2 participants 5 messages Nov 25, 2022 – Dec 2, 2022

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover octeontx2-pf: Fix several bugs in exception paths

Find several obvious bugs during code review in exception paths. Provide this patchset to fix them. Not tested, just compiled.

Ziyang Xuan (2):
octeontx2-pf: Fix potential memory leak in otx2_init_tc()
octeontx2-pf: Fix a potential double free in otx2_sq_free_sqbs()

 drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.c | 1 +
 drivers/net/ethernet/marvell/octeontx2/nic/otx2_tc.c     | 7 ++++++-
 2 files changed, 7 insertions(+), 1 deletion(-)
Signature · 1 line
2.25.1
#1 lore raw

PATCH 1/2 octeontx2-pf: Fix potential memory leak in otx2_init_tc()

In otx2_init_tc(), if rhashtable_init() failed, it does not free tc->tc_entries_bitmap which is allocated in otx2_tc_alloc_ent_bitmap().

Fixes 2e2a8126ffac ("octeontx2-pf: Unify flow management variables")
---
 drivers/net/ethernet/marvell/octeontx2/nic/otx2_tc.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
drivers/net/ethernet/marvell/octeontx2/nic/otx2_tc.c +6 -1
index e64318c110fd..6a01ab1a6e6f 100644
@@ -1134,7 +1134,12 @@ int otx2_init_tc(struct otx2_nic *nic)
 		return err;
 
 	tc->flow_ht_params = tc_flow_ht_params;
-	return rhashtable_init(&tc->flow_table, &tc->flow_ht_params);
+	err = rhashtable_init(&tc->flow_table, &tc->flow_ht_params);
+	if (err) {
+		kfree(tc->tc_entries_bitmap);
+		tc->tc_entries_bitmap = NULL;
+	}
+	return err;
 }
 EXPORT_SYMBOL(otx2_init_tc);
 
Signature · 1 line
2.25.1
#2 lore raw

PATCH 2/2 octeontx2-pf: Fix a potential double free in otx2_sq_free_sqbs()

In reply to Ziyang Xuan

otx2_sq_free_sqbs() will be called twice when goto "err_free_nix_queues" label in otx2_init_hw_resources(). The first calling is within otx2_free_sq_res() at "err_free_nix_queues" label, and the second calling is at later "err_free_sq_ptrs" label.

In otx2_sq_free_sqbs(), If sq->sqb_ptrs[i] is not 0, the memory page it points to will be freed, and sq->sqb_ptrs[i] do not be assigned 0 after memory page be freed. If otx2_sq_free_sqbs() is called twice, the memory page pointed by sq->sqb_ptrs[i] will be freeed twice. To fix the bug, assign 0 to sq->sqb_ptrs[i] after memory page be freed.

Fixes caa2da34fd25 ("octeontx2-pf: Initialize and config queues")
---
 drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.c | 1 +
 1 file changed, 1 insertion(+)
drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.c +1 -0
index 9e10e7471b88..5a25fe51d102 100644
@@ -1146,6 +1146,7 @@ void otx2_sq_free_sqbs(struct otx2_nic *pfvf)
 					     DMA_FROM_DEVICE,
 					     DMA_ATTR_SKIP_CPU_SYNC);
 			put_page(virt_to_page(phys_to_virt(pa)));
+			sq->sqb_ptrs[sqb] = 0;
 		}
 		sq->sqb_count = 0;
 	}
Signature · 1 line
2.25.1
maintainer
#3 lore raw

Re: [PATCH net 2/2] octeontx2-pf: Fix a potential double free in otx2_sq_free_sqbs()

Hello,

Quoted 22 lines · Ziyang Xuan

otx2_sq_free_sqbs() will be called twice when goto "err_free_nix_queues" label in otx2_init_hw_resources(). The first calling is within otx2_free_sq_res() at "err_free_nix_queues" label, and the second calling is at later "err_free_sq_ptrs" label.

In otx2_sq_free_sqbs(), If sq->sqb_ptrs[i] is not 0, the memory page it points to will be freed, and sq->sqb_ptrs[i] do not be assigned 0 after memory page be freed. If otx2_sq_free_sqbs() is called twice, the memory page pointed by sq->sqb_ptrs[i] will be freeed twice. To fix the bug, assign 0 to sq->sqb_ptrs[i] after memory page be freed.

Fixes caa2da34fd25 ("octeontx2-pf: Initialize and config queues")
---
 drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.c | 1 +
 1 file changed, 1 insertion(+)
drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.c +0 -0
index 9e10e7471b88..5a25fe51d102 100644

drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.c void otx2_sq_free_sqbs(struct otx2_nic *pfvf) · line 1149

Quoted 4 lines
drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.c +1 -0
@@ -1146,6 +1146,7 @@ void otx2_sq_free_sqbs(struct otx2_nic *pfvf)
 					     DMA_FROM_DEVICE,
 					     DMA_ATTR_SKIP_CPU_SYNC);
 			put_page(virt_to_page(phys_to_virt(pa)));
+			sq->sqb_ptrs[sqb] = 0;

The above looks not needed...

drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.c void otx2_sq_free_sqbs(struct otx2_nic *pfvf) · line 1151

Quoted 2 lines
drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.c +0 -0
 		}
 		sq->sqb_count = 0;

... as this will prevent the next invocation of otx2_sq_free_sqbs() from traversing and freeing any sq->sqb_ptrs[] element.

Cheers,

Paolo

Quoted 1 line
drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.c +0 -0
 	}
#4 lore raw

Re: [PATCH net 2/2] octeontx2-pf: Fix a potential double free in otx2_sq_free_sqbs()

Quoted 31 lines

Hello,

Quoted 22 lines · Ziyang Xuan

otx2_sq_free_sqbs() will be called twice when goto "err_free_nix_queues" label in otx2_init_hw_resources(). The first calling is within otx2_free_sq_res() at "err_free_nix_queues" label, and the second calling is at later "err_free_sq_ptrs" label.

In otx2_sq_free_sqbs(), If sq->sqb_ptrs[i] is not 0, the memory page it points to will be freed, and sq->sqb_ptrs[i] do not be assigned 0 after memory page be freed. If otx2_sq_free_sqbs() is called twice, the memory page pointed by sq->sqb_ptrs[i] will be freeed twice. To fix the bug, assign 0 to sq->sqb_ptrs[i] after memory page be freed.

Fixes caa2da34fd25 ("octeontx2-pf: Initialize and config queues")
---
 drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.c | 1 +
 1 file changed, 1 insertion(+)
drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.c +0 -0
index 9e10e7471b88..5a25fe51d102 100644

drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.c void otx2_sq_free_sqbs(struct otx2_nic *pfvf) · line 1149

Quoted 4 lines
drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.c +1 -0
@@ -1146,6 +1146,7 @@ void otx2_sq_free_sqbs(struct otx2_nic *pfvf)
 					     DMA_FROM_DEVICE,
 					     DMA_ATTR_SKIP_CPU_SYNC);
 			put_page(virt_to_page(phys_to_virt(pa)));
+			sq->sqb_ptrs[sqb] = 0;

The above looks not needed...

Quoted 5 lines

drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.c void otx2_sq_free_sqbs(struct otx2_nic *pfvf) · line 1151

Quoted 2 lines
drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.c +0 -0
 		}
 		sq->sqb_count = 0;

... as this will prevent the next invocation of otx2_sq_free_sqbs() from traversing and freeing any sq->sqb_ptrs[] element.

Yes, you are right. I did pay much attention to sq->sqb_ptrs[], and omitted the for loop condition.

Thank you!

Quoted 9 lines

Cheers,

Paolo

drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.c void otx2_sq_free_sqbs(struct otx2_nic *pfvf) · line 1152

Quoted 1 line
drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.c +0 -0
 	}

.