unrm
play

UNRM Hacking the filesystem Jessica Yu WHOOPS... GMAIL: UNDO SEND - PowerPoint PPT Presentation

UNRM Hacking the filesystem Jessica Yu WHOOPS... GMAIL: UNDO SEND unrm operates on the same idea as Gmail's undo send. UNRM: USAGE Goal : after an rm , want to be able to recover all removed files under a certain directory within a set period


  1. UNRM Hacking the filesystem Jessica Yu

  2. WHOOPS...

  3. GMAIL: UNDO SEND unrm operates on the same idea as Gmail's undo send.

  4. UNRM: USAGE Goal : after an rm , want to be able to recover all removed files under a certain directory within a set period of time. $ ls document.pdf image.png file.txt dir/ $ rm -r * # rm all files $ ls -l # all gone! total 0 $ unrm # undo $ ls document.pdf image.png file.txt dir/ # all back!

  5. RM: UNDER THE HOOD What happens during an rm? Application Application Application C-Standard Library (libc) USERSPACE KERNELSPACE Virtual Filesystem (VFS) Ext4 Btrfs XFS

  6. RM: UNDER THE HOOD What happens during an rm? Application rm Application $ strace rm file ... unlinkat(AT_FDCWD, "file", 0) C-Standard Library (libc) ... USERSPACE KERNELSPACE Virtual Filesystem (VFS) Ext4 Btrfs XFS

  7. RM: UNDER THE HOOD What happens during an rm? Application rm Application $ strace rm file ... unlinkat(AT_FDCWD, "file", 0) C-Standard Library (libc) ... USERSPACE KERNELSPACE do_unlinkat(...) Virtual Filesystem (VFS) → vfs_unlink(...) Ext4 Btrfs XFS

  8. RM: UNDER THE HOOD What happens during an rm? Application rm Application $ strace rm file ... unlinkat(AT_FDCWD, "file", 0) C-Standard Library (libc) ... USERSPACE KERNELSPACE do_unlinkat(...) Virtual Filesystem (VFS) → vfs_unlink(...) → dir->i_op->unlink(...) Ext4 Btrfs XFS

  9. RM: UNDER THE HOOD What happens during an rm? Application rm Application $ strace rm file ... unlinkat(AT_FDCWD, "file", 0) C-Standard Library (libc) ... USERSPACE KERNELSPACE do_unlinkat(...) Virtual Filesystem (VFS) → vfs_unlink(...) → dir->i_op->unlink(...) → ext4_unlink(....) Ext4 Btrfs XFS

  10. UNRM: UNDER THE HOOD What happens during an rm? Application rm Application $ strace rm file ... unlinkat(AT_FDCWD, "file", 0) C-Standard Library (libc) ... USERSPACE KERNELSPACE do_unlinkat(...) Virtual Filesystem (VFS) → vfs_unlink(...) → dir->i_op->unlink(...) → ext4_unlink(....) Ext4 Btrfs XFS → ext4_unrm_save(...)

  11. UNRM: OVERVIEW ○ Idea : Intercept unlinking process at the fs layer ○ When we run rm , we want it to look like the file has been removed already ( 'ls' shouldn't show file) □ But file should still exist somewhere □ And the file is finally removed after a period of time ○ accomplish this via work queues

  12. UNRM: OVERVIEW ext4_sb_info ○ Create a tree ... struct radix_tree_root s_unrm ; "second chance tree" □ ... radix tree rooted at ext4 superblock info □ ... struct dir 123 . c e s 0 indexed by directory inode # ○ 3 file each node in the tree points to a linked list □ . c e s 0 3 file . c ○ Linked lists e s 0 3 file For each directory, use a linked list to keep track □ of individual rm'd files from that dir ○ Work queues Finish unlinking process after set period of time □

  13. UNRM: OVERVIEW ext4_sb_info ○ Create a tree ... struct radix_tree_root s_unrm ; "second chance tree" □ ... radix tree rooted at ext4 superblock info □ ... struct dir 123 ! ! G N I indexed by directory inode # R ○ file each node in the tree points to a linked list □ . c e s 0 3 file . c ○ Linked lists e s 0 3 file For each directory, use a linked list to keep track □ of individual rm'd files from that dir ○ Work queues Finish unlinking process after set period of time □

  14. UNRM: OVERVIEW ext4_sb_info ○ Create a tree ... struct radix_tree_root s_unrm ; "second chance tree" □ ... radix tree rooted at ext4 superblock info □ ... struct goodbye dir 123 world :( indexed by directory inode # ○ file each node in the tree points to a linked list □ . c e s 0 3 file . c ○ Linked lists e s 0 3 file For each directory, use a linked list to keep track □ of individual rm'd files from that dir ○ Work queues Finish unlinking process after set period of time □ File is removed + entry from linked list removed □

  15. UNRM: OVERVIEW ext4_sb_info ○ Create a tree ... struct radix_tree_root s_unrm ; "second chance tree" □ ... radix tree rooted at ext4 superblock info □ ... struct dir 123 indexed by directory inode # ○ each node in the tree points to a linked list □ . c e s 0 3 file . c ○ Linked lists e s 0 3 file For each directory, use a linked list to keep track □ of individual rm'd files from that dir ○ Work queues Finish unlinking process after set period of time □ File is removed + entry from linked list removed □

  16. UNRM: ext4_unrm_save() ○ Idea : Intercept unlinking process at the fs layer Want to invalidate associated dentry (negate it) □ So that lookups fail ○ $ ls testfile testfile: No such file or directory $ ▌ ...but keep around the inode secretly (link count > 0) □ keep around the negative dentry too □ we'll need to "instantiate" it again if we call unrm ○ ...i.e., make the path lookup succeed again! ○

  17. UNRM: ext4_unrm_save() ○ Idea : Intercept unlinking process at the fs layer ext4_unlink() □ ext4_unrm_save(): ○ Inserts new entry in our radix tree Save relevant info that will let us unrm □ i.e. Save pointers to the inode and dentry □ ○ But do not drop the inode's i_nlink (# of hard links)

  18. UNRM: ext4_unrm_save() ext4_sb_info ▌ radix_tree_root $ pwd s_unrm /home/jyu/ $ ls -lih /home/jyu 795 drwx------ 41 jyu jyu 4.0K Aug 12 22:37 /home/jyu $ ls testfile.pdf track01.mp3 important.doc $ ls -lih testfile.pdf 901 -rw-r--r-- 1 jyu jyu 94K Jun 23 18:04 testfile.pdf $ ▌

  19. UNRM: ext4_unrm_save() ext4_sb_info ▌ radix_tree_root $ pwd s_unrm /home/jyu/ $ ls -lih /home/jyu 795 drwx------ 41 jyu jyu 4.0K Aug 12 22:37 /home/jyu key: 795 ➞ Create a new list $ ls head ➞ Insert into radix testfile.pdf track01.mp3 important.doc tree with key 795 $ ls -lih testfile.pdf ➞ Create list node with: 901 -rw-r--r-- 1 jyu jyu 94K Jun 23 18:04 testfile.pdf $ rm testfile.pdf $ ▌

  20. UNRM: ext4_unrm_save() ext4_sb_info ▌ radix_tree_root $ pwd s_unrm /home/jyu/ $ ls -lih /home/jyu 795 drwx------ 41 jyu jyu 4.0K Aug 12 22:37 /home/jyu key: 795 ➞ Create a new list $ ls head ➞ Insert into radix testfile.pdf track01.mp3 important.doc tree with key 795 □ inode 901 $ ls -lih testfile.pdf ➞ Create list node □ dentry with: 901 -rw-r--r-- 1 jyu jyu 94K Jun 23 18:04 testfile.pdf □ pointer to inode □ pointer to dentry $ rm testfile.pdf □ allocated work $ ▌

  21. UNRM: ext4_unrm_save() ext4_sb_info ▌ radix_tree_root $ pwd s_unrm /home/jyu/ $ ls -lih /home/jyu ### inode 795 795 drwx------ 41 jyu jyu 4.0K Aug 12 22:37 /home/jyu key: 795 ➞ Create a new list $ ls head ➞ Insert into radix testfile.pdf track01.mp3 important.doc tree with key 795 □ inode 901 $ ls -lih testfile.pdf ➞ Create list node □ dentry with: 901 -rw-r--r-- 1 jyu jyu 94K Jun 23 18:04 testfile.pdf □ pointer to inode □ pointer to dentry $ rm testfile.pdf ### inode 901 □ allocated work $ rm track01.mp3 ### inode 941 □ inode 941 $ ▌ □ dentry

  22. UNRM: ext4_unrm_save() ext4_sb_info ▌ radix_tree_root $ pwd s_unrm /home/jyu/ $ ls -lih /home/jyu ### inode 795 795 drwx------ 41 jyu jyu 4.0K Aug 12 22:37 /home/jyu key: 795 ➞ Create a new list $ ls head ➞ Insert into radix testfile.pdf track01.mp3 important.doc tree with key 795 □ inode 901 $ ls -lih testfile.pdf ➞ Create list node □ dentry with: 901 -rw-r--r-- 1 jyu jyu 94K Jun 23 18:04 testfile.pdf □ pointer to inode □ pointer to dentry $ rm testfile.pdf ### inode 901 □ allocated work ➞ Negative dentries $ rm track01.mp3 ### inode 941 created as unlink □ inode 941 process finishes $ ls track01.mp3 □ dentry track01.mp3: No such file or directory $ ▌

  23. UNRM: RECURSIVE RM ext4_sb_info ▌ radix_tree_root $ pwd s_unrm /home/jyu/ $ ls testfile.pdf music/ $ ls music/ track01.mp3 $ ▌

  24. UNRM: RECURSIVE RM ext4_sb_info ▌ radix_tree_root $ pwd s_unrm /home/jyu/ $ ls testfile.pdf music/ $ ls music/ track01.mp3 $ rm -r * ### BOOM $ ▌

  25. UNRM: RECURSIVE RM ext4_sb_info ▌ radix_tree_root $ pwd s_unrm /home/jyu/ $ ls testfile.pdf music/ key:/home/jyu $ ls music/ track01.mp3 □ testfile.pdf $ rm -r * ### BOOM □ dentry $ ▌ □ music/ □ dentry * inode #'s replaced with filenames for simplicity

  26. UNRM: RECURSIVE RM ext4_sb_info ▌ radix_tree_root $ pwd s_unrm /home/jyu/ $ ls testfile.pdf music/ key:/home/jyu $ ls music/ track01.mp3 □ testfile.pdf $ echo * □ dentry testfile.pdf music ### rm -r * uses this order $ rm -r * ### BOOM $ ▌ □ music/ Mark dir entries so dir=1 that we can recurse □ dentry into them when unrm is called later * inode #'s replaced with filenames for simplicity

  27. UNRM: RECURSIVE RM ext4_sb_info ▌ radix_tree_root $ pwd s_unrm /home/jyu/ $ ls testfile.pdf music/ key:/home/jyu key: music/ $ ls music/ track01.mp3 □ testfile.pdf □ track01.mp3 $ echo * □ dentry □ dentry testfile.pdf music ### rm -r * uses this order $ rm -r * ### BOOM $ ▌ □ music/ dir=1 □ dentry * inode #'s replaced with filenames for simplicity

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend