jessica yu - events.static.linuxfound.org · testfile.pdf track01.mp3 important.doc $ ls -lih...

58
UNRM Hacking the filesystem Jessica Yu

Upload: others

Post on 24-Jul-2020

0 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Jessica Yu - events.static.linuxfound.org · testfile.pdf track01.mp3 important.doc $ ls -lih testfile.pdf 901 -rw-r--r-- 1 jyu jyu 94K Jun 23 18:04 testfile.pdf $ rm testfile.pdf

UNRMHacking the filesystem

Jessica Yu

Page 2: Jessica Yu - events.static.linuxfound.org · testfile.pdf track01.mp3 important.doc $ ls -lih testfile.pdf 901 -rw-r--r-- 1 jyu jyu 94K Jun 23 18:04 testfile.pdf $ rm testfile.pdf

WHOOPS...

Page 3: Jessica Yu - events.static.linuxfound.org · testfile.pdf track01.mp3 important.doc $ ls -lih testfile.pdf 901 -rw-r--r-- 1 jyu jyu 94K Jun 23 18:04 testfile.pdf $ rm testfile.pdf

GMAIL: UNDO SEND

unrm operates on the same idea as Gmail's undo send.

Page 4: Jessica Yu - events.static.linuxfound.org · testfile.pdf track01.mp3 important.doc $ ls -lih testfile.pdf 901 -rw-r--r-- 1 jyu jyu 94K Jun 23 18:04 testfile.pdf $ rm testfile.pdf

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!

Page 5: Jessica Yu - events.static.linuxfound.org · testfile.pdf track01.mp3 important.doc $ ls -lih testfile.pdf 901 -rw-r--r-- 1 jyu jyu 94K Jun 23 18:04 testfile.pdf $ rm testfile.pdf

RM: UNDER THE HOOD

Application Application Application

C-Standard Library (libc)

Virtual Filesystem (VFS)

Ext4 Btrfs XFS

USERSPACE

KERNELSPACE

What happens during an rm?

Page 6: Jessica Yu - events.static.linuxfound.org · testfile.pdf track01.mp3 important.doc $ ls -lih testfile.pdf 901 -rw-r--r-- 1 jyu jyu 94K Jun 23 18:04 testfile.pdf $ rm testfile.pdf

RM: UNDER THE HOOD

Application rm Application

C-Standard Library (libc)

Virtual Filesystem (VFS)

Ext4 Btrfs XFS

USERSPACE

KERNELSPACE

What happens during an rm?

$ strace rm file

...

unlinkat(AT_FDCWD, "file", 0)

...

Page 7: Jessica Yu - events.static.linuxfound.org · testfile.pdf track01.mp3 important.doc $ ls -lih testfile.pdf 901 -rw-r--r-- 1 jyu jyu 94K Jun 23 18:04 testfile.pdf $ rm testfile.pdf

RM: UNDER THE HOOD

Application rm Application

C-Standard Library (libc)

Virtual Filesystem (VFS)

Ext4 Btrfs XFS

USERSPACE

KERNELSPACE

What happens during an rm?

$ strace rm file

...

unlinkat(AT_FDCWD, "file", 0)

...

do_unlinkat(...)

→ vfs_unlink(...)

Page 8: Jessica Yu - events.static.linuxfound.org · testfile.pdf track01.mp3 important.doc $ ls -lih testfile.pdf 901 -rw-r--r-- 1 jyu jyu 94K Jun 23 18:04 testfile.pdf $ rm testfile.pdf

RM: UNDER THE HOOD

Application rm Application

C-Standard Library (libc)

Virtual Filesystem (VFS)

Ext4 Btrfs XFS

USERSPACE

KERNELSPACE

What happens during an rm?

$ strace rm file

...

unlinkat(AT_FDCWD, "file", 0)

...

do_unlinkat(...)

→ vfs_unlink(...)

→ dir->i_op->unlink(...)

Page 9: Jessica Yu - events.static.linuxfound.org · testfile.pdf track01.mp3 important.doc $ ls -lih testfile.pdf 901 -rw-r--r-- 1 jyu jyu 94K Jun 23 18:04 testfile.pdf $ rm testfile.pdf

RM: UNDER THE HOOD

Application rm Application

C-Standard Library (libc)

Virtual Filesystem (VFS)

Ext4 Btrfs XFS

USERSPACE

KERNELSPACE

What happens during an rm?

$ strace rm file

...

unlinkat(AT_FDCWD, "file", 0)

...

do_unlinkat(...)

→ vfs_unlink(...)

→ dir->i_op->unlink(...)

→ ext4_unlink(....)

Page 10: Jessica Yu - events.static.linuxfound.org · testfile.pdf track01.mp3 important.doc $ ls -lih testfile.pdf 901 -rw-r--r-- 1 jyu jyu 94K Jun 23 18:04 testfile.pdf $ rm testfile.pdf

