linux/fs/crypto
Eric Biggers 1227ffc9d7 fscrypt: add fscrypt_is_nokey_name()
commit 159e1de201 upstream.

It's possible to create a duplicate filename in an encrypted directory
by creating a file concurrently with adding the encryption key.

Specifically, sys_open(O_CREAT) (or sys_mkdir(), sys_mknod(), or
sys_symlink()) can lookup the target filename while the directory's
encryption key hasn't been added yet, resulting in a negative no-key
dentry.  The VFS then calls ->create() (or ->mkdir(), ->mknod(), or
->symlink()) because the dentry is negative.  Normally, ->create() would
return -ENOKEY due to the directory's key being unavailable.  However,
if the key was added between the dentry lookup and ->create(), then the
filesystem will go ahead and try to create the file.

If the target filename happens to already exist as a normal name (not a
no-key name), a duplicate filename may be added to the directory.

In order to fix this, we need to fix the filesystems to prevent
->create(), ->mkdir(), ->mknod(), and ->symlink() on no-key names.
(->rename() and ->link() need it too, but those are already handled
correctly by fscrypt_prepare_rename() and fscrypt_prepare_link().)

In preparation for this, add a helper function fscrypt_is_nokey_name()
that filesystems can use to do this check.  Use this helper function for
the existing checks that fs/crypto/ does for rename and link.

Cc: stable@vger.kernel.org
Link: https://lore.kernel.org/r/20201118075609.120337-2-ebiggers@kernel.org
Signed-off-by: Eric Biggers <ebiggers@google.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2021-01-06 14:44:58 +01:00
..
bio.c fscrypt: allow synchronous bio decryption 2018-05-02 14:30:57 -07:00
crypto.c fscrypt: clean up and improve dentry revalidation 2020-11-05 11:08:35 +01:00
fname.c fscrypt: fix race where ->lookup() marks plaintext dentry as ciphertext 2020-11-05 11:08:35 +01:00
fscrypt_private.h crypto: speck - remove Speck 2018-11-13 11:08:46 -08:00
hooks.c fscrypt: add fscrypt_is_nokey_name() 2021-01-06 14:44:58 +01:00
Kconfig fscrypt: add support for AES-128-CBC 2017-06-23 20:05:07 -04:00
keyinfo.c crypto: speck - remove Speck 2018-11-13 11:08:46 -08:00
Makefile fscrypt: new helper function - fscrypt_file_open() 2017-10-18 19:52:37 -04:00
policy.c fscrypt: return -EXDEV for incompatible rename or link into encrypted dir 2020-11-05 11:08:35 +01:00