diff options
author | José Bollo <jose.bollo@iot.bzh> | 2020-02-06 09:17:52 +0100 |
---|---|---|
committer | Jan-Simon Moeller <jsmoeller@linuxfoundation.org> | 2020-02-12 13:37:19 +0000 |
commit | 44c40eaa9c923e070ab628ae759bcc01d9431aec (patch) | |
tree | 816554ab0266cc77312b97b761a0dcd501fbf917 /src/afb-api-so.c | |
parent | 00b0c28ff1c4a111a86175ac945c519315082229 (diff) |
Improves compatibility with AddressSanitizersicefish_9.0.0icefish/9.0.09.0.0
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
Diffstat (limited to 'src/afb-api-so.c')
-rw-r--r-- | src/afb-api-so.c | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/src/afb-api-so.c b/src/afb-api-so.c index 4b574879..02e986e7 100644 --- a/src/afb-api-so.c +++ b/src/afb-api-so.c @@ -20,6 +20,7 @@ #define _GNU_SOURCE #include <stdio.h> +#include <stdlib.h> #include <dlfcn.h> #include <string.h> #include <dirent.h> @@ -74,10 +75,23 @@ static int load_binding(const char *path, int force, struct afb_apiset *declare_ 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 */ rc = -!!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()); @@ -85,6 +99,9 @@ static int load_binding(const char *path, int force, struct afb_apiset *declare_ 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); |