crypto/scheduler: set null pointer after freeing
authorPablo de Lara <pablo.de.lara.guarch@intel.com>
Thu, 26 Apr 2018 15:09:49 +0000 (16:09 +0100)
committerPablo de Lara <pablo.de.lara.guarch@intel.com>
Thu, 10 May 2018 16:46:19 +0000 (17:46 +0100)
When freeing memory, pointers should be set to NULL,
to avoid memory corruption/segmentation faults.

Fixes: 31439ee72b2c ("crypto/scheduler: add API implementations")
Fixes: 50e14527b9d1 ("crypto/scheduler: improve parameters parsing")
Fixes: 57523e682bb7 ("crypto/scheduler: register operation functions")
Fixes: a783aa634410 ("crypto/scheduler: add packet size based mode")
Fixes: 4c07e0552f0a ("crypto/scheduler: add multicore scheduling mode")
Cc: stable@dpdk.org
Signed-off-by: Pablo de Lara <pablo.de.lara.guarch@intel.com>
Acked-by: Fan Zhang <roy.fan.zhang@intel.com>
drivers/crypto/scheduler/rte_cryptodev_scheduler.c
drivers/crypto/scheduler/scheduler_multicore.c
drivers/crypto/scheduler/scheduler_pkt_size_distr.c
drivers/crypto/scheduler/scheduler_pmd_ops.c

index 140c8b4..ed574cc 100644 (file)
@@ -91,8 +91,10 @@ update_scheduler_capability(struct scheduler_ctx *sched_ctx)
        struct rte_cryptodev_capabilities tmp_caps[256] = { {0} };
        uint32_t nb_caps = 0, i;
 
-       if (sched_ctx->capabilities)
+       if (sched_ctx->capabilities) {
                rte_free(sched_ctx->capabilities);
+               sched_ctx->capabilities = NULL;
+       }
 
        for (i = 0; i < sched_ctx->nb_slaves; i++) {
                struct rte_cryptodev_info dev_info;
@@ -462,8 +464,10 @@ rte_cryptodev_scheduler_load_user_scheduler(uint8_t scheduler_id,
        sched_ctx->ops.option_set = scheduler->ops->option_set;
        sched_ctx->ops.option_get = scheduler->ops->option_get;
 
-       if (sched_ctx->private_ctx)
+       if (sched_ctx->private_ctx) {
                rte_free(sched_ctx->private_ctx);
+               sched_ctx->private_ctx = NULL;
+       }
 
        if (sched_ctx->ops.create_private_ctx) {
                int ret = (*sched_ctx->ops.create_private_ctx)(dev);
index b2ce44c..15a57c3 100644 (file)
@@ -328,11 +328,13 @@ static int
 scheduler_create_private_ctx(struct rte_cryptodev *dev)
 {
        struct scheduler_ctx *sched_ctx = dev->data->dev_private;
-       struct mc_scheduler_ctx *mc_ctx;
+       struct mc_scheduler_ctx *mc_ctx = NULL;
        uint16_t i;
 
-       if (sched_ctx->private_ctx)
+       if (sched_ctx->private_ctx) {
                rte_free(sched_ctx->private_ctx);
+               sched_ctx->private_ctx = NULL;
+       }
 
        mc_ctx = rte_zmalloc_socket(NULL, sizeof(struct mc_scheduler_ctx), 0,
                        rte_socket_id());
index 96bf016..d09e849 100644 (file)
@@ -334,8 +334,10 @@ scheduler_create_private_ctx(struct rte_cryptodev *dev)
        struct scheduler_ctx *sched_ctx = dev->data->dev_private;
        struct psd_scheduler_ctx *psd_ctx;
 
-       if (sched_ctx->private_ctx)
+       if (sched_ctx->private_ctx) {
                rte_free(sched_ctx->private_ctx);
+               sched_ctx->private_ctx = NULL;
+       }
 
        psd_ctx = rte_zmalloc_socket(NULL, sizeof(struct psd_scheduler_ctx), 0,
                        rte_socket_id());
index 680c2af..147dc51 100644 (file)
@@ -46,6 +46,7 @@ scheduler_attach_init_slave(struct rte_cryptodev *dev)
                                sched_ctx->init_slave_names[i]);
 
                rte_free(sched_ctx->init_slave_names[i]);
+               sched_ctx->init_slave_names[i] = NULL;
 
                sched_ctx->nb_init_slaves -= 1;
        }
@@ -261,11 +262,15 @@ scheduler_pmd_close(struct rte_cryptodev *dev)
                }
        }
 
-       if (sched_ctx->private_ctx)
+       if (sched_ctx->private_ctx) {
                rte_free(sched_ctx->private_ctx);
+               sched_ctx->private_ctx = NULL;
+       }
 
-       if (sched_ctx->capabilities)
+       if (sched_ctx->capabilities) {
                rte_free(sched_ctx->capabilities);
+               sched_ctx->capabilities = NULL;
+       }
 
        return 0;
 }