Skip to contentSkip to conversation

rtld.c: LD_PRELOAD bugfix

PATCH Maninder Singh 2 participants 2 messages Nov 7, 2015 – Nov 9, 2015

lore
Share & tools
lore
#0 lore raw

Hi,
Ping....

Quoted 72 lines

This patch do following things:-
1. Fixes bug of adding preloaded libs in search scope of dependent
libraries which results in search scope of few symbols becomes same for executable and library, so conflict doesn't occur for those symbols and hence resulted in less number of conflicts.
2. Reduce code redundancy.
3. Buffer Overflow fix.

---
trunk/src/rtld/rtld.c | 27 ++++++++++++++++-----------

1 files changed, 16 insertions(+), 11 deletions(-)
trunk/src/rtld/rtld.c +16 -11
index 50461b6..8af5052 100644
@@ -606,7 +606,7 @@ load_dsos (DSO *dso, int host_paths)
 {
  struct dso_list *dso_list, *dso_list_tail, *cur_dso_ent, *new_dso_ent;
  struct stat64 st;
-  int total_preload = 0;
+  int total_preload = 0, temp_total_preload = 0;
  char * libname[MAX_PRELOADED_LIBS] = {NULL};
 
  /* Assume it's static unless we find DT_NEEDED entries */
@@ -632,19 +632,19 @@ load_dsos (DSO *dso, int host_paths)
 
  if(dso->ehdr.e_type == ET_EXEC && ld_preload) {
      char *next_lib =  ld_preload;
-      libname[total_preload] = ld_preload;
-      total_preload++;
-      next_lib=strchr(ld_preload,':');
-      while(next_lib!=NULL){
-	  *next_lib = '\0';
-	  next_lib++;
-	  libname[total_preload] = next_lib;
-	  total_preload++;
-	  next_lib=strchr(next_lib,':');
-      }
+      while(*next_lib != '\0' && (total_preload < MAX_PRELOADED_LIBS)){
+        libname[total_preload++] = next_lib;
+        next_lib=strchrnul(next_lib,':');
+        if(*next_lib == '\0')
+          break;
+        *next_lib = '\0';
+        next_lib++;
+     }
+    temp_total_preload = total_preload;
  }
  else {
      total_preload = 0;
+      temp_total_preload = 0;
  }
  while (cur_dso_ent != NULL)
    {
@@ -666,6 +666,11 @@ load_dsos (DSO *dso, int host_paths)
 	{
 	  int ndx, maxndx;
 	  maxndx = data->d_size / cur_dso->shdr[cur_dso->dynamic].sh_entsize;
+      if(!(cur_dso->ehdr.e_type == ET_EXEC))
+        total_preload = 0;
+      else
+        total_preload = temp_total_preload;
+
 	  for (ndx = 0; ndx < maxndx + total_preload; ++ndx)
 	    {
 
Signature · 1 line
1.7.1
#1 lore raw
Quoted 2 lines · Maninder Singh

Hi,
Ping....

I'd gotten a msg after this to hold off and wait for an update. Is this the updated version of the fix?

--Mark

Quoted 72 lines
Quoted 72 lines

This patch do following things:-
1. Fixes bug of adding preloaded libs in search scope of dependent
libraries which results in search scope of few symbols becomes same for executable and library, so conflict doesn't occur for those symbols and hence resulted in less number of conflicts.
2. Reduce code redundancy.
3. Buffer Overflow fix.

---
trunk/src/rtld/rtld.c | 27 ++++++++++++++++-----------

1 files changed, 16 insertions(+), 11 deletions(-)
trunk/src/rtld/rtld.c +16 -11
index 50461b6..8af5052 100644
@@ -606,7 +606,7 @@ load_dsos (DSO *dso, int host_paths)
 {
  struct dso_list *dso_list, *dso_list_tail, *cur_dso_ent, *new_dso_ent;
  struct stat64 st;
-  int total_preload = 0;
+  int total_preload = 0, temp_total_preload = 0;
  char * libname[MAX_PRELOADED_LIBS] = {NULL};
 
  /* Assume it's static unless we find DT_NEEDED entries */
@@ -632,19 +632,19 @@ load_dsos (DSO *dso, int host_paths)
 
  if(dso->ehdr.e_type == ET_EXEC && ld_preload) {
      char *next_lib =  ld_preload;
-      libname[total_preload] = ld_preload;
-      total_preload++;
-      next_lib=strchr(ld_preload,':');
-      while(next_lib!=NULL){
-	  *next_lib = '\0';
-	  next_lib++;
-	  libname[total_preload] = next_lib;
-	  total_preload++;
-	  next_lib=strchr(next_lib,':');
-      }
+      while(*next_lib != '\0' && (total_preload < MAX_PRELOADED_LIBS)){
+        libname[total_preload++] = next_lib;
+        next_lib=strchrnul(next_lib,':');
+        if(*next_lib == '\0')
+          break;
+        *next_lib = '\0';
+        next_lib++;
+     }
+    temp_total_preload = total_preload;
  }
  else {
      total_preload = 0;
+      temp_total_preload = 0;
  }
  while (cur_dso_ent != NULL)
    {
@@ -666,6 +666,11 @@ load_dsos (DSO *dso, int host_paths)
 	{
 	  int ndx, maxndx;
 	  maxndx = data->d_size / cur_dso->shdr[cur_dso->dynamic].sh_entsize;
+      if(!(cur_dso->ehdr.e_type == ET_EXEC))
+        total_preload = 0;
+      else
+        total_preload = temp_total_preload;
+
 	  for (ndx = 0; ndx < maxndx + total_preload; ++ndx)
 	    {
 
Signature · 1 line
1.7.1