From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 91A2EC388F9 for ; Tue, 3 Nov 2020 21:25:46 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3D3F820757 for ; Tue, 3 Nov 2020 21:25:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1604438746; bh=NCgEeXgIGtG26G81EP7Rjb5PupTf60OODIdNFZgVuYM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=OM6OS7ZJnSc0cfYSQxR33HzoQI7i0oA6NF5VKvpK3Xsd2HhhjJGnHC3eV4+z0o4ji TZS1wuQVY2EgEUBcL58X7uWD1isl2QlB1MAMPLOmFxI8Q/9sDVrzmaXe1s+Al9aJyx 9sMIbnFlV969MMTxXggJtkE7Nc0EtI4VWsUqgVVQ= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388256AbgKCVZp (ORCPT ); Tue, 3 Nov 2020 16:25:45 -0500 Received: from mail.kernel.org ([198.145.29.99]:39380 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387614AbgKCVCU (ORCPT ); Tue, 3 Nov 2020 16:02:20 -0500 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 9762220658; Tue, 3 Nov 2020 21:02:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1604437340; bh=NCgEeXgIGtG26G81EP7Rjb5PupTf60OODIdNFZgVuYM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ke4pVpumifRFuJA06vdJ+TMgX7AfGmt1vdggeQZt7lVQP4OU2/dPXL+hBC0uhiZjk nS3fFIteQ2GaAknP9gk0GMLl/sbgc4/z7s53LkpyhZlrL+QTNq+LxufidPQfi+xlAQ yJxUCO+MlB6X0SbZC4qnUvlB7UMmjdNS+wilAhX4= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Greg Kroah-Hartman , "linux-fscrypt@vger.kernel.org, linux-ext4@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net, linux-mtd@lists.infradead.org, Theodore Tso" , Eric Biggers , Theodore Ts'o Subject: [PATCH 4.19 033/191] fscrypt: only set dentry_operations on ciphertext dentries Date: Tue, 3 Nov 2020 21:35:25 +0100 Message-Id: <20201103203237.007655514@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201103203232.656475008@linuxfoundation.org> References: <20201103203232.656475008@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Eric Biggers 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 Signed-off-by: Theodore Ts'o Signed-off-by: Greg Kroah-Hartman --- fs/crypto/hooks.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) --- a/fs/crypto/hooks.c +++ b/fs/crypto/hooks.c @@ -115,9 +115,8 @@ int __fscrypt_prepare_lookup(struct inod spin_lock(&dentry->d_lock); dentry->d_flags |= DCACHE_ENCRYPTED_NAME; spin_unlock(&dentry->d_lock); + d_set_d_op(dentry, &fscrypt_d_ops); } - - d_set_d_op(dentry, &fscrypt_d_ops); return 0; } EXPORT_SYMBOL_GPL(__fscrypt_prepare_lookup);