UNRM: UNDER THE HOOD

Application rm Application

C-Standard Library (libc)

Virtual Filesystem (VFS)

Ext4 Btrfs XFS

USERSPACE

KERNELSPACE

What happens during an rm?

$ strace rm file

...

unlinkat(AT_FDCWD, "file", 0)

...

do_unlinkat(...)

→ vfs_unlink(...)

→ dir->i_op->unlink(...)

→ ext4_unlink(....)

→ ext4_unrm_save(...)

Page 11: Jessica Yu - events.static.linuxfound.org · testfile.pdf track01.mp3 important.doc $ ls -lih testfile.pdf 901 -rw-r--r-- 1 jyu jyu 94K Jun 23 18:04 testfile.pdf $ rm testfile.pdf

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

Page 12: Jessica Yu - events.static.linuxfound.org · testfile.pdf track01.mp3 important.doc $ ls -lih testfile.pdf 901 -rw-r--r-- 1 jyu jyu 94K Jun 23 18:04 testfile.pdf $ rm testfile.pdf

UNRM: OVERVIEW

○ Create a tree□ "second chance tree"□ radix tree rooted at ext4 superblock info

struct○ indexed by directory inode #

□ each node in the tree points to a linked list

○ Linked lists□ 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

ext4_sb_info...

struct radix_tree_root s_unrm;...

file

file

file

30 sec.

30 sec.

30 sec.

...dir 123

Page 13: Jessica Yu - events.static.linuxfound.org · testfile.pdf track01.mp3 important.doc $ ls -lih testfile.pdf 901 -rw-r--r-- 1 jyu jyu 94K Jun 23 18:04 testfile.pdf $ rm testfile.pdf

UNRM: OVERVIEW

○ Create a tree□ "second chance tree"□ radix tree rooted at ext4 superblock info

struct○ indexed by directory inode #

□ each node in the tree points to a linked list

○ Linked lists□ 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

ext4_sb_info...

struct radix_tree_root s_unrm;...

file

file

file

RING!!

30 sec.

30 sec.

...dir 123

Page 14: Jessica Yu - events.static.linuxfound.org · testfile.pdf track01.mp3 important.doc $ ls -lih testfile.pdf 901 -rw-r--r-- 1 jyu jyu 94K Jun 23 18:04 testfile.pdf $ rm testfile.pdf

UNRM: OVERVIEW

○ Create a tree□ "second chance tree"□ radix tree rooted at ext4 superblock info

struct○ indexed by directory inode #

□ each node in the tree points to a linked list

○ Linked lists□ 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

ext4_sb_info...

struct radix_tree_root s_unrm;...

file

file

file

30 sec.

30 sec.

...dir 123 goodbye world :(

Page 15: Jessica Yu - events.static.linuxfound.org · testfile.pdf track01.mp3 important.doc $ ls -lih testfile.pdf 901 -rw-r--r-- 1 jyu jyu 94K Jun 23 18:04 testfile.pdf $ rm testfile.pdf

UNRM: OVERVIEW

○ Create a tree□ "second chance tree"□ radix tree rooted at ext4 superblock info

struct○ indexed by directory inode #

□ each node in the tree points to a linked list

○ Linked lists□ 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

ext4_sb_info...

struct radix_tree_root s_unrm;...

file

file

30 sec.

30 sec.

...dir 123

Page 16: Jessica Yu - events.static.linuxfound.org · testfile.pdf track01.mp3 important.doc $ ls -lih testfile.pdf 901 -rw-r--r-- 1 jyu jyu 94K Jun 23 18:04 testfile.pdf $ rm testfile.pdf

UNRM: ext4_unrm_save()

○ Idea: Intercept unlinking process at the fs layer□ Want to invalidate associated dentry (negate it)

○ So that lookups fail

□ ...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!

$ ls testfiletestfile: No such file or directory$ ▌

Page 17: Jessica Yu - events.static.linuxfound.org · testfile.pdf track01.mp3 important.doc $ ls -lih testfile.pdf 901 -rw-r--r-- 1 jyu jyu 94K Jun 23 18:04 testfile.pdf $ rm testfile.pdf

UNRM: ext4_unrm_save()

○ Idea: Intercept unlinking process at the fs layer□ ext4_unlink()

○ 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)

ext4_unrm_save():

Page 18: Jessica Yu - events.static.linuxfound.org · testfile.pdf track01.mp3 important.doc $ ls -lih testfile.pdf 901 -rw-r--r-- 1 jyu jyu 94K Jun 23 18:04 testfile.pdf $ rm testfile.pdf

UNRM: ext4_unrm_save()

$ pwd

/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

$ ▌

radix_tree_root s_unrm

ext4_sb_info

Page 19: Jessica Yu - events.static.linuxfound.org · testfile.pdf track01.mp3 important.doc $ ls -lih testfile.pdf 901 -rw-r--r-- 1 jyu jyu 94K Jun 23 18:04 testfile.pdf $ rm testfile.pdf

