Skip to content

Instantly share code, notes, and snippets.

@larytet
Last active November 11, 2023 02:33
Show Gist options
  • Save larytet/32869f59d664fe4164430028a25365ba to your computer and use it in GitHub Desktop.
Save larytet/32869f59d664fe4164430028a25365ba to your computer and use it in GitHub Desktop.
Get absolute path of the executable in the Linux kernel, context of do_exec() kprobe/SystemTap
static char* get_exe_name(int pid, char *buffer, int buffer_size)
{
char *result = NULL;
struct mm_struct* mm = current->mm;
if (mm)
{
int lock_result = down_read_trylock(&mm->mmap_sem);
if ((lock_result) && (mm->exe_file))
{
result = d_path(&mm->exe_file->f_path, buffer, buffer_size);
up_read(&mm->mmap_sem);
}
}
if (IS_ERR(result) == true)
{
return NULL;
}
return result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment