Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove unsecure library loading by removing marker file logic on Android #168

Merged
merged 2 commits into from
Jan 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/ittnotify/ittnotify_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -208,10 +208,10 @@
#define ITT_MAGIC { 0xED, 0xAB, 0xAB, 0xEC, 0x0D, 0xEE, 0xDA, 0x30 }

/* Replace with snapshot date YYYYMMDD for promotion build. */
#define API_VERSION_BUILD 20230630
#define API_VERSION_BUILD 20250113

#ifndef API_VERSION_NUM
#define API_VERSION_NUM 3.24.6
#define API_VERSION_NUM 3.25.4
#endif /* API_VERSION_NUM */

#define API_VERSION "ITT-API-Version " ITT_TO_STR(API_VERSION_NUM) \
Expand Down
114 changes: 0 additions & 114 deletions src/ittnotify/ittnotify_static.c
Original file line number Diff line number Diff line change
Expand Up @@ -1258,120 +1258,6 @@ static const char* __itt_get_env_var(const char* name)
static const char* __itt_get_lib_name(void)
{
const char* lib_name = __itt_get_env_var(ITT_TO_STR(LIB_VAR_NAME));

#ifdef __ANDROID__
if (lib_name == NULL)
{

#if ITT_ARCH==ITT_ARCH_IA32 || ITT_ARCH==ITT_ARCH_ARM
const char* const marker_filename = "com.intel.itt.collector_lib_32";
#else
const char* const marker_filename = "com.intel.itt.collector_lib_64";
#endif

char system_wide_marker_filename[PATH_MAX] = {0};
int itt_marker_file_fd = -1;
ssize_t res = 0;

res = snprintf(system_wide_marker_filename, PATH_MAX - 1, "%s%s", "/data/local/tmp/", marker_filename);
if (res < 0)
{
ITT_ANDROID_LOGE("Unable to concatenate marker file string.");
return lib_name;
}
itt_marker_file_fd = open(system_wide_marker_filename, O_RDONLY);

if (itt_marker_file_fd == -1)
{
const pid_t my_pid = getpid();
char cmdline_path[PATH_MAX] = {0};
char package_name[PATH_MAX] = {0};
char app_sandbox_file[PATH_MAX] = {0};
int cmdline_fd = 0;

ITT_ANDROID_LOGI("Unable to open system-wide marker file.");
res = snprintf(cmdline_path, PATH_MAX - 1, "/proc/%d/cmdline", my_pid);
if (res < 0)
{
ITT_ANDROID_LOGE("Unable to get cmdline path string.");
return lib_name;
}

ITT_ANDROID_LOGI("CMD file: %s\n", cmdline_path);
cmdline_fd = open(cmdline_path, O_RDONLY);
if (cmdline_fd == -1)
{
ITT_ANDROID_LOGE("Unable to open %s file!", cmdline_path);
return lib_name;
}
res = read(cmdline_fd, package_name, PATH_MAX - 1);
if (res == -1)
{
ITT_ANDROID_LOGE("Unable to read %s file!", cmdline_path);
res = close(cmdline_fd);
if (res == -1)
{
ITT_ANDROID_LOGE("Unable to close %s file!", cmdline_path);
}
return lib_name;
}
res = close(cmdline_fd);
if (res == -1)
{
ITT_ANDROID_LOGE("Unable to close %s file!", cmdline_path);
return lib_name;
}
ITT_ANDROID_LOGI("Package name: %s\n", package_name);
res = snprintf(app_sandbox_file, PATH_MAX - 1, "/data/data/%s/%s", package_name, marker_filename);
if (res < 0)
{
ITT_ANDROID_LOGE("Unable to concatenate marker file string.");
return lib_name;
}

ITT_ANDROID_LOGI("Lib marker file name: %s\n", app_sandbox_file);
itt_marker_file_fd = open(app_sandbox_file, O_RDONLY);
if (itt_marker_file_fd == -1)
{
ITT_ANDROID_LOGE("Unable to open app marker file!");
return lib_name;
}
}

{
char itt_lib_name[PATH_MAX] = {0};

res = read(itt_marker_file_fd, itt_lib_name, PATH_MAX - 1);
if (res == -1)
{
ITT_ANDROID_LOGE("Unable to read %s file!", itt_marker_file_fd);
res = close(itt_marker_file_fd);
if (res == -1)
{
ITT_ANDROID_LOGE("Unable to close %s file!", itt_marker_file_fd);
}
return lib_name;
}
ITT_ANDROID_LOGI("ITT Lib path: %s", itt_lib_name);
res = close(itt_marker_file_fd);
if (res == -1)
{
ITT_ANDROID_LOGE("Unable to close %s file!", itt_marker_file_fd);
return lib_name;
}
ITT_ANDROID_LOGI("Set env %s to %s", ITT_TO_STR(LIB_VAR_NAME), itt_lib_name);
res = setenv(ITT_TO_STR(LIB_VAR_NAME), itt_lib_name, 0);
if (res == -1)
{
ITT_ANDROID_LOGE("Unable to set env var!");
return lib_name;
}
lib_name = __itt_get_env_var(ITT_TO_STR(LIB_VAR_NAME));
ITT_ANDROID_LOGI("ITT Lib path from env: %s", lib_name);
}
}
#endif

return lib_name;
}

Expand Down
Loading