Commit 55ee9961 authored by Maria Matejka's avatar Maria Matejka
Browse files

Fix of shutdown: premature log cleanup led to use-after-free

parent bb63e99d
Loading
Loading
Loading
Loading
+16 −4
Original line number Diff line number Diff line
@@ -387,6 +387,21 @@ default_log_list(int initial, const char **syslog_name)
  return &log_list;
}

void
log_cleanup(int syslog)
{
  struct log_config *l;

  if (current_log_list)
    WALK_LIST(l, *current_log_list)
      if (l->rf)
	log_close(l);

  if (syslog && current_syslog_name)
    closelog();
}


void
log_switch(int initial, list *logs, const char *new_syslog_name)
{
@@ -399,10 +414,7 @@ log_switch(int initial, list *logs, const char *new_syslog_name)
    logs = default_log_list(initial, &new_syslog_name);

  /* Close the logs to avoid pinning them on disk when deleted */
  if (current_log_list)
    WALK_LIST(l, *current_log_list)
      if (l->rf)
	log_close(l);
  log_cleanup(0);

  /* Reopen the logs, needed for 'configure undo' */
  if (logs)
+4 −1
Original line number Diff line number Diff line
@@ -202,7 +202,9 @@ sysdep_preconfig(struct config *c)
int
sysdep_commit(struct config *new, struct config *old UNUSED)
{
  if (!new->shutdown)
    log_switch(0, &new->logfiles, new->syslog_name);

  return 0;
}

@@ -613,6 +615,7 @@ sysdep_shutdown_done(void)
  unlink_pid_file();
  unlink(path_control_socket);
  log_msg(L_FATAL "Shutdown completed");
  log_cleanup(1);
  exit(0);
}

+1 −0
Original line number Diff line number Diff line
@@ -122,6 +122,7 @@ void krt_io_init(void);
void main_thread_init(void);
void log_init_debug(char *);		/* Initialize debug dump to given file (NULL=stderr, ""=off) */
void log_switch(int initial, list *l, const char *);
void log_cleanup(int syslog);

struct log_config {
  node n;