隐藏文件该如何被ys?
想隐藏文件, 还是要从sys_dents64系统调用下手。 去看下它在内核中是如何实现的。
代码在linux-2。6。26/fs/readdir。c中:
asmlinkage long sys_getdents64(unsigned int fd, struct linux_dirent64
__user * dirent, unsigned int count)
{
struct file * file;
struct linux_dirent64 __user * lastdirent;
struct getdents_callback64 buf;
int error;
error ...全部
想隐藏文件, 还是要从sys_dents64系统调用下手。 去看下它在内核中是如何实现的。
代码在linux-2。6。26/fs/readdir。c中:
asmlinkage long sys_getdents64(unsigned int fd, struct linux_dirent64
__user * dirent, unsigned int count)
{
struct file * file;
struct linux_dirent64 __user * lastdirent;
struct getdents_callback64 buf;
int error;
error = -EFAULT;
if (!access_ok(VERIFY_WRITE, dirent, count))
goto out;
error = -EBADF;
file = fget(fd);
if (!file)
goto out;
buf。
current_dir = dirent;
buf。previous = NULL;
buf。count = count;
buf。error = 0;
error = vfs_readdir(file, filldir64, &buf);
if (error d_off) d_off = file->f_pos;
error = -EFAULT;
if (__put_user(d_off, &lastdirent->d_off))
goto out_putf;
error = count - buf。
count;
}
out_putf:
fput(file);
out:
return error;
}
首先调用access_ok来验证是下用户空间的dirent地址是否越界,是否可写。 接着根据fd,利用fget找到对应的file结构。
接着出现了一个填充buf数据结构的操作,先不管它是干什么的,接着往下看。
vfs_readdir(file, filldir64, &buf);
函数最终还是调用vfs层的vfs_readdir来获取文件列表的。
到这,我们可以是否通过hookvfs_readdir来达到隐藏文件的效果呢。 继续跟踪vfs_readdir看看这个想法是否可行。
源代码在同一文件中:
int vfs_readdir(struct file *file, filldir_t filler, void *buf)
{
struct inode *inode = file->f_path。
dentry->d_inode;
int res = -ENOTDIR;
if (!file->f_op || !file->f_op->readdir)
goto out;
res = security_file_permission(file, MAY_READ);
if (res)
goto out;。
收起