vlib: mitigate outdated new cli session events 22/35722/2
authorVladislav Grishenko <themiron@yandex-team.ru>
Wed, 29 Dec 2021 09:30:32 +0000 (14:30 +0500)
committerDamjan Marion <dmarion@me.com>
Wed, 23 Mar 2022 18:27:15 +0000 (18:27 +0000)
Possible races while concurrent additon to the new sessions vector
in a one process and remove from it in an another need to be avoided.
Let the vector be changed in the new session process function only.
Also cli_file_pool element may be freed already at the new session
event arrive timepoint, still causing unexpected cli banner for
noninteracive cli sessions.

Type: fix
Fixes: 17a67218587d40541ff522c6a86f354720481fbb
Signed-off-by: Vladislav Grishenko <themiron@yandex-team.ru>
Change-Id: I022d16dd3aad9c9330834d35c58938f04b015b08

src/vlib/unix/cli.c

index e6f549b..03baf3e 100644 (file)
@@ -1312,6 +1312,10 @@ unix_cli_new_session_process (vlib_main_t * vm, vlib_node_runtime_t * rt,
            /* Add an identifier to the new session list */
            unix_cli_new_session_t ns;
 
+           /* Check the connection didn't close already */
+           if (pool_is_free_index (cm->cli_file_pool, event_data[0]))
+             break;
+
            ns.cf_index = event_data[0];
            ns.deadline = vlib_time_now (vm) + 1.0;
 
@@ -2693,7 +2697,7 @@ unix_cli_kill (unix_cli_main_t * cm, uword cli_file_index)
 
       if (ns->cf_index == cli_file_index)
        {
-         vec_del1 (cm->new_sessions, i);
+         ns->cf_index = ~0;
          break;
        }
     }