Skip to contentSkip to conversation

generic: test revalidation of encrypted dentries

PATCH In review Eric Biggers 2 participants 2 messages May 4, 2017 – May 5, 2017 fscrypt: file system level encryption support

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 generic: test revalidation of encrypted dentries

From: Eric Biggers <[email protected]>

Add a test which verifies that dentries in an encrypted directory are invalidated when an encryption key is added --- which should cause the plaintext filenames to be visible and accessible, replacing the encoded ciphertext filenames and any negative dentries for the plaintext names. This primarily tests for a bug which was fixed in the v4.5 kernel, plus a v4.6 fix for incorrect RCU usage in the earlier fix.

---
 .gitignore                     |   1 +
 common/encrypt                 |  42 ++++++++---
 src/Makefile                   |   2 +-
 src/t_encrypted_d_revalidate.c | 122 ++++++++++++++++++++++++++++++++
 tests/generic/600              | 154 +++++++++++++++++++++++++++++++++++++++++
 tests/generic/600.out          |  37 ++++++++++
 tests/generic/group            |   1 +
 7 files changed, 349 insertions(+), 10 deletions(-)
 create mode 100644 src/t_encrypted_d_revalidate.c
 create mode 100755 tests/generic/600
 create mode 100644 tests/generic/600.out
.gitignore +1 -0
index b609f10f..38f3a001 100644
@@ -112,6 +112,7 @@
 /src/t_dir_offset
 /src/t_dir_offset2
 /src/t_dir_type
+/src/t_encrypted_d_revalidate
 /src/t_futimens
 /src/t_getcwd
 /src/t_holes
common/encrypt +33 -9

64 lines not on this page · raw message

src/Makefile +1 -1
index f1338ca9..e5042c9b 100644
@@ -22,7 +22,7 @@ LINUX_TARGETS = xfsctl bstat t_mtab getdevicesize preallo_rw_pattern_reader \
 	seek_copy_test t_readdir_1 t_readdir_2 fsync-tester nsexec cloner \
 	renameat2 t_getcwd e4compact test-nextquota punch-alternating \
 	attr-list-by-handle-cursor-test listxattr dio-interleaved t_dir_type \
-	dio-invalidate-cache stat_test
+	dio-invalidate-cache stat_test t_encrypted_d_revalidate
 
 SUBDIRS =
 
src/t_encrypted_d_revalidate.c new file +122 -0

122 lines not on this page · raw message

tests/generic/600 new file +154 -0

154 lines not on this page · raw message

tests/generic/600.out new file +37 -0
new file mode 100644
index 00000000..34bf6aab
@@ -0,0 +1,37 @@
+QA output created by 600
+
+***** Without encryption key *****
+--- Directory listing:
+SCRATCH_MNT/edir/ENCRYPTED_NAME
+SCRATCH_MNT/edir/ENCRYPTED_NAME
+--- Contents of files using plaintext names:
+cat: SCRATCH_MNT/edir/@@@: No such file or directory
+cat: SCRATCH_MNT/edir/abcd: No such file or directory
+--- Contents of files using ciphertext names:
+cat: SCRATCH_MNT/edir/ENCRYPTED_NAME: Required key not available
+cat: SCRATCH_MNT/edir/ENCRYPTED_NAME: Required key not available
+
+***** With encryption key *****
+--- Directory listing:
+SCRATCH_MNT/edir/@@@
+SCRATCH_MNT/edir/abcd
+--- Contents of files using plaintext names:
+contents_@@@
+contents_abcd
+--- Contents of files using ciphertext names:
+cat: SCRATCH_MNT/edir/ENCRYPTED_NAME: No such file or directory
+cat: SCRATCH_MNT/edir/ENCRYPTED_NAME: No such file or directory
+
+***** Race conditions *****
+t_encrypted_d_revalidate finished
+
+***** After key revocation *****
+--- Directory listing:
+SCRATCH_MNT/edir/@@@
+SCRATCH_MNT/edir/abcd
+--- Contents of files using plaintext names:
+contents_@@@
+contents_abcd
+--- Contents of files using ciphertext names:
+cat: SCRATCH_MNT/edir/ENCRYPTED_NAME: No such file or directory
+cat: SCRATCH_MNT/edir/ENCRYPTED_NAME: No such file or directory
tests/generic/group +1 -0
index b3051752..edfc99a6 100644
@@ -431,3 +431,4 @@
 426 auto quick exportfs
 427 auto quick aio rw
 428 auto quick
+600 auto encrypt
Signature · 1 line
2.13.0.rc1.294.g07d810a77f-goog
#1 lore raw
Quoted 11 lines · Eric Biggers

From: Eric Biggers <[email protected]>

Add a test which verifies that dentries in an encrypted directory are invalidated when an encryption key is added --- which should cause the plaintext filenames to be visible and accessible, replacing the encoded ciphertext filenames and any negative dentries for the plaintext names. This primarily tests for a bug which was fixed in the v4.5 kernel, plus a v4.6 fix for incorrect RCU usage in the earlier fix.

Looks good to me, ext4 passed this test with 4.11-rc8 kernel.

...

Quoted 10 lines
tests/generic/600 new file +10 -0
+_filter_ciphertext_filenames()
+{
+	_filter_scratch | sed 's|edir/[a-zA-Z0-9+,_]\+|edir/ENCRYPTED_NAME|g'
+}
+
+_show_file_contents()
+{
+	echo "--- Contents of files using plaintext names:"
+	cat $SCRATCH_MNT/edir/@@@ |& _filter_scratch
+	cat $SCRATCH_MNT/edir/abcd |& _filter_scratch

tests/generic/600 line 109

Quoted 10 lines
tests/generic/600 new file +10 -0
+	echo "--- Contents of files using ciphertext names:"
+	cat ${ciphertext_names[@]} |& _filter_ciphertext_filenames
+}
+
+_show_directory_with_key()
+{
+	echo "--- Directory listing:"
+	find $SCRATCH_MNT/edir -mindepth 1 | sort | _filter_scratch
+	_show_file_contents
+}

I just removed the leading underscore from above three local functions, leading underscores are reserved for global helpers.

Thanks,
Eryu