Skip to content

Commit

Permalink
Remove unsecure library loading by removing marker file logic on Andr…
Browse files Browse the repository at this point in the history
…oid (#168)

* Remove marker file logic to find dynamic itt library on Android

* API version update
  • Loading branch information
eparshut authored Jan 14, 2025
1 parent dd9593a commit 854e7c6
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 116 deletions.
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

0 comments on commit 854e7c6

Please sign in to comment.