[PATCH] lib: prevent RTLD_DEEPBIND if run with libasan
swen
swen at linux.ibm.com
Mon Jul 22 13:41:08 UTC 2019
While at it, prepare lib code to run with ASAN
without the need to set the flag LDB_MODULES_DISABLE_DEEPBIND.
Please review and push if happy.
Cheers Swen
-------------- next part --------------
From 74aed6333e5c4b970ffe55728be8808e9607788b Mon Sep 17 00:00:00 2001
From: Swen Schillig <swen at linux.ibm.com>
Date: Mon, 22 Jul 2019 15:32:46 +0200
Subject: [PATCH] lib: prevent RTLD_DEEPBIND if run with libasan
If run with ASAN sanitizer we cannot use RTLD_DEEPBIND flag for dlopen.
Signed-off-by: Swen Schillig <swen at linux.ibm.com>
---
lib/ldb/common/ldb_modules.c | 21 ++++++++++++++++++++-
1 file changed, 20 insertions(+), 1 deletion(-)
diff --git a/lib/ldb/common/ldb_modules.c b/lib/ldb/common/ldb_modules.c
index cc067abdfe0..cef29723b68 100644
--- a/lib/ldb/common/ldb_modules.c
+++ b/lib/ldb/common/ldb_modules.c
@@ -939,7 +939,26 @@ static int ldb_modules_load_path(const char *path, const char *version)
int dlopen_flags;
#ifdef RTLD_DEEPBIND
- bool deepbind_enabled = (getenv("LDB_MODULES_DISABLE_DEEPBIND") == NULL);
+ const char *env_preload = getenv("LD_PRELOAD");
+ const char *env_deepbind = getenv("LDB_MODULES_DISABLE_DEEPBIND");
+ bool deepbind_enabled = true;
+
+ /* Don't do a deepbind if we run with libasan */
+ if (env_preload != NULL && strlen(env_preload) < 1024) {
+ const char *p = strstr(env_preload, "libasan.so");
+ if (p != NULL) {
+ deepbind_enabled = false;
+ }
+ }
+
+ if (env_deepbind != NULL && strlen(env_deepbind) >= 1) {
+ deepbind_enabled = false;
+ }
+
+ if (deepbind_enabled) {
+ dlopen_flags |= RTLD_DEEPBIND;
+ }
+
#endif
ret = stat(path, &st);
--
2.20.1
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: This is a digitally signed message part
URL: <http://lists.samba.org/pipermail/samba-technical/attachments/20190722/cd7e8dbe/signature.sig>
More information about the samba-technical
mailing list