Skip to content

Commit

Permalink
Fix: Reset main kb link after fork()'ing
Browse files Browse the repository at this point in the history
This fix an issue which produce the scanner to hang because sharing redis connection without reseting them. Redis connection are not thread safe
  • Loading branch information
jjnicola committed Nov 29, 2022
1 parent faf8fe5 commit 2fa8ea8
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
14 changes: 7 additions & 7 deletions misc/plugutils.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ plug_current_vhost (void)
return current_vhost->value;
}

static int plug_fork_child (kb_t, kb_t);
static int plug_fork_child (kb_t);

void
plug_set_dep (struct script_infos *args, const char *depname)
Expand Down Expand Up @@ -266,7 +266,7 @@ plug_get_host_fqdn (struct script_infos *args)
return g_strdup (current_vhost->value);
while (vhosts)
{
int ret = plug_fork_child (get_main_kb (), args->key);
int ret = plug_fork_child (args->key);

if (ret == 0)
{
Expand Down Expand Up @@ -676,8 +676,8 @@ proto_post_wrapped (const char *oid, struct script_infos *desc, int port,
return;
}


kb_item_push_str_with_main_kb_check (get_main_kb (), "internal/results", data);
kb_item_push_str_with_main_kb_check (get_main_kb (), "internal/results",
data);
g_free (data);
g_free (buffer);
g_string_free (action_str, TRUE);
Expand Down Expand Up @@ -1099,7 +1099,7 @@ sig_n (int signo, void (*fnc) (int))
* failure
*/
static int
plug_fork_child (kb_t main, kb_t kb)
plug_fork_child (kb_t kb)
{
pid_t pid;

Expand All @@ -1109,7 +1109,7 @@ plug_fork_child (kb_t main, kb_t kb)
sig_n (SIGTERM, _exit);
mqtt_reset ();
kb_lnk_reset (kb);
kb_lnk_reset (main);
kb_lnk_reset (get_main_kb ());
nvticache_reset ();
srand48 (getpid () + getppid () + time (NULL));
return 0;
Expand Down Expand Up @@ -1189,7 +1189,7 @@ plug_get_key (struct script_infos *args, char *name, int *type, size_t *len,
res_list = res;
while (res)
{
int pret = plug_fork_child (get_main_kb (), kb);
int pret = plug_fork_child (kb);

if (pret == 0)
{
Expand Down
3 changes: 3 additions & 0 deletions nasl/nasl_builtin_find_service.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

#define SMART_TCP_RW

#include "../misc/kb_cache.h" /* for get_main_kb */
#include "../misc/network.h" /* for get_encaps_through */
#include "../misc/plugutils.h" /* for OPENVAS_ENCAPS_IP */
#include "nasl_builtin_plugins.h"
Expand Down Expand Up @@ -2583,8 +2584,10 @@ plugin_run_find_service (lex_ctxt *lexic)
if (sons[i] == 0)
{
kb_lnk_reset (kb);
kb_lnk_reset (get_main_kb ());
mqtt_reset ();
nvticache_reset ();

signal (SIGTERM, _exit);
plugin_do_run (desc, sons_args[i], test_ssl);
_exit (0);
Expand Down
2 changes: 2 additions & 0 deletions src/nasl_plugins.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
* @brief The nasl - plugin class. Loads or launches nasl- plugins.
*/

#include "../misc/kb_cache.h" /* for get_main_kb */
#include "../misc/network.h"
#include "../misc/plugutils.h" /* for plug_set_launch */
#include "../nasl/nasl.h"
Expand Down Expand Up @@ -211,6 +212,7 @@ nasl_thread (struct ipc_context *ipcc, struct script_infos *args)
nvticache_reset ();
kb = args->key;
kb_lnk_reset (kb);
kb_lnk_reset (get_main_kb ());
addr6_to_str (args->ip, ip_str);
// TODO extend sript_infos here
setproctitle ("openvas: testing %s (%s)", ip_str, args->name);
Expand Down

0 comments on commit 2fa8ea8

Please sign in to comment.