@henningw, the problem could appears not only on FreeBSD environment, but on any ASLR environment.

I've wrote a test case for the regression close to Kamailio behavior:

libtest.c:

#include "modules.h"

static char *str= "app_lua";

int mod_register()
{
  modules_add(str);

  return 0;
}

modules.c:

#include <stdio.h>

void modules_add(char *msg)
{
  printf("modules_add(%p): %s\n", msg, msg);
}

main.c:

#include <stdio.h>
#include <dlfcn.h>
#include "modules.h"

typedef int (*mod_register_function)();

int testlib(int num) {
  mod_register_function mr;
  char* error;

  void* h = dlopen("libtest.so", RTLD_NOW);
  if (h == 0) {
    printf("Error loading\n");
    return 1;
  }
  dlerror();
  mr = (mod_register_function)dlsym(h, "mod_register");
  if ((error = (char*)dlerror()) != 0) {
    printf("dlsym error: %s\n", error);
    return 1;
  }
  printf("Call mod_register() #%d: ", num);
  mr();
  dlclose(h);

  return 0;
}

int main()
{
  int err;
  err = testlib(1);
  if (err != 0) return err;

  err = testlib(2);
  if (err != 0) return err;

  return 0;
}

And ran it on non-ASLR and ASLR environment:
non-ASLR:

boris@boris:~/aslr_test% ./aslr_test
Call mod_register() #1: modules_add(0x800646528): app_lua
Call mod_register() #2: modules_add(0x800646528): app_lua

ASLR:

boris@boris:~/aslr_test% ./aslr_test
Call mod_register() #1: modules_add(0x825abc528): app_lua
Call mod_register() #2: modules_add(0x825bfe528): app_lua

And how can we see: str address is changed on ASLR environment, and we cannot use it after reloading library.

I suppose using static variable after reloading library is incorrect way.


Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.Message ID: <kamailio/kamailio/issues/3202/1204917683@github.com>