]> git.ipfire.org Git - thirdparty/kernel/stable.git/commit
fscrypt: only set dentry_operations on ciphertext dentries
authorEric Biggers <ebiggers@google.com>
Sat, 31 Oct 2020 22:05:52 +0000 (15:05 -0700)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 5 Nov 2020 10:08:35 +0000 (11:08 +0100)
commitf217c9685c39735f8a8080d00d17ae2e9d536823
tree0c577167c219b71d073e5156c7cc18ec6a3af5bf
parent906242d10b0b9279e5fda9691c13500d5b1fb543
fscrypt: only set dentry_operations on ciphertext dentries

commit d456a33f041af4b54f3ce495a86d00c246165032 upstream.

Plaintext dentries are always valid, so only set fscrypt_d_ops on
ciphertext dentries.

Besides marginally improved performance, this allows overlayfs to use an
fscrypt-encrypted upperdir, provided that all the following are true:

    (1) The fscrypt encryption key is placed in the keyring before
mounting overlayfs, and remains while the overlayfs is mounted.

    (2) The overlayfs workdir uses the same encryption policy.

    (3) No dentries for the ciphertext names of subdirectories have been
created in the upperdir or workdir yet.  (Since otherwise
d_splice_alias() will reuse the old dentry with ->d_op set.)

One potential use case is using an ephemeral encryption key to encrypt
all files created or changed by a container, so that they can be
securely erased ("crypto-shredded") after the container stops.

Signed-off-by: Eric Biggers <ebiggers@google.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
fs/crypto/hooks.c