UNRM: ext4_unrm_save()

$ pwd

/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

$ rm testfile.pdf

$ ▌

radix_tree_root s_unrm

key: 795 ➞ Create a new list head

➞ Insert into radix tree with key 795

➞ Create list node with:

ext4_sb_info

Page 20: Jessica Yu - events.static.linuxfound.org · testfile.pdf track01.mp3 important.doc $ ls -lih testfile.pdf 901 -rw-r--r-- 1 jyu jyu 94K Jun 23 18:04 testfile.pdf $ rm testfile.pdf

UNRM: ext4_unrm_save()

$ pwd

/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

$ rm testfile.pdf

$ ▌

radix_tree_root s_unrm

key: 795

□ inode 901□ dentry

➞ Create a new list head

➞ Insert into radix tree with key 795

➞ Create list node with: □ pointer to inode □ pointer to dentry □ allocated work

ext4_sb_info

Page 21: Jessica Yu - events.static.linuxfound.org · testfile.pdf track01.mp3 important.doc $ ls -lih testfile.pdf 901 -rw-r--r-- 1 jyu jyu 94K Jun 23 18:04 testfile.pdf $ rm testfile.pdf

UNRM: ext4_unrm_save()

$ pwd

/home/jyu/

$ ls -lih /home/jyu ### inode 795

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

$ rm testfile.pdf ### inode 901

$ rm track01.mp3 ### inode 941

$ ▌

radix_tree_root s_unrm

key: 795

□ inode 901□ dentry

➞ Create a new list head

➞ Insert into radix tree with key 795

➞ Create list node with: □ pointer to inode □ pointer to dentry □ allocated work

□ inode 941□ dentry

ext4_sb_info

Page 22: Jessica Yu - events.static.linuxfound.org · testfile.pdf track01.mp3 important.doc $ ls -lih testfile.pdf 901 -rw-r--r-- 1 jyu jyu 94K Jun 23 18:04 testfile.pdf $ rm testfile.pdf

UNRM: ext4_unrm_save()

$ pwd

/home/jyu/

$ ls -lih /home/jyu ### inode 795

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

$ rm testfile.pdf ### inode 901

$ rm track01.mp3 ### inode 941

$ ls track01.mp3

track01.mp3: No such file or directory

$ ▌

radix_tree_root s_unrm

key: 795

□ inode 901□ dentry

➞ Create a new list head

➞ Insert into radix tree with key 795

➞ Create list node with: □ pointer to inode □ pointer to dentry □ allocated work➞ Negative dentries created as unlink process finishes

□ inode 941□ dentry

ext4_sb_info

Page 23: Jessica Yu - events.static.linuxfound.org · testfile.pdf track01.mp3 important.doc $ ls -lih testfile.pdf 901 -rw-r--r-- 1 jyu jyu 94K Jun 23 18:04 testfile.pdf $ rm testfile.pdf

UNRM: RECURSIVE RM

$ pwd

/home/jyu/

$ ls

testfile.pdf music/

$ ls music/

track01.mp3

$ ▌

radix_tree_root s_unrm

ext4_sb_info

Page 24: Jessica Yu - events.static.linuxfound.org · testfile.pdf track01.mp3 important.doc $ ls -lih testfile.pdf 901 -rw-r--r-- 1 jyu jyu 94K Jun 23 18:04 testfile.pdf $ rm testfile.pdf

UNRM: RECURSIVE RM

$ pwd

/home/jyu/

$ ls

testfile.pdf music/

$ ls music/

track01.mp3

$ rm -r * ### BOOM

$ ▌

radix_tree_root s_unrm

ext4_sb_info

Page 25: Jessica Yu - events.static.linuxfound.org · testfile.pdf track01.mp3 important.doc $ ls -lih testfile.pdf 901 -rw-r--r-- 1 jyu jyu 94K Jun 23 18:04 testfile.pdf $ rm testfile.pdf

UNRM: RECURSIVE RM

$ pwd

/home/jyu/

$ ls

testfile.pdf music/

$ ls music/

track01.mp3

$ rm -r * ### BOOM

$ ▌

radix_tree_root s_unrm

ext4_sb_info

key:/home/jyu

□ testfile.pdf□ dentry

□ music/□ dentry

* inode #'s replaced with filenames for simplicity

Page 26: Jessica Yu - events.static.linuxfound.org · testfile.pdf track01.mp3 important.doc $ ls -lih testfile.pdf 901 -rw-r--r-- 1 jyu jyu 94K Jun 23 18:04 testfile.pdf $ rm testfile.pdf

UNRM: RECURSIVE RM

$ pwd

/home/jyu/

$ ls

testfile.pdf music/

$ ls music/

track01.mp3

$ echo *

testfile.pdf music ### rm -r * uses this order

