Open Dinakaranevil opened 3 years ago
The following approach is the best, but it is not supported by the kernel yet. Use kfunc with kernel function security_path_unlink. linux/security.h:int security_path_unlink(const struct path dir, struct dentry dentry); The kernel bpf_d_path helper:
@chenhengqi has a upstream patch for this, but not merged yet.
In the same time, you can still attach to security_path_unlink() function with kfunc or kprobe, but you need to do your own path traversal similar to kernel code in bpf program.
Hi @yonghong-song thanks for the insights
but you need to do your own path traversal similar to kernel code in bpf program.
this means should we check the file exits each time if security_path_unlink function is executed could you give some more info on this
Hi @chenhengqi
@chenhengqi has a upstream patch for this, but not merged yet. can you attach any related issues so that i get notified when it is merged
Still on my TODO list, will pick up that work soon.
Hi @chenhengqi , Is there anyway that i can help you out with it
Hi @chenhengqi ,@yongshong-song , Can i try to identify the deletion of files even before the deletion of files happens so that i can hook a function to take the backup and then deletion of file happens.
Use LSM_PROBE to hook security_path_unlink, reject such call and make the backup, then delete the file. (I am not sure whether this way works)
I wanted to trace unlink_at system call to find whether files are getting deleted or not for this solution i used bcc python
A) Is this the way to track files that are deleted by tracing unlink system call B)if A is the proper approach then so to achieve file path i just went through issue #237 there are two recommnedations
1)to use dentry and traverse it continuosly but its not recommended for longer run its not recommended 2)to use bpf_dpath but this helper function needs struct file as an input and i am not sure how to get that
please provide your insights on this