[sr-dev] [kamailio/kamailio] Regression on app_lua after ASLR enable on FreeBSD (Issue #3202)

Boris Korzun notifications at github.com
Thu Aug 4 10:13:28 CEST 2022


@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_:
```c
#include "modules.h"

static char *str= "app_lua";

int mod_register()
{
  modules_add(str);

  return 0;
}
```
_modules.c_:
```c
#include <stdio.h>

void modules_add(char *msg)
{
  printf("modules_add(%p): %s\n", msg, msg);
}
```
_main.c_:
```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 at 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 at 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 or view it on GitHub:
https://github.com/kamailio/kamailio/issues/3202#issuecomment-1204917683
You are receiving this because you are subscribed to this thread.

Message ID: <kamailio/kamailio/issues/3202/1204917683 at github.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.kamailio.org/pipermail/sr-dev/attachments/20220804/e9455ca1/attachment.htm>


More information about the sr-dev mailing list