public inbox for fstests@vger.kernel.org
 help / color / mirror / Atom feed
From: Eric Biggers <ebiggers3@gmail.com>
To: fstests@vger.kernel.org
Cc: Eric Biggers <ebiggers@google.com>, Theodore Ts'o <tytso@mit.edu>,
	Jaegeuk Kim <jaegeuk@kernel.org>,
	Richard Weinberger <richard@nod.at>
Subject: [PATCH] generic/397: test renaming encrypted files without key
Date: Tue, 14 Mar 2017 14:23:58 -0700	[thread overview]
Message-ID: <20170314212358.46169-1-ebiggers3@gmail.com> (raw)

From: Eric Biggers <ebiggers@google.com>

Update generic/397 to test another behavior when accessing encrypted
files without the key: renames should be forbidden, even though they may
be possible cryptographically.  Test both a regular rename and a cross
rename.  (It happens that generic/398 also covers the cross rename case,
but it's primarily for a different reason.)

Cc: Theodore Ts'o <tytso@mit.edu>
Cc: Jaegeuk Kim <jaegeuk@kernel.org>
Cc: Richard Weinberger <richard@nod.at>
Signed-off-by: Eric Biggers <ebiggers@google.com>
---
 tests/generic/397     | 13 +++++++++++++
 tests/generic/397.out |  2 ++
 2 files changed, 15 insertions(+)

diff --git a/tests/generic/397 b/tests/generic/397
index 7077d048..0d3ab4c1 100755
--- a/tests/generic/397
+++ b/tests/generic/397
@@ -46,6 +46,7 @@ _cleanup()
 . ./common/rc
 . ./common/filter
 . ./common/encrypt
+. ./common/renameat2
 
 # remove previous $seqres.full before test
 rm -f $seqres.full
@@ -56,6 +57,7 @@ _supported_os Linux
 _require_scratch_encryption
 _require_xfs_io_command "set_encpolicy"
 _require_command "$KEYCTL_PROG" keyctl
+_requires_renameat2
 
 _new_session_keyring
 
@@ -135,6 +137,17 @@ mkdir $SCRATCH_MNT/edir/0123456789abcdef |& filter_create_errors | _filter_scrat
 ln -s foo $SCRATCH_MNT/edir/newlink |& filter_create_errors | _filter_scratch
 ln -s foo $SCRATCH_MNT/edir/0123456789abcdef |& filter_create_errors | _filter_scratch
 
+# Try to rename files in the encrypted directory.  This should fail with ENOKEY.
+# As noted above, encrypted filenames are unpredictable, so this needs to be
+# written in a way that does not assume any particular filenames.
+# Regression test for:
+#	173b8439e1ba ("ext4: don't allow encrypted operations without keys")
+#	363fa4e078cb ("f2fs: don't allow encrypted operations without keys")
+efile1=$(find $SCRATCH_MNT/edir -maxdepth 1 -type f | head -1)
+efile2=$(find $SCRATCH_MNT/edir -maxdepth 1 -type f | tail -1)
+mv $efile1 $efile2 |& _filter_scratch | sed 's|edir/[a-zA-Z0-9+,_]\+|edir/FILENAME|g'
+src/renameat2 -x $efile1 $efile2
+
 # Delete the encrypted directory (should succeed)
 rm -r $SCRATCH_MNT/edir
 stat $SCRATCH_MNT/edir |& _filter_scratch
diff --git a/tests/generic/397.out b/tests/generic/397.out
index 2f55c5d6..3cf57aab 100644
--- a/tests/generic/397.out
+++ b/tests/generic/397.out
@@ -10,4 +10,6 @@ mkdir: cannot create directory 'SCRATCH_MNT/edir/newdir': Required key not avail
 mkdir: cannot create directory 'SCRATCH_MNT/edir/0123456789abcdef': Required key not available
 ln: failed to create symbolic link 'SCRATCH_MNT/edir/newlink': Required key not available
 ln: failed to create symbolic link 'SCRATCH_MNT/edir/0123456789abcdef': Required key not available
+mv: cannot move 'SCRATCH_MNT/edir/FILENAME' to 'SCRATCH_MNT/edir/FILENAME': Required key not available
+Required key not available
 stat: cannot stat 'SCRATCH_MNT/edir': No such file or directory
-- 
2.12.0.367.g23dc2f6d3c-goog


             reply	other threads:[~2017-03-14 21:24 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-03-14 21:23 Eric Biggers [this message]
2017-03-15  9:39 ` [PATCH] generic/397: test renaming encrypted files without key Eryu Guan
2017-03-15 17:59   ` Eric Biggers

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170314212358.46169-1-ebiggers3@gmail.com \
    --to=ebiggers3@gmail.com \
    --cc=ebiggers@google.com \
    --cc=fstests@vger.kernel.org \
    --cc=jaegeuk@kernel.org \
    --cc=richard@nod.at \
    --cc=tytso@mit.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox