History

libbpf: Do not require executable permission for shared libraries

Currently, resolve_full_path() requires executable permission for both programs and shared libraries. This causes failures on distos like Debian since the shared libraries are not installed executable and Linux is not requiring shared libraries to have executable permissions. Let's remove executable permission check for shared libraries.

Hengqi Chen committed 4 years ago

Commit 9e320841 parent 0c9a7a71 file · +5 −3Browse files

Unified · Split

tools/lib/bpf/libbpf.c+5−3
@@ -10664,15 +10664,17 @@ static const char *arch_specific_lib_paths(void) · 10663 unmodified lines
1066410664 static int resolve_full_path(const char *file, char *result, size_t result_sz)
1066510665 {
1066610666 const char *search_paths[3] = {};
10667− int i;
10667+ int i, perm;
1066810668
1066910669 if (str_has_sfx(file, ".so") || strstr(file, ".so.")) {
1067010670 search_paths[0] = getenv("LD_LIBRARY_PATH");
1067110671 search_paths[1] = "/usr/lib64:/usr/lib";
1067210672 search_paths[2] = arch_specific_lib_paths();
10673+ perm = R_OK;
1067310674 } else {
1067410675 search_paths[0] = getenv("PATH");
1067510676 search_paths[1] = "/usr/bin:/usr/sbin";
10677+ perm = R_OK | X_OK;
1067610678 }
1067710679
1067810680 for (i = 0; i < ARRAY_SIZE(search_paths); i++) {
@@ -10691,8 +10693,8 @@ static int resolve_full_path(const char *file, char *result, size_t result_sz) · 12 unmodified lines
1069110693 if (!seg_len)
1069210694 continue;
1069310695 snprintf(result, result_sz, "%.*s/%s", seg_len, s, file);
10694− /* ensure it is an executable file/link */
10695− if (access(result, R_OK | X_OK) < 0)
10696+ /* ensure it has required permissions */
10697+ if (access(result, perm) < 0)
1069610698 continue;
1069710699 pr_debug("resolved '%s' to '%s'\n", file, result);
1069810700 return 0;