$ rm -r * ### BOOM

$ ▌

radix_tree_root s_unrm

ext4_sb_info

key:/home/jyu

□ testfile.pdf□ dentry

□ music/□ dentry

* inode #'s replaced with filenames for simplicity

dir=1Mark dir entries so that we can recurseinto them when unrm is called later

Page 27: Jessica Yu - events.static.linuxfound.org · testfile.pdf track01.mp3 important.doc $ ls -lih testfile.pdf 901 -rw-r--r-- 1 jyu jyu 94K Jun 23 18:04 testfile.pdf $ rm testfile.pdf

UNRM: RECURSIVE RM

$ pwd

/home/jyu/

$ ls

testfile.pdf music/

$ ls music/

track01.mp3

$ echo *

testfile.pdf music ### rm -r * uses this order

$ rm -r * ### BOOM

$ ▌

radix_tree_root s_unrm

ext4_sb_info

key:/home/jyu

□ testfile.pdf□ dentry

□ music/□ dentry

key: music/

□ track01.mp3□ dentry

* inode #'s replaced with filenames for simplicity

dir=1

Page 28: Jessica Yu - events.static.linuxfound.org · testfile.pdf track01.mp3 important.doc $ ls -lih testfile.pdf 901 -rw-r--r-- 1 jyu jyu 94K Jun 23 18:04 testfile.pdf $ rm testfile.pdf

UNRM: BACK TO USERSPACE

○ The "unrm" command□ a simple C program

○ issues an ioctl() to ext4 (ext4_ioctl())○ ext4_ioctl()

ext4_do_unrm()

Page 29: Jessica Yu - events.static.linuxfound.org · testfile.pdf track01.mp3 important.doc $ ls -lih testfile.pdf 901 -rw-r--r-- 1 jyu jyu 94K Jun 23 18:04 testfile.pdf $ rm testfile.pdf

UNRM: ext4_do_unrm()

int ext4_do_unrm(struct super_block *sb,

struct inode *dir)

Arguments:

○ @sb: superblock struct □ should be an ext4fs superblock□ from superblock can access our unrm radix tree

○ @dir: directory in which to look for recently rm'd files□ use this dir's inode number as key into radix tree

Page 30: Jessica Yu - events.static.linuxfound.org · testfile.pdf track01.mp3 important.doc $ ls -lih testfile.pdf 901 -rw-r--r-- 1 jyu jyu 94K Jun 23 18:04 testfile.pdf $ rm testfile.pdf

UNRM: ext4_do_unrm()

int ext4_do_unrm(struct super_block *sb,

struct inode *dir)

What does ext4_do_unrm() do?○ Lookup dir->i_no with radix_tree_lookup()

□ key: directory inode number.□ entry: linked list of deleted files

○ iterate list of deleted files: list_for_each_entry(...)□ For each deleted file:

○ add the file back to the directory

