Address sanitizers is expecting shared objects loaded
without the flag RTLD_DEEPBIND. This can be achieved
by setting the environment variable AFB_NO_RTLD_DEEPBIND
to the value 1 (exactly).
This implies that the binder takes care of not clashing
the namespaces by defining the symbol afbBindingV3root
in both environment: the binder and the bindings.
Bug-AGL: SPEC-3040
Bug-AGL: SPEC-3162
Signed-off-by: José Bollo <jose.bollo@iot.bzh>
Change-Id: Ic064590178d4cf8b34b939e4c9ecd587668f71b8
* @see afbBindingV3
* @see @ref validity-v3
*/
* @see afbBindingV3
* @see @ref validity-v3
*/
+#if !defined(AFB_BINDING_NO_ROOT) /* use with caution, see @ref validity-v3 */
#if AFB_BINDING_VERSION != 3
extern
#endif
struct afb_api_x3 *afbBindingV3root __attribute__((weak));
#if AFB_BINDING_VERSION != 3
extern
#endif
struct afb_api_x3 *afbBindingV3root __attribute__((weak));
/**
* Pre-initialization function.
/**
* Pre-initialization function.
#define _GNU_SOURCE
#include <stdio.h>
#define _GNU_SOURCE
#include <stdio.h>
#include <dlfcn.h>
#include <string.h>
#include <dirent.h>
#include <dlfcn.h>
#include <string.h>
#include <dirent.h>
int obsolete = 0;
int rc;
void *handle;
int obsolete = 0;
int rc;
void *handle;
+ static int dlopen_flags = 0;
+
+ /* compute the dlopen flags */
+ if (dlopen_flags == 0) {
+ /* For ASan mode, export AFB_NO_RTLD_DEEPBIND=1, to disable RTLD_DEEPBIND */
+ char *string = secure_getenv("AFB_NO_RTLD_DEEPBIND");
+ if (string && string[0] == '1' && string[1] == 0)
+ dlopen_flags = RTLD_NOW | RTLD_LOCAL;
+ else
+ dlopen_flags = RTLD_NOW | RTLD_LOCAL | RTLD_DEEPBIND;
+ }
- // This is a loadable library let's check if it's a binding
+ /* set default return code rc according to force */
- handle = safe_dlopen(path, RTLD_NOW | RTLD_LOCAL | RTLD_DEEPBIND);
+
+ /* try to open the library */
+ handle = safe_dlopen(path, dlopen_flags);
if (handle == NULL) {
if (force)
ERROR("binding [%s] not loadable: %s", path, dlerror());
if (handle == NULL) {
if (force)
ERROR("binding [%s] not loadable: %s", path, dlerror());
WARNING("binding [%s] not loadable: %s", path, dlerror());
goto error;
}
WARNING("binding [%s] not loadable: %s", path, dlerror());
goto error;
}
+ /*
+ * This is a loadable library let's check if it's a binding ...
+ */
/* try the version 3 */
rc = afb_api_so_v3_add(path, handle, declare_set, call_set);
/* try the version 3 */
rc = afb_api_so_v3_add(path, handle, declare_set, call_set);
#include <json-c/json.h>
#define AFB_BINDING_VERSION 3
#include <json-c/json.h>
#define AFB_BINDING_VERSION 3
+#define AFB_BINDING_NO_ROOT
#include <afb/afb-binding.h>
#include "afb-api.h"
#include <afb/afb-binding.h>
#include "afb-api.h"
#include <json-c/json.h>
#define AFB_BINDING_VERSION 3
#include <json-c/json.h>
#define AFB_BINDING_VERSION 3
+#define AFB_BINDING_NO_ROOT
#include <afb/afb-binding.h>
#include "afb-api.h"
#include <afb/afb-binding.h>
#include "afb-api.h"
#endif
#define AFB_BINDING_VERSION 3
#endif
#define AFB_BINDING_VERSION 3
+#define AFB_BINDING_NO_ROOT
#include <afb/afb-binding.h>
#include "afb-hook.h"
#include <afb/afb-binding.h>
#include "afb-hook.h"
#include <json-c/json.h>
#define AFB_BINDING_VERSION 3
#include <json-c/json.h>
#define AFB_BINDING_VERSION 3
+#define AFB_BINDING_NO_ROOT
#include <afb/afb-binding.h>
#include "afb-cred.h"
#include <afb/afb-binding.h>
#include "afb-cred.h"