Last active
November 11, 2023 02:33
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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