Fix parsing parameter errors in start and stop commands 41/68441/3
authorXavier Simonart <xavier.simonart@intel.com>
Wed, 4 Sep 2019 12:07:53 +0000 (14:07 +0200)
committerPatrice Buriez <patrice.buriez@intel.com>
Wed, 9 Oct 2019 12:12:09 +0000 (12:12 +0000)
Some wrong parameters in start (such as "start all 4" while there are only
less than 4 tasks available on some cores) and stop command could
have potentially caused a crash in some cases.

Change-Id: I6dc201575b574c53ded242ea795c35de82fb787e
Signed-off-by: Xavier Simonart <xavier.simonart@intel.com>
VNFs/DPPD-PROX/commands.c
VNFs/DPPD-PROX/lconf.c

index 50d04d2..969dec3 100644 (file)
@@ -137,10 +137,14 @@ void start_cores(uint32_t *cores, int count, int task_id)
                                        targ = &lconf->targs[tid];
                                        start_l3(targ);
                                }
-                       } else {
+                       } else if (task_id < lconf->n_tasks_all) {
                                targ = &lconf->targs[task_id];
                                start_l3(targ);
+                       } else {
+                               plog_warn("Invalid task id %d on core %u\n", task_id, cores[i]);
+                               continue;
                        }
+                       if (wait_command_handled(lconf) == -1) return;
                        lconf->msg.type = LCONF_MSG_START;
                        lconf->msg.task_id = task_id;
                        lconf_set_req(lconf);
@@ -177,6 +181,10 @@ void stop_cores(uint32_t *cores, int count, int task_id)
 
        for (int i = 0; i < count; ++i) {
                struct lcore_cfg *lconf = &lcore_cfg[cores[i]];
+               if (task_id >= lconf->n_tasks_all) {
+                       plog_warn("Trying to stop invalid task id %d on core %u\n", task_id, cores[i]);
+                       continue;
+               }
                if (lconf->n_tasks_run) {
                        if (wait_command_handled(lconf) == -1) return;
 
@@ -890,6 +898,7 @@ void cmd_reset_port(uint8_t portid)
                plog_warn("Failed to restart port %d\n", portid);
        }
 }
+
 void cmd_write_reg(uint8_t port_id, unsigned int id, unsigned int val)
 {
        if (!port_is_active(port_id)) {
index 935bac5..23ae58e 100644 (file)
@@ -127,6 +127,10 @@ static void msg_stop(struct lcore_cfg *lconf)
                                idx++;
                        }
                }
+               // Check that task id is valid and running
+               if (idx == -1)
+                       return;
+
                lconf->task_is_running[lconf->msg.task_id] = 0;
 
                t = lconf->tasks_all[lconf->msg.task_id];
@@ -155,8 +159,14 @@ static void msg_start(struct lcore_cfg *lconf)
                                t->aux->start(t);
                }
                lconf->n_tasks_run = lconf->n_tasks_all;
+               return;
        }
-       else if (lconf->n_tasks_run == 0) {
+
+       // Check that task id is valid
+       if (lconf->msg.task_id >= lconf->n_tasks_all)
+               return;
+
+       if (lconf->n_tasks_run == 0) {
                t = lconf->tasks_run[0] = lconf->tasks_all[lconf->msg.task_id];
                lconf->n_tasks_run = 1;
                lconf->task_is_running[lconf->msg.task_id] = 1;
@@ -167,9 +177,13 @@ static void msg_start(struct lcore_cfg *lconf)
                        t->aux->start(t);
        }
        else {
+               if (lconf->task_is_running[lconf->msg.task_id])
+                       return;
                for (int i = lconf->n_tasks_run - 1; i >= 0; --i) {
                        idx = lconf_get_task_id(lconf, lconf->tasks_run[i]);
                        if (idx == lconf->msg.task_id) {
+                               // We should not come here as checking earlier if task id is running...
+                               plog_warn("Unexpectedly get request to start task %d already running\n", idx);
                                break;
                        }
                        else if (idx > lconf->msg.task_id) {