]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
dpdk: NULL freed variables
authorLukas Sismis <lsismis@oisf.net>
Tue, 25 Mar 2025 11:31:48 +0000 (12:31 +0100)
committerVictor Julien <victor@inliniac.net>
Mon, 31 Mar 2025 17:16:50 +0000 (19:16 +0200)
The DPDKDeviceResourcesDeinit function now accepts second-level
reference to NULL the provided variable after deinitialization..

src/runmode-dpdk.c
src/util-dpdk-common.c
src/util-dpdk-common.h
src/util-dpdk.c

index e1b071721a6bf8e2b5e829b77b9e716dc4b4110e..f13e27d006fe00314e9a73a4f22e9c39f8bcc598 100644 (file)
@@ -336,7 +336,7 @@ static void DPDKDerefConfig(void *conf)
     DPDKIfaceConfig *iconf = (DPDKIfaceConfig *)conf;
 
     if (SC_ATOMIC_SUB(iconf->ref, 1) == 1) {
-        DPDKDeviceResourcesDeinit(iconf->pkt_mempools);
+        DPDKDeviceResourcesDeinit(&iconf->pkt_mempools);
         SCFree(iconf);
     }
     SCReturn;
@@ -1464,6 +1464,7 @@ static int DeviceConfigureQueues(DPDKIfaceConfig *iconf, const struct rte_eth_de
         if (retval < 0) {
             SCLogError("%s: failed to setup TX queue %u: %s", iconf->iface, queue_id,
                     rte_strerror(-retval));
+            retval = -1; // the error code explained, informing about failure
             goto cleanup;
         }
     }
@@ -1471,7 +1472,7 @@ static int DeviceConfigureQueues(DPDKIfaceConfig *iconf, const struct rte_eth_de
     SCReturnInt(0);
 
 cleanup:
-    DPDKDeviceResourcesDeinit(iconf->pkt_mempools);
+    DPDKDeviceResourcesDeinit(&iconf->pkt_mempools);
     SCReturnInt(retval);
 }
 
index 5ef967b1418f9f49d434e65b804061c571571f51..52b8d77060407e5395cdf5021b6d88cc54a560e1 100644 (file)
@@ -47,21 +47,22 @@ int DPDKDeviceResourcesInit(DPDKDeviceResources **dpdk_vars, uint16_t mp_cnt)
     SCReturnInt(0);
 }
 
-void DPDKDeviceResourcesDeinit(DPDKDeviceResources *dpdk_vars)
+void DPDKDeviceResourcesDeinit(DPDKDeviceResources **dpdk_vars)
 {
-    if (dpdk_vars != NULL) {
-        if (dpdk_vars->pkt_mp != NULL) {
-            for (int j = 0; j < dpdk_vars->pkt_mp_capa; j++) {
-                if (dpdk_vars->pkt_mp[j] != NULL) {
-                    rte_mempool_free(dpdk_vars->pkt_mp[j]);
+    if ((*dpdk_vars) != NULL) {
+        if ((*dpdk_vars)->pkt_mp != NULL) {
+            for (int j = 0; j < (*dpdk_vars)->pkt_mp_capa; j++) {
+                if ((*dpdk_vars)->pkt_mp[j] != NULL) {
+                    rte_mempool_free((*dpdk_vars)->pkt_mp[j]);
                 }
             }
-            SCFree(dpdk_vars->pkt_mp);
-            dpdk_vars->pkt_mp_capa = 0;
-            dpdk_vars->pkt_mp_cnt = 0;
-            dpdk_vars->pkt_mp = NULL;
+            SCFree((*dpdk_vars)->pkt_mp);
+            (*dpdk_vars)->pkt_mp_capa = 0;
+            (*dpdk_vars)->pkt_mp_cnt = 0;
+            (*dpdk_vars)->pkt_mp = NULL;
         }
-        SCFree(dpdk_vars);
+        SCFree(*dpdk_vars);
+        *dpdk_vars = NULL;
     }
 }
 
index 9a2779dc7c959863d2f36c70334722acaa8692d2..0caa2ac3711be34d0ac5b01f929f83981304d774 100644 (file)
@@ -124,7 +124,7 @@ typedef struct {
 } DPDKDeviceResources;
 
 int DPDKDeviceResourcesInit(DPDKDeviceResources **dpdk_vars, uint16_t mp_cnt);
-void DPDKDeviceResourcesDeinit(DPDKDeviceResources *dpdk_vars);
+void DPDKDeviceResourcesDeinit(DPDKDeviceResources **dpdk_vars);
 
 #endif /* HAVE_DPDK */
 
index 22ac12efc1b2714b874feaa7d26ec0e42e27e44d..09e05ccd0ea09333d6f78e3a79bb6c8662edeb02 100644 (file)
@@ -60,7 +60,7 @@ void DPDKFreeDevice(LiveDevice *ldev)
 #ifdef HAVE_DPDK
     if (SCRunmodeGet() == RUNMODE_DPDK) {
         SCLogDebug("%s: releasing packet mempools", ldev->dev);
-        DPDKDeviceResourcesDeinit(ldev->dpdk_vars);
+        DPDKDeviceResourcesDeinit(&ldev->dpdk_vars);
     }
 #endif
 }