□ (remember, directories are just files that are lists of other files, so

we're technically just adding an entry back)○ re-instantiate saved dentry with saved inode○ cancel scheduled work

Page 31: Jessica Yu - events.static.linuxfound.org · testfile.pdf track01.mp3 important.doc $ ls -lih testfile.pdf 901 -rw-r--r-- 1 jyu jyu 94K Jun 23 18:04 testfile.pdf $ rm testfile.pdf

UNRM: ext4_do_unrm()

$ pwd

/home/jyu

$ ls

testfile.pdf track01.mp3 important.doc

$ rm testfile.pdf ### inode 901

$ rm track01.mp3 ### inode 941

$ ls track01.mp3

track01.mp3: No such file or directory

$ ▌

radix_tree_root s_unrm

key: 795

□ inode 901□ dentry

□ inode 941□ dentry

ext4_sb_info

Page 32: Jessica Yu - events.static.linuxfound.org · testfile.pdf track01.mp3 important.doc $ ls -lih testfile.pdf 901 -rw-r--r-- 1 jyu jyu 94K Jun 23 18:04 testfile.pdf $ rm testfile.pdf

UNRM: ext4_do_unrm()

$ pwd

/home/jyu

$ ls

testfile.pdf track01.mp3 important.doc

$ rm testfile.pdf ### inode 901

$ rm track01.mp3 ### inode 941

$ ls track01.mp3

track01.mp3: No such file or directory

$ unrm

$ ▌

radix_tree_root s_unrm

key: 795

□ inode 901□ dentry

□ inode 941□ dentry

ext4_sb_info

What directory was 'unrm' executed in? ..Oh, /home/jyu, inode 795 Is it in our radix tree?

Page 33: Jessica Yu - events.static.linuxfound.org · testfile.pdf track01.mp3 important.doc $ ls -lih testfile.pdf 901 -rw-r--r-- 1 jyu jyu 94K Jun 23 18:04 testfile.pdf $ rm testfile.pdf

UNRM: ext4_do_unrm()

$ pwd

/home/jyu

$ ls

testfile.pdf track01.mp3 important.doc

$ rm testfile.pdf ### inode 901

$ rm track01.mp3 ### inode 941

$ ls track01.mp3

track01.mp3: No such file or directory

$ unrm

$ ▌

radix_tree_root s_unrm

key: 795

□ inode 901□ dentry

□ inode 941□ dentry

ext4_sb_info

What directory was 'unrm' executed in? ..Oh, /home/jyu, inode 795 Is it in our radix tree?radix_tree_lookup(..,795);

Page 34: Jessica Yu - events.static.linuxfound.org · testfile.pdf track01.mp3 important.doc $ ls -lih testfile.pdf 901 -rw-r--r-- 1 jyu jyu 94K Jun 23 18:04 testfile.pdf $ rm testfile.pdf

UNRM: ext4_do_unrm()

$ pwd

/home/jyu

$ ls

testfile.pdf track01.mp3 important.doc

$ rm testfile.pdf ### inode 901

$ rm track01.mp3 ### inode 941

$ ls track01.mp3

track01.mp3: No such file or directory

$ unrm

$ ▌

radix_tree_root s_unrm

key: 795

□ inode 901□ dentry

□ inode 941□ dentry

ext4_sb_info

What directory was 'unrm' executed in? ..Oh, /home/jyu, inode 795 Is it in our radix tree?radix_tree_lookup(..,795);

Page 35: Jessica Yu - events.static.linuxfound.org · testfile.pdf track01.mp3 important.doc $ ls -lih testfile.pdf 901 -rw-r--r-- 1 jyu jyu 94K Jun 23 18:04 testfile.pdf $ rm testfile.pdf

UNRM: ext4_do_unrm()

$ pwd

/home/jyu

$ ls

testfile.pdf track01.mp3 important.doc

$ rm testfile.pdf ### inode 901

$ rm track01.mp3 ### inode 941

$ ls track01.mp3

track01.mp3: No such file or directory

$ unrm

$ ▌

radix_tree_root s_unrm

key: 795

□ inode 901□ dentry

□ inode 941□ dentry

ext4_sb_info

radix_tree_lookup(..,795);Found our linked list.

Iterate through it:list_for_each_entry(...)

Page 36: Jessica Yu - events.static.linuxfound.org · testfile.pdf track01.mp3 important.doc $ ls -lih testfile.pdf 901 -rw-r--r-- 1 jyu jyu 94K Jun 23 18:04 testfile.pdf $ rm testfile.pdf

UNRM: ext4_do_unrm()

$ pwd

/home/jyu

$ ls

testfile.pdf track01.mp3 important.doc

$ rm testfile.pdf ### inode 901

$ rm track01.mp3 ### inode 941

$ ls track01.mp3

track01.mp3: No such file or directory

$ unrm

$ ▌

radix_tree_root s_unrm

key: 795

□ inode 941□ dentry

ext4_sb_info

Iterate through it:list_for_each_entry(...)➞ add inode+dentry back to directory (/home/jyu in this case)➞ reinstantiate dentry (so it's no longer negative)➞ cancel scheduled work➞ remove from list

□ inode 901□ dentry

Page 37: Jessica Yu - events.static.linuxfound.org · testfile.pdf track01.mp3 important.doc $ ls -lih testfile.pdf 901 -rw-r--r-- 1 jyu jyu 94K Jun 23 18:04 testfile.pdf $ rm testfile.pdf

UNRM: ext4_do_unrm()

$ pwd

/home/jyu

$ ls

testfile.pdf track01.mp3 important.doc

$ rm testfile.pdf ### inode 901

$ rm track01.mp3 ### inode 941

$ ls track01.mp3

track01.mp3: No such file or directory

$ unrm

$ ▌

radix_tree_root s_unrm

key: 795

□ inode 941□ dentry

ext4_sb_info

Iterate through it:list_for_each_entry(...)➞ add inode+dentry back to directory (/home/jyu in this case)➞ reinstantiate dentry (so it's no longer negative)➞ cancel scheduled work➞ remove from list

Page 38: Jessica Yu - events.static.linuxfound.org · testfile.pdf track01.mp3 important.doc $ ls -lih testfile.pdf 901 -rw-r--r-- 1 jyu jyu 94K Jun 23 18:04 testfile.pdf $ rm testfile.pdf

UNRM: ext4_do_unrm()

$ pwd

/home/jyu

$ ls

testfile.pdf track01.mp3 important.doc

$ rm testfile.pdf ### inode 901

$ rm track01.mp3 ### inode 941

$ ls track01.mp3

track01.mp3: No such file or directory

$ unrm

$ ▌

radix_tree_root s_unrm

key: 795

□ inode 941□ dentry

ext4_sb_info

Iterate through it:list_for_each_entry(...)➞ add inode+dentry back to directory (/home/jyu in this case)➞ reinstantiate dentry (so it's no longer negative)➞ cancel scheduled work➞ remove from list

Page 39: Jessica Yu - events.static.linuxfound.org · testfile.pdf track01.mp3 important.doc $ ls -lih testfile.pdf 901 -rw-r--r-- 1 jyu jyu 94K Jun 23 18:04 testfile.pdf $ rm testfile.pdf

UNRM: ext4_do_unrm()

$ pwd

/home/jyu

$ ls

testfile.pdf track01.mp3 important.doc

$ rm testfile.pdf ### inode 901

$ rm track01.mp3 ### inode 941

$ ls track01.mp3

track01.mp3: No such file or directory

$ unrm

$ ▌

radix_tree_root s_unrm

key: 795

□ inode 941□ dentry

ext4_sb_info

Iterate through it:list_for_each_entry(...)➞ add inode+dentry back to directory (/home/jyu in this case)➞ reinstantiate dentry (so it's no longer negative)➞ cancel scheduled work➞ remove from list

Page 40: Jessica Yu - events.static.linuxfound.org · testfile.pdf track01.mp3 important.doc $ ls -lih testfile.pdf 901 -rw-r--r-- 1 jyu jyu 94K Jun 23 18:04 testfile.pdf $ rm testfile.pdf

UNRM: ext4_do_unrm()

$ pwd

/home/jyu

$ ls

testfile.pdf track01.mp3 important.doc

$ rm testfile.pdf ### inode 901

$ rm track01.mp3 ### inode 941

$ ls track01.mp3

track01.mp3: No such file or directory

$ unrm

$ ▌

radix_tree_root s_unrm

key: 795

ext4_sb_info

Iterate through it:list_for_each_entry(...)➞ add inode+dentry back to directory (/home/jyu in this case)➞ reinstantiate dentry (so it's no longer negative)➞ cancel scheduled work➞ remove from list

Page 41: Jessica Yu - events.static.linuxfound.org · testfile.pdf track01.mp3 important.doc $ ls -lih testfile.pdf 901 -rw-r--r-- 1 jyu jyu 94K Jun 23 18:04 testfile.pdf $ rm testfile.pdf

UNRM: ext4_do_unrm()

$ pwd

/home/jyu

$ ls

testfile.pdf track01.mp3 important.doc

$ rm testfile.pdf ### inode 901

$ rm track01.mp3 ### inode 941

$ ls track01.mp3

track01.mp3: No such file or directory

$ unrm

$ ▌

radix_tree_root s_unrm

key: 795

ext4_sb_info

Iterate through it:list_for_each_entry(...)➞ add inode+dentry back to directory (/home/jyu in this case)➞ reinstantiate dentry (so it's no longer negative)➞ cancel scheduled work➞ remove from list

Page 42: Jessica Yu - events.static.linuxfound.org · testfile.pdf track01.mp3 important.doc $ ls -lih testfile.pdf 901 -rw-r--r-- 1 jyu jyu 94K Jun 23 18:04 testfile.pdf $ rm testfile.pdf

UNRM: ext4_do_unrm()

$ pwd

/home/jyu

$ ls

testfile.pdf track01.mp3 important.doc

$ rm testfile.pdf ### inode 901

$ rm track01.mp3 ### inode 941

$ ls track01.mp3

track01.mp3: No such file or directory

$ unrm

$ ▌

radix_tree_root s_unrm

ext4_sb_info

List empty, looks like we're all done here.

Page 43: Jessica Yu - events.static.linuxfound.org · testfile.pdf track01.mp3 important.doc $ ls -lih testfile.pdf 901 -rw-r--r-- 1 jyu jyu 94K Jun 23 18:04 testfile.pdf $ rm testfile.pdf

UNRM: ext4_do_unrm()

$ pwd

/home/jyu

$ ls

testfile.pdf track01.mp3 important.doc

$ rm testfile.pdf ### inode 901

$ rm track01.mp3 ### inode 941

$ ls track01.mp3

track01.mp3: No such file or directory

$ unrm

$ ls ### success!

testfile.pdf track01.mp3 important.doc

$ ▌

radix_tree_root s_unrm

ext4_sb_info

List empty, looks like we're all done here.

Page 44: Jessica Yu - events.static.linuxfound.org · testfile.pdf track01.mp3 important.doc $ ls -lih testfile.pdf 901 -rw-r--r-- 1 jyu jyu 94K Jun 23 18:04 testfile.pdf $ rm testfile.pdf

RECURSIVE UNRM

$ pwd

/home/jyu/

$ ls

testfile.pdf music/

$ ls music/

track01.mp3

$ rm -r * ### BOOM

$ ▌

radix_tree_root s_unrm

ext4_sb_info

key:/home/jyu

□ testfile.pdf□ dentry

□ music/□ dentry

key: music/

□ track01.mp3□ dentry

* inode #'s replaced with filenames for simplicity

dir=1

Page 45: Jessica Yu - events.static.linuxfound.org · testfile.pdf track01.mp3 important.doc $ ls -lih testfile.pdf 901 -rw-r--r-- 1 jyu jyu 94K Jun 23 18:04 testfile.pdf $ rm testfile.pdf

RECURSIVE UNRM

$ pwd

/home/jyu/

$ ls

testfile.pdf music/

$ ls music/

track01.mp3

$ rm -r * ### BOOM

$ unrm

$ ▌

radix_tree_root s_unrm

ext4_sb_info

key:/home/jyu

□ testfile.pdf□ dentry

□ music/□ dentry

key: music/

□ track01.mp3□ dentry

* inode #'s replaced with filenames for simplicity

dir=1

Page 46: Jessica Yu - events.static.linuxfound.org · testfile.pdf track01.mp3 important.doc $ ls -lih testfile.pdf 901 -rw-r--r-- 1 jyu jyu 94K Jun 23 18:04 testfile.pdf $ rm testfile.pdf

RECURSIVE UNRM

$ pwd

/home/jyu/

$ ls

testfile.pdf music/

$ ls music/

track01.mp3

$ rm -r * ### BOOM

$ unrm

$ ▌

radix_tree_root s_unrm

ext4_sb_info

key:/home/jyu

□ testfile.pdf□ dentry

□ music/□ dentry

key: music/

□ track01.mp3□ dentry

* inode #'s replaced with filenames for simplicity

dir=1

Page 47: Jessica Yu - events.static.linuxfound.org · testfile.pdf track01.mp3 important.doc $ ls -lih testfile.pdf 901 -rw-r--r-- 1 jyu jyu 94K Jun 23 18:04 testfile.pdf $ rm testfile.pdf

RECURSIVE UNRM

$ pwd

/home/jyu/

$ ls

testfile.pdf music/

$ ls music/

track01.mp3

$ rm -r * ### BOOM

$ unrm

$ ▌

radix_tree_root s_unrm

ext4_sb_info

key:/home/jyu

□ music/□ dentry

key: music/

□ track01.mp3□ dentry

* inode #'s replaced with filenames for simplicity

dir=1

Page 48: Jessica Yu - events.static.linuxfound.org · testfile.pdf track01.mp3 important.doc $ ls -lih testfile.pdf 901 -rw-r--r-- 1 jyu jyu 94K Jun 23 18:04 testfile.pdf $ rm testfile.pdf

RECURSIVE UNRM

$ pwd

/home/jyu/

$ ls

testfile.pdf music/

$ ls music/

track01.mp3

$ rm -r * ### BOOM

$ unrm

$ ▌

radix_tree_root s_unrm

ext4_sb_info

key:/home/jyu

□ music/□ dentry

key: music/

□ track01.mp3□ dentry

* inode #'s replaced with filenames for simplicity

dir=1 hey, it's a directory

Page 49: Jessica Yu - events.static.linuxfound.org · testfile.pdf track01.mp3 important.doc $ ls -lih testfile.pdf 901 -rw-r--r-- 1 jyu jyu 94K Jun 23 18:04 testfile.pdf $ rm testfile.pdf

RECURSIVE UNRM

$ pwd

/home/jyu/

$ ls

testfile.pdf music/

$ ls music/

track01.mp3

$ rm -r * ### BOOM

$ unrm

$ ▌

radix_tree_root s_unrm

ext4_sb_info

key:/home/jyu

□ music/□ dentry

key: music/

□ track01.mp3□ dentry

* inode #'s replaced with filenames for simplicity

dir=1 RECURSE:Grab inode num for music/, recursively call ext4_do_unrm() passing in the ino

Page 50: Jessica Yu - events.static.linuxfound.org · testfile.pdf track01.mp3 important.doc $ ls -lih testfile.pdf 901 -rw-r--r-- 1 jyu jyu 94K Jun 23 18:04 testfile.pdf $ rm testfile.pdf

RECURSIVE UNRM

$ pwd

/home/jyu/

$ ls

testfile.pdf music/

$ ls music/

track01.mp3

$ rm -r * ### BOOM

$ unrm

$ ▌

radix_tree_root s_unrm

ext4_sb_info

key:/home/jyu

□ music/□ dentry

key: music/

□ track01.mp3□ dentry

* inode #'s replaced with filenames for simplicity

dir=1

ext4_do_unrm()

➞ radix_tree_lookup() ➞ found it!

RECURSE:Grab inode num for music/, recursively call ext4_do_unrm() passing in the ino

Page 51: Jessica Yu - events.static.linuxfound.org · testfile.pdf track01.mp3 important.doc $ ls -lih testfile.pdf 901 -rw-r--r-- 1 jyu jyu 94K Jun 23 18:04 testfile.pdf $ rm testfile.pdf

RECURSIVE UNRM

$ pwd

/home/jyu/

$ ls

testfile.pdf music/

$ ls music/

track01.mp3

$ rm -r * ### BOOM

$ unrm

$ ▌

radix_tree_root s_unrm

ext4_sb_info

key:/home/jyu

□ music/□ dentry

key: music/

□ track01.mp3□ dentry

* inode #'s replaced with filenames for simplicity

dir=1 RECURSE:Grab inode num for music/, recursively call ext4_do_unrm() passing in the ino

Page 52: Jessica Yu - events.static.linuxfound.org · testfile.pdf track01.mp3 important.doc $ ls -lih testfile.pdf 901 -rw-r--r-- 1 jyu jyu 94K Jun 23 18:04 testfile.pdf $ rm testfile.pdf

RECURSIVE UNRM

$ pwd

/home/jyu/

$ ls

testfile.pdf music/

$ ls music/

track01.mp3

$ rm -r * ### BOOM

$ unrm

$ ▌

radix_tree_root s_unrm

ext4_sb_info

key:/home/jyu

□ music/□ dentry

key: music/

* inode #'s replaced with filenames for simplicity

dir=1 RECURSE:Grab inode num for music/, recursively call ext4_do_unrm() passing in the ino

Page 53: Jessica Yu - events.static.linuxfound.org · testfile.pdf track01.mp3 important.doc $ ls -lih testfile.pdf 901 -rw-r--r-- 1 jyu jyu 94K Jun 23 18:04 testfile.pdf $ rm testfile.pdf

RECURSIVE UNRM

$ pwd

/home/jyu/

$ ls

testfile.pdf music/

$ ls music/

track01.mp3

$ rm -r * ### BOOM

$ unrm

$ ▌

radix_tree_root s_unrm

ext4_sb_info

key:/home/jyu

□ music/□ dentry

* inode #'s replaced with filenames for simplicity

dir=1 RECURSE:Grab inode num for music/, recursively call ext4_do_unrm() passing in the ino

Page 54: Jessica Yu - events.static.linuxfound.org · testfile.pdf track01.mp3 important.doc $ ls -lih testfile.pdf 901 -rw-r--r-- 1 jyu jyu 94K Jun 23 18:04 testfile.pdf $ rm testfile.pdf

RECURSIVE UNRM

$ pwd

/home/jyu/

$ ls

testfile.pdf music/

$ ls music/

track01.mp3

$ rm -r * ### BOOM

$ unrm

$ ▌

radix_tree_root s_unrm

ext4_sb_info

key:/home/jyu

* inode #'s replaced with filenames for simplicity

Page 55: Jessica Yu - events.static.linuxfound.org · testfile.pdf track01.mp3 important.doc $ ls -lih testfile.pdf 901 -rw-r--r-- 1 jyu jyu 94K Jun 23 18:04 testfile.pdf $ rm testfile.pdf

RECURSIVE UNRM

$ pwd

/home/jyu/

$ ls

testfile.pdf music/

$ ls music/

track01.mp3

$ rm -r * ### BOOM

$ unrm

$ tree ### Show dir tree

.

├── music ### Hurray!

│ └── track01.mp3

└── testfile.pdf

radix_tree_root s_unrm

ext4_sb_info

* inode #'s replaced with filenames for simplicity

List empty, looks like we're all done here.

Page 56: Jessica Yu - events.static.linuxfound.org · testfile.pdf track01.mp3 important.doc $ ls -lih testfile.pdf 901 -rw-r--r-- 1 jyu jyu 94K Jun 23 18:04 testfile.pdf $ rm testfile.pdf

DEMO...Let's hope nothing explodes

%_

Page 57: Jessica Yu - events.static.linuxfound.org · testfile.pdf track01.mp3 important.doc $ ls -lih testfile.pdf 901 -rw-r--r-- 1 jyu jyu 94K Jun 23 18:04 testfile.pdf $ rm testfile.pdf

UNRM: ISSUES & FUTURE WORK

○ Warning! unrm is just a fun hack! Was never meant to be used in production

With that said...Here are some ideas for future work...

○ Memory hog! Removal of thousands of files = thousands of nodes in memory

○ Security - take permissions into account○ Make work queue delay adjustable - make the period of

time adjustable (currently hardcoded at 30 seconds)○ Filesystem can be left inconsistent in the event of a

sudden crash (before unlinking or unrm process finishes)○ ....probably more! Feel free to send pull requests!

Page 58: Jessica Yu - events.static.linuxfound.org · testfile.pdf track01.mp3 important.doc $ ls -lih testfile.pdf 901 -rw-r--r-- 1 jyu jyu 94K Jun 23 18:04 testfile.pdf $ rm testfile.pdf

FULL KERNEL SOURCEGITHUB.COM/FLAMING-TOAST/UNRM

Thanks!

CONTACTJYU AT EISEN.IO