I am trying to hook unlinkat.my hooking function.
but i get only file name instead of absolute path.so i want absolute path to compare string.when i try rm -r than i get only file name if i get absolute path then it works.so please tell me how i get absolute path.
my code is
long mw_sys_unlink(int dfd, const char *filename ,int flag)
{
long ret;
if( strstr(filename,"/tmp/a/"))
{
printk(KERN_INFO "file %s has not been deleted by kernel module\n", filename);
return -1;
}
else
{
ret = orig_sys_unlink(dfd ,filename,flag);
printk(KERN_INFO "file %s has been deleted", filename);
return ret;
}
}
Try the following:
char *tmp = (char*)__get_free_page(GFP_TEMPORARY);
file *file = fget(dfd);
if (!file) {
goto out
}
char *path = d_path(&file->f_path, tmp, PAGE_SIZE);
if (IS_ERR(path)) {
printk("error: %d\n", (int)path);
goto out;
}
printk("path: %s\n", path);
out:
free_page((unsigned long)tmp);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With