eal: restrict default plugin path to shared lib mode
[dpdk.git] / lib / librte_eal / common / eal_common_options.c
index 6c63b93..34edd8c 100644 (file)
@@ -414,11 +414,17 @@ verify_perms(const char *dirpath)
 
        /* if not root, check down one level first */
        if (strcmp(dirpath, "/") != 0) {
+               static __thread char last_dir_checked[PATH_MAX];
                char copy[PATH_MAX];
+               const char *dir;
 
                strlcpy(copy, dirpath, PATH_MAX);
-               if (verify_perms(dirname(copy)) != 0)
-                       return -1;
+               dir = dirname(copy);
+               if (strncmp(dir, last_dir_checked, PATH_MAX) != 0) {
+                       if (verify_perms(dir) != 0)
+                               return -1;
+                       strlcpy(last_dir_checked, dir, PATH_MAX);
+               }
        }
 
        /* call stat to check for permissions and ensure not world writable */
@@ -478,8 +484,15 @@ eal_plugins_init(void)
        struct shared_driver *solib = NULL;
        struct stat sb;
 
-       if (*default_solib_dir != '\0' && stat(default_solib_dir, &sb) == 0 &&
-                               S_ISDIR(sb.st_mode))
+       /* If we are not statically linked, add default driver loading
+        * path if it exists as a directory.
+        * (Using dlopen with NOLOAD flag on EAL, will return NULL if the EAL
+        * shared library is not already loaded i.e. it's statically linked.)
+        */
+       if (dlopen("librte_eal.so", RTLD_LAZY | RTLD_NOLOAD) != NULL &&
+                       *default_solib_dir != '\0' &&
+                       stat(default_solib_dir, &sb) == 0 &&
+                       S_ISDIR(sb.st_mode))
                eal_plugin_add(default_solib_dir);
 
        TAILQ_FOREACH(solib, &solib_list, next) {