From patchwork Wed Feb 8 06:21:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Biggers X-Patchwork-Id: 13132468 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.sourceforge.net (lists.sourceforge.net [216.105.38.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 3D781C64ED6 for ; Wed, 8 Feb 2023 06:21:47 +0000 (UTC) Received: from [127.0.0.1] (helo=sfs-ml-2.v29.lw.sourceforge.com) by sfs-ml-2.v29.lw.sourceforge.com with esmtp (Exim 4.95) (envelope-from ) id 1pPdpz-0004Wu-1r; Wed, 08 Feb 2023 06:21:46 +0000 Received: from [172.30.20.202] (helo=mx.sourceforge.net) by sfs-ml-2.v29.lw.sourceforge.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1pPdpx-0004Wm-S7 for linux-f2fs-devel@lists.sourceforge.net; Wed, 08 Feb 2023 06:21:45 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=Content-Transfer-Encoding:MIME-Version:References: In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=JkFM0WcenL3jza42LrOkjPhnbb7eCgnerOySPiYQcI0=; b=MJjd/XBfKD75HuJWlYM63sre7w f5Naoo8664do5kjbnYXHxsxjvqPbWiksG7V1rYQz5xb/4t4HCr8HxF6COucukfVD0NDHEOX9xl5fI QJAtvc7DfohVaJzPFdt+rkmrvYhI90wpIQu54qufPenquhIupzBLNz3N7mbOaIfRLftE=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-Id: Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=JkFM0WcenL3jza42LrOkjPhnbb7eCgnerOySPiYQcI0=; b=kfhePfzVK/w0Qc+lcM+mgOtDA0 YMa/oCwM7lNK+l8Amsi814ES2GtJ5ldfmUNKnADN25tc+GNTUjAxGyizXM+0oPI8TIsB3NurRxFXn BHi/yen5qKwmioa32uuUEOkainOz3/utBIL5i8Jux5nhnXDtQZP7rRQNJLeGERUtsy04=; Received: from dfw.source.kernel.org ([139.178.84.217]) by sfi-mx-2.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.95) id 1pPdpu-0008Qj-Ej for linux-f2fs-devel@lists.sourceforge.net; Wed, 08 Feb 2023 06:21:45 +0000 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id B2818614D7; Wed, 8 Feb 2023 06:21:35 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id EC55DC433D2; Wed, 8 Feb 2023 06:21:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1675837295; bh=rXzimvd4PWdjTx5BBrxxERaITqXWUNGccCwAWr6IKjY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bqgr3pjenH4hhu5yGdWxOmuBDTfjE4KLBRmr1eWNY3senk1DChomHChHvaaxF6sbw WFt0IatwITKGVY/itxERVpapqWkjt5alhkueEyIKT84lQoCu0gAZ4T1uEu4FJf33/o heMAhP1Ezd9x0FPiBMslUu7RBEXu3HgMborHvzBMxsapUwcOEVrGe3o0JmYKEwck9m S2m6eg9Fv1O+XZQUCAASPtvuI1I1bozwdJGolV70KdhTahQQadD71tVagZeGiTGqSg zLKtosWgeOdtBPa38BSfliQolz1TEODI3gol34EYGKeYBQmVPlK7+cRjlDgxXc/dC3 T73UdOlm3P/mQ== From: Eric Biggers To: linux-fscrypt@vger.kernel.org Date: Tue, 7 Feb 2023 22:21:03 -0800 Message-Id: <20230208062107.199831-2-ebiggers@kernel.org> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230208062107.199831-1-ebiggers@kernel.org> References: <20230208062107.199831-1-ebiggers@kernel.org> MIME-Version: 1.0 X-Headers-End: 1pPdpu-0008Qj-Ej Subject: [f2fs-dev] [PATCH 1/5] fscrypt: add the test dummy encryption key on-demand X-BeenThere: linux-f2fs-devel@lists.sourceforge.net X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-fsdevel@vger.kernel.org, linux-ext4@vger.kernel.org, Linus Torvalds , linux-f2fs-devel@lists.sourceforge.net Errors-To: linux-f2fs-devel-bounces@lists.sourceforge.net From: Eric Biggers When the key for an inode is not found but the inode is using the test_dummy_encryption policy, automatically add the test_dummy_encryption key to the filesystem keyring. This eliminates the need for all the individual filesystems to do this at mount time, which is a bit tricky to clean up from on failure. Note: this covers the call to fscrypt_find_master_key() from inode key setup, but not from the fscrypt ioctls. So, this isn't *exactly* the same as the key being present from the very beginning. I think we can tolerate that, though, since the inode key setup caller is the only one that actually matters in the context of test_dummy_encryption. Signed-off-by: Eric Biggers --- fs/crypto/fscrypt_private.h | 1 + fs/crypto/keysetup.c | 25 +++++++++++++++++++++++-- fs/crypto/policy.c | 3 +-- 3 files changed, 25 insertions(+), 4 deletions(-) diff --git a/fs/crypto/fscrypt_private.h b/fs/crypto/fscrypt_private.h index 316a778cec0ff..17dd33d9a522e 100644 --- a/fs/crypto/fscrypt_private.h +++ b/fs/crypto/fscrypt_private.h @@ -651,6 +651,7 @@ bool fscrypt_policies_equal(const union fscrypt_policy *policy1, const union fscrypt_policy *policy2); int fscrypt_policy_to_key_spec(const union fscrypt_policy *policy, struct fscrypt_key_specifier *key_spec); +const union fscrypt_policy *fscrypt_get_dummy_policy(struct super_block *sb); bool fscrypt_supported_policy(const union fscrypt_policy *policy_u, const struct inode *inode); int fscrypt_policy_from_context(union fscrypt_policy *policy_u, diff --git a/fs/crypto/keysetup.c b/fs/crypto/keysetup.c index 94757ccd30568..20323c0ba4c5e 100644 --- a/fs/crypto/keysetup.c +++ b/fs/crypto/keysetup.c @@ -438,6 +438,7 @@ static int setup_file_encryption_key(struct fscrypt_info *ci, bool need_dirhash_key, struct fscrypt_master_key **mk_ret) { + struct super_block *sb = ci->ci_inode->i_sb; struct fscrypt_key_specifier mk_spec; struct fscrypt_master_key *mk; int err; @@ -450,8 +451,28 @@ static int setup_file_encryption_key(struct fscrypt_info *ci, if (err) return err; - mk = fscrypt_find_master_key(ci->ci_inode->i_sb, &mk_spec); - if (!mk) { + mk = fscrypt_find_master_key(sb, &mk_spec); + if (unlikely(!mk)) { + const union fscrypt_policy *dummy_policy = + fscrypt_get_dummy_policy(sb); + + /* + * Add the test_dummy_encryption key on-demand. In principle, + * it should be added at mount time. Do it here instead so that + * the individual filesystems don't need to worry about adding + * this key at mount time and cleaning up on mount failure. + */ + if (dummy_policy && + fscrypt_policies_equal(dummy_policy, &ci->ci_policy)) { + struct fscrypt_dummy_policy tmp = { dummy_policy }; + + err = fscrypt_add_test_dummy_key(sb, &tmp); + if (err) + return err; + mk = fscrypt_find_master_key(sb, &mk_spec); + } + } + if (unlikely(!mk)) { if (ci->ci_policy.version != FSCRYPT_POLICY_V1) return -ENOKEY; diff --git a/fs/crypto/policy.c b/fs/crypto/policy.c index 893661b523769..69dca4ff5f488 100644 --- a/fs/crypto/policy.c +++ b/fs/crypto/policy.c @@ -53,8 +53,7 @@ int fscrypt_policy_to_key_spec(const union fscrypt_policy *policy, } } -static const union fscrypt_policy * -fscrypt_get_dummy_policy(struct super_block *sb) +const union fscrypt_policy *fscrypt_get_dummy_policy(struct super_block *sb) { if (!sb->s_cop->get_dummy_policy) return NULL; From patchwork Wed Feb 8 06:21:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Biggers X-Patchwork-Id: 13132471 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.sourceforge.net (lists.sourceforge.net [216.105.38.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 82317C636CC for ; Wed, 8 Feb 2023 06:21:55 +0000 (UTC) Received: from [127.0.0.1] (helo=sfs-ml-4.v29.lw.sourceforge.com) by sfs-ml-4.v29.lw.sourceforge.com with esmtp (Exim 4.95) (envelope-from ) id 1pPdq8-0006LB-Fv; Wed, 08 Feb 2023 06:21:55 +0000 Received: from [172.30.20.202] (helo=mx.sourceforge.net) by sfs-ml-4.v29.lw.sourceforge.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1pPdpx-0006Kn-BI for linux-f2fs-devel@lists.sourceforge.net; Wed, 08 Feb 2023 06:21:43 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=Content-Transfer-Encoding:MIME-Version:References: In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=Qrrmuw3XnvQUPWSh2rYSo7BzQ8UPQb+RFl56nqNFV7E=; b=FX718Atr4OFbA7n+broTw/TiAY tbtgxLHjUtu8MFniZTFJt3wFdLDNl8RHuD8jM/MykjVZi6hDW9YnbOpp5fsgPQr/wK4HG3qsFpK47 0UgL+yOMua1NTAM7JvOUChgu3vevrLUDbHw6k80HGN3RbN8pde82Sy0kEJ4BAfkollsQ=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-Id: Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=Qrrmuw3XnvQUPWSh2rYSo7BzQ8UPQb+RFl56nqNFV7E=; b=hGnZ2KSuTAYjIZJPb9NPKLbgUD E9HDxu8QuBYOlUa9BMyWXY2XJw/r/1ro13B+RwfP2gljNF6isDOUq/WpNhcSIoUsWGOp09jhIqD8/ CRvYW7YqypFc+UOE26LvrTcvlB1Dtt+ejgKpQNVC+KkzV98XpMVjqN/cuy5Fa05w9rpw=; Received: from dfw.source.kernel.org ([139.178.84.217]) by sfi-mx-2.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.95) id 1pPdpu-0008Qo-Gl for linux-f2fs-devel@lists.sourceforge.net; Wed, 08 Feb 2023 06:21:43 +0000 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 16F91614E1; Wed, 8 Feb 2023 06:21:36 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 46C26C4339B; Wed, 8 Feb 2023 06:21:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1675837295; bh=kfr98bGzVCZ89v5RF0C39SP0fCvbpfqJYzf6QFQbhlc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=vNp1UKHXj/Iwfo2wnOJu9HISJGFDp8Ak2VghNEydsMfUfm14hT+A1VvSuRDmI4/LA LqQ9bHnJnch8CTDA7s2xPU6WlgwbiMVvZMkX+2NytMXtsPa7nOAREhPr+2TwKTDNr1 +U6RBTgwmam283E1xcZPMK8gMOHQOJjTUEYUoux7Y8DW+HVKvc2xqnri4n4kHiBInS UpuhbJObRfKNnaexU7Deca24KaeQf3c7O8szvMDNcM1A0r5+aw1hUTeXLwkmjs/h1l /ym4oDpYxxXjQQ9VqyNRpsPX1S1er6TsJ401l5ReYKH9DPPDcmzsimS7idcPDQDvjj IegFclMH9Bm8w== From: Eric Biggers To: linux-fscrypt@vger.kernel.org Date: Tue, 7 Feb 2023 22:21:04 -0800 Message-Id: <20230208062107.199831-3-ebiggers@kernel.org> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230208062107.199831-1-ebiggers@kernel.org> References: <20230208062107.199831-1-ebiggers@kernel.org> MIME-Version: 1.0 X-Headers-End: 1pPdpu-0008Qo-Gl Subject: [f2fs-dev] [PATCH 2/5] ext4: stop calling fscrypt_add_test_dummy_key() X-BeenThere: linux-f2fs-devel@lists.sourceforge.net X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-fsdevel@vger.kernel.org, linux-ext4@vger.kernel.org, Linus Torvalds , linux-f2fs-devel@lists.sourceforge.net Errors-To: linux-f2fs-devel-bounces@lists.sourceforge.net From: Eric Biggers Now that fs/crypto/ adds the test dummy encryption key on-demand when it's needed, there's no need for individual filesystems to call fscrypt_add_test_dummy_key(). Remove the call to it from ext4. Signed-off-by: Eric Biggers --- fs/ext4/super.c | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/fs/ext4/super.c b/fs/ext4/super.c index 260c1b3e3ef2c..260bbab25db38 100644 --- a/fs/ext4/super.c +++ b/fs/ext4/super.c @@ -2635,7 +2635,6 @@ static int ext4_check_test_dummy_encryption(const struct fs_context *fc, { const struct ext4_fs_context *ctx = fc->fs_private; const struct ext4_sb_info *sbi = EXT4_SB(sb); - int err; if (!fscrypt_is_dummy_policy_set(&ctx->dummy_enc_policy)) return 0; @@ -2668,17 +2667,7 @@ static int ext4_check_test_dummy_encryption(const struct fs_context *fc, "Conflicting test_dummy_encryption options"); return -EINVAL; } - /* - * fscrypt_add_test_dummy_key() technically changes the super_block, so - * technically it should be delayed until ext4_apply_options() like the - * other changes. But since we never get here for remounts (see above), - * and this is the last chance to report errors, we do it here. - */ - err = fscrypt_add_test_dummy_key(sb, &ctx->dummy_enc_policy); - if (err) - ext4_msg(NULL, KERN_WARNING, - "Error adding test dummy encryption key [%d]", err); - return err; + return 0; } static void ext4_apply_test_dummy_encryption(struct ext4_fs_context *ctx, From patchwork Wed Feb 8 06:21:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Biggers X-Patchwork-Id: 13132472 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.sourceforge.net (lists.sourceforge.net [216.105.38.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id C3F94C05027 for ; Wed, 8 Feb 2023 06:21:55 +0000 (UTC) Received: from [127.0.0.1] (helo=sfs-ml-4.v29.lw.sourceforge.com) by sfs-ml-4.v29.lw.sourceforge.com with esmtp (Exim 4.95) (envelope-from ) id 1pPdq8-0006LN-PF; Wed, 08 Feb 2023 06:21:55 +0000 Received: from [172.30.20.202] (helo=mx.sourceforge.net) by sfs-ml-4.v29.lw.sourceforge.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1pPdpy-0006Ku-Ue for linux-f2fs-devel@lists.sourceforge.net; Wed, 08 Feb 2023 06:21:45 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=Content-Transfer-Encoding:MIME-Version:References: In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=hDaq+hzSVVr5/sihIKGTr4ISu/lQ4Nf0whpSXh44p6Y=; b=N/adQMzFa+rw2yQyYtz4thmf4f vxzlcLRLqWv13Vp0C1PS4HSQVOc8931tozcM2GlzLrxSPimv1m7ZRixg6cKmOkcGKbJ9FDPYl+q4n fbzEtFbgQIwziOb0bX57rCRd9spqHszo0uTvu1eUzo/nhq5iQxTe2xblg8J3KdwGhJvs=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-Id: Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=hDaq+hzSVVr5/sihIKGTr4ISu/lQ4Nf0whpSXh44p6Y=; b=l01kFvY5TXvYgbKCg/tVf18+3w EioAOLhAtmSidn52l2fziCLVogcBcRC+8FIc7v+EJCHRbZ7BNHREut4IjNQW4gSOi6ihSzrJJiJKo pdxsXaXuTvOTWmI3Mvf/zaw6yxN7B0807VQQQGrkbDhEq0stERom++JfKZf2bAdKcfgA=; Received: from dfw.source.kernel.org ([139.178.84.217]) by sfi-mx-1.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.95) id 1pPdpw-00EiFu-Uy for linux-f2fs-devel@lists.sourceforge.net; Wed, 08 Feb 2023 06:21:45 +0000 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 5AB85614E4; Wed, 8 Feb 2023 06:21:36 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 962A8C4339E; Wed, 8 Feb 2023 06:21:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1675837295; bh=sQVJxIPMagQOo1HvXPpx7fyeR0XGhmDecu3YxyPB1CY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=DbGtwnF4VnuwU4on1O7/cEfWfHUtx13gh7P3p8mGefvuSnr1Ike5IbZgNRonYmLak TlZiwaey1dosbaeUDX+gS6i63mlXqU+UUnqw3ObBCq5amvYOD+PdMoBuEbDHpWdTeE 7Tf+IAkd9SNsWzJrexAGucM8cE6kuRJGukl+uiN49e23GgXqvpHO04TJjfHzI9VhdH dPlxSQ6u82GVy9gg6YzNeoUC8+osvpsuBem37izs+Vr7b9l0T48EplZNtLsVCjt7lB lBZpV3e3rS9HUxDLQYLa0e6DwSGUDLlMXwL7Bb8UZoX4o17JL+rQDuXZ73F7xtKhQq B0+C/uOTOfAog== From: Eric Biggers To: linux-fscrypt@vger.kernel.org Date: Tue, 7 Feb 2023 22:21:05 -0800 Message-Id: <20230208062107.199831-4-ebiggers@kernel.org> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230208062107.199831-1-ebiggers@kernel.org> References: <20230208062107.199831-1-ebiggers@kernel.org> MIME-Version: 1.0 X-Headers-End: 1pPdpw-00EiFu-Uy Subject: [f2fs-dev] [PATCH 3/5] f2fs: stop calling fscrypt_add_test_dummy_key() X-BeenThere: linux-f2fs-devel@lists.sourceforge.net X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-fsdevel@vger.kernel.org, linux-ext4@vger.kernel.org, Linus Torvalds , linux-f2fs-devel@lists.sourceforge.net Errors-To: linux-f2fs-devel-bounces@lists.sourceforge.net From: Eric Biggers Now that fs/crypto/ adds the test dummy encryption key on-demand when it's needed, there's no need for individual filesystems to call fscrypt_add_test_dummy_key(). Remove the call to it from f2fs. Signed-off-by: Eric Biggers --- fs/f2fs/super.c | 6 ------ 1 file changed, 6 deletions(-) diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c index 1f812b9ce985b..64d3556d61a55 100644 --- a/fs/f2fs/super.c +++ b/fs/f2fs/super.c @@ -540,12 +540,6 @@ static int f2fs_set_test_dummy_encryption(struct super_block *sb, opt, err); return -EINVAL; } - err = fscrypt_add_test_dummy_key(sb, policy); - if (err) { - f2fs_warn(sbi, "Error adding test dummy encryption key [%d]", - err); - return err; - } f2fs_warn(sbi, "Test dummy encryption mode enabled"); return 0; } From patchwork Wed Feb 8 06:21:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Biggers X-Patchwork-Id: 13132470 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.sourceforge.net (lists.sourceforge.net [216.105.38.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 8494EC636CC for ; Wed, 8 Feb 2023 06:21:50 +0000 (UTC) Received: from [127.0.0.1] (helo=sfs-ml-1.v29.lw.sourceforge.com) by sfs-ml-1.v29.lw.sourceforge.com with esmtp (Exim 4.95) (envelope-from ) id 1pPdpz-0007dn-KH; Wed, 08 Feb 2023 06:21:46 +0000 Received: from [172.30.20.202] (helo=mx.sourceforge.net) by sfs-ml-1.v29.lw.sourceforge.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1pPdpx-0007dg-VX for linux-f2fs-devel@lists.sourceforge.net; Wed, 08 Feb 2023 06:21:45 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=Content-Transfer-Encoding:MIME-Version:References: In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=5YCJw/RLnPdh8GovstVbf2rVyqeI/UAHHsIVqhugQMw=; b=eQSH/QEUdBvVXQgLG7TO4qfJ+U S35e/6CwP1ZYlGS4O45QDxsilOju1pQdYrmwSew0E8wqRQk+polmZwVv4npdmd4cl9pXbdsL+XmNd wpHvJorFXw1KL5xKx4tF33i8R3vp2qmcriwdaGGG4yfm1CaUu82+6Iuuhx3xKaOvgu/0=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-Id: Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=5YCJw/RLnPdh8GovstVbf2rVyqeI/UAHHsIVqhugQMw=; b=fAyEgJ0WBIa2o91kWL6rOBmyQe fctVQCcA72gkGEQ1pjvEzyXrShhtGrIS+bEAQo9VW7oZQlhMLVUsKjJtYReiLBlq637S8sUt6DESe nvN7CUgbLbeDNxkwWLffJR9K6NoJIuTtF5exD87nha8AD5BQM9IdJT7ox9JSQ9PJRGKg=; Received: from dfw.source.kernel.org ([139.178.84.217]) by sfi-mx-2.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.95) id 1pPdpu-0008Qp-En for linux-f2fs-devel@lists.sourceforge.net; Wed, 08 Feb 2023 06:21:45 +0000 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 4A04C614E2; Wed, 8 Feb 2023 06:21:36 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E4C28C433A0; Wed, 8 Feb 2023 06:21:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1675837296; bh=yjmeR+HuHfvezqUObRjW0JmkMkN4qqziD8/F7kQFQoY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hT9wbh5lvDI4fsinMVQlijsAmGKYTa8mpzuBKjJvZdcI59ojR9Cc8Y0JeTfP6EcUW gnmWte7KXT5+7DMRhWstF+GOYeEdc0mWM3C9q2/d/uS++ZXpPcKaWFLMX+5Bz0KcXV svLKcryv3OwMsB3NjgUpy1TI4h79P4ZvpFk8EY2LMpMMK4U8+/AEy4nESn4eHgVt2Q LDB5rnitSdhws3R/f5wYRp6nIbFdruxxBqVUbwNsv97kpoCbHw1Myev+E+sNUpoVfR qJTkvr0Y+k9p1FoLAfA1PRBrCLIYncTqVpO0qbIa2pNsuyBF39Uj5wCQbAp8HfXVcz N+FuuAq++dH3g== From: Eric Biggers To: linux-fscrypt@vger.kernel.org Date: Tue, 7 Feb 2023 22:21:06 -0800 Message-Id: <20230208062107.199831-5-ebiggers@kernel.org> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230208062107.199831-1-ebiggers@kernel.org> References: <20230208062107.199831-1-ebiggers@kernel.org> MIME-Version: 1.0 X-Headers-End: 1pPdpu-0008Qp-En Subject: [f2fs-dev] [PATCH 4/5] fs/super.c: stop calling fscrypt_destroy_keyring() from __put_super() X-BeenThere: linux-f2fs-devel@lists.sourceforge.net X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-fsdevel@vger.kernel.org, linux-ext4@vger.kernel.org, Linus Torvalds , linux-f2fs-devel@lists.sourceforge.net Errors-To: linux-f2fs-devel-bounces@lists.sourceforge.net From: Eric Biggers Now that the key associated with the "test_dummy_operation" mount option is added on-demand when it's needed, rather than immediately when the filesystem is mounted, fscrypt_destroy_keyring() no longer needs to be called from __put_super() to avoid a memory leak on mount failure. Remove this call, which was causing confusion because it appeared to be a sleep-in-atomic bug (though it wasn't, for a somewhat-subtle reason). Signed-off-by: Eric Biggers --- fs/super.c | 1 - 1 file changed, 1 deletion(-) diff --git a/fs/super.c b/fs/super.c index 12c08cb20405d..ce45b7fd27f90 100644 --- a/fs/super.c +++ b/fs/super.c @@ -291,7 +291,6 @@ static void __put_super(struct super_block *s) WARN_ON(s->s_inode_lru.node); WARN_ON(!list_empty(&s->s_mounts)); security_sb_free(s); - fscrypt_destroy_keyring(s); put_user_ns(s->s_user_ns); kfree(s->s_subtype); call_rcu(&s->rcu, destroy_super_rcu); From patchwork Wed Feb 8 06:21:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Biggers X-Patchwork-Id: 13132473 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.sourceforge.net (lists.sourceforge.net [216.105.38.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 72F9BC636D3 for ; Wed, 8 Feb 2023 06:21:56 +0000 (UTC) Received: from [127.0.0.1] (helo=sfs-ml-4.v29.lw.sourceforge.com) by sfs-ml-4.v29.lw.sourceforge.com with esmtp (Exim 4.95) (envelope-from ) id 1pPdq9-0006La-4U; Wed, 08 Feb 2023 06:21:55 +0000 Received: from [172.30.20.202] (helo=mx.sourceforge.net) by sfs-ml-4.v29.lw.sourceforge.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1pPdpz-0006L0-QE for linux-f2fs-devel@lists.sourceforge.net; Wed, 08 Feb 2023 06:21:46 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=Content-Transfer-Encoding:MIME-Version:References: In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=ZM2gebMby0FP9+HsVZ0LPm3InqNmJr/0inCyE6wV4Pk=; b=UdGNsZ+jxiMe1nwE5fGlzsr4l0 X1H71FRKZ9/v9IdRRtvs13u20wC51ELv7yN+eukoW8Z9vzVZnGGRpArCkys3VehTrte0DNhS4rjmm wz1MCvsgRZcPvZwmzkVzooBb+utFn6hm+M4oJAP7ZHjraqd8+QtljBmUopRhZNuTT3lo=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-Id: Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=ZM2gebMby0FP9+HsVZ0LPm3InqNmJr/0inCyE6wV4Pk=; b=avoeMxB0m9VwcjKycIzjpfwBVe 1GE6Z5kPMdzRnb+5s/vW/QDiJuOHDP1zlFDw4dWfiLsrWei8TnRG/QkhBZX0FbtcLHjU9hpERsymV SVkbuNmpJc5bFASVZvyZUdXyGvW5JgahRjcl7Y6vNEnKnloFSK0qud/V3j73gNGAJii8=; Received: from ams.source.kernel.org ([145.40.68.75]) by sfi-mx-2.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.95) id 1pPdpv-0008R5-Eu for linux-f2fs-devel@lists.sourceforge.net; Wed, 08 Feb 2023 06:21:46 +0000 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id B13AAB81C20; Wed, 8 Feb 2023 06:21:37 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3F8D2C4339C; Wed, 8 Feb 2023 06:21:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1675837296; bh=9FKAgPpudsEY1b71O+8Pdv2NPJKqQ94hKa6qzZM+f/E=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=X2gSotr/T2tuDmj7eKZmGldsLfnOOCW8QnUhI2J1RVyfsgRQkq6H/4aUYesDQqe5u p9xk2PzVPdD3+GWILcUbgcq3lYj62oT2jWOjX9pvjpMINlDn9DM8Ba7BMJtgrazy7L MQnl1SYZ/1vlQofGYyiIllHv+nQqLWAQJKdkHMJRW0XXpjuq+/53oHp4oNTNvW0uXB DGMASFJ6wcbYlRfKN9HQJ83ru/vWVpJ761mzUoHLe2g8zHMOvokUupC6LVJnjhERJI HXgyqcAzu02y7ZMxIXGiHqkJumxfzUmZ6lJ7AZurqZgLD7eZw3M/uzoUunaFzn/wNP zEVtwiPO+49gw== From: Eric Biggers To: linux-fscrypt@vger.kernel.org Date: Tue, 7 Feb 2023 22:21:07 -0800 Message-Id: <20230208062107.199831-6-ebiggers@kernel.org> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230208062107.199831-1-ebiggers@kernel.org> References: <20230208062107.199831-1-ebiggers@kernel.org> MIME-Version: 1.0 X-Headers-End: 1pPdpv-0008R5-Eu Subject: [f2fs-dev] [PATCH 5/5] fscrypt: clean up fscrypt_add_test_dummy_key() X-BeenThere: linux-f2fs-devel@lists.sourceforge.net X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-fsdevel@vger.kernel.org, linux-ext4@vger.kernel.org, Linus Torvalds , linux-f2fs-devel@lists.sourceforge.net Errors-To: linux-f2fs-devel-bounces@lists.sourceforge.net From: Eric Biggers Now that fscrypt_add_test_dummy_key() is only called by setup_file_encryption_key() and not by the individual filesystems, un-export it. Also change its prototype to take the fscrypt_key_specifier directly, as the caller already has it. Signed-off-by: Eric Biggers --- fs/crypto/fscrypt_private.h | 3 +++ fs/crypto/keyring.c | 26 +++++++------------------- fs/crypto/keysetup.c | 4 +--- include/linux/fscrypt.h | 9 --------- 4 files changed, 11 insertions(+), 31 deletions(-) diff --git a/fs/crypto/fscrypt_private.h b/fs/crypto/fscrypt_private.h index 17dd33d9a522e..0fec2dfc36ebe 100644 --- a/fs/crypto/fscrypt_private.h +++ b/fs/crypto/fscrypt_private.h @@ -573,6 +573,9 @@ fscrypt_find_master_key(struct super_block *sb, int fscrypt_get_test_dummy_key_identifier( u8 key_identifier[FSCRYPT_KEY_IDENTIFIER_SIZE]); +int fscrypt_add_test_dummy_key(struct super_block *sb, + struct fscrypt_key_specifier *key_spec); + int fscrypt_verify_key_added(struct super_block *sb, const u8 identifier[FSCRYPT_KEY_IDENTIFIER_SIZE]); diff --git a/fs/crypto/keyring.c b/fs/crypto/keyring.c index 78dd2ff306bd7..78086f8dbda52 100644 --- a/fs/crypto/keyring.c +++ b/fs/crypto/keyring.c @@ -211,10 +211,6 @@ static int allocate_filesystem_keyring(struct super_block *sb) * are still available at this time; this is important because after user file * accesses have been allowed, this function may need to evict keys from the * keyslots of an inline crypto engine, which requires the block device(s). - * - * This is also called when the super_block is being freed. This is needed to - * avoid a memory leak if mounting fails after the "test_dummy_encryption" - * option was processed, as in that case the unmount-time call isn't made. */ void fscrypt_destroy_keyring(struct super_block *sb) { @@ -778,34 +774,26 @@ int fscrypt_get_test_dummy_key_identifier( /** * fscrypt_add_test_dummy_key() - add the test dummy encryption key * @sb: the filesystem instance to add the key to - * @dummy_policy: the encryption policy for test_dummy_encryption + * @key_spec: the key specifier of the test dummy encryption key * - * If needed, add the key for the test_dummy_encryption mount option to the - * filesystem. To prevent misuse of this mount option, a per-boot random key is - * used instead of a hardcoded one. This makes it so that any encrypted files - * created using this option won't be accessible after a reboot. + * Add the key for the test_dummy_encryption mount option to the filesystem. To + * prevent misuse of this mount option, a per-boot random key is used instead of + * a hardcoded one. This makes it so that any encrypted files created using + * this option won't be accessible after a reboot. * * Return: 0 on success, -errno on failure */ int fscrypt_add_test_dummy_key(struct super_block *sb, - const struct fscrypt_dummy_policy *dummy_policy) + struct fscrypt_key_specifier *key_spec) { - const union fscrypt_policy *policy = dummy_policy->policy; - struct fscrypt_key_specifier key_spec; struct fscrypt_master_key_secret secret; int err; - if (!policy) - return 0; - err = fscrypt_policy_to_key_spec(policy, &key_spec); - if (err) - return err; fscrypt_get_test_dummy_secret(&secret); - err = add_master_key(sb, &secret, &key_spec); + err = add_master_key(sb, &secret, key_spec); wipe_master_key_secret(&secret); return err; } -EXPORT_SYMBOL_GPL(fscrypt_add_test_dummy_key); /* * Verify that the current user has added a master key with the given identifier diff --git a/fs/crypto/keysetup.c b/fs/crypto/keysetup.c index 20323c0ba4c5e..aa94fba9d17e7 100644 --- a/fs/crypto/keysetup.c +++ b/fs/crypto/keysetup.c @@ -464,9 +464,7 @@ static int setup_file_encryption_key(struct fscrypt_info *ci, */ if (dummy_policy && fscrypt_policies_equal(dummy_policy, &ci->ci_policy)) { - struct fscrypt_dummy_policy tmp = { dummy_policy }; - - err = fscrypt_add_test_dummy_key(sb, &tmp); + err = fscrypt_add_test_dummy_key(sb, &mk_spec); if (err) return err; mk = fscrypt_find_master_key(sb, &mk_spec); diff --git a/include/linux/fscrypt.h b/include/linux/fscrypt.h index 4f5f8a6512132..44848d870046a 100644 --- a/include/linux/fscrypt.h +++ b/include/linux/fscrypt.h @@ -309,8 +309,6 @@ fscrypt_free_dummy_policy(struct fscrypt_dummy_policy *dummy_policy) /* keyring.c */ void fscrypt_destroy_keyring(struct super_block *sb); int fscrypt_ioctl_add_key(struct file *filp, void __user *arg); -int fscrypt_add_test_dummy_key(struct super_block *sb, - const struct fscrypt_dummy_policy *dummy_policy); int fscrypt_ioctl_remove_key(struct file *filp, void __user *arg); int fscrypt_ioctl_remove_key_all_users(struct file *filp, void __user *arg); int fscrypt_ioctl_get_key_status(struct file *filp, void __user *arg); @@ -530,13 +528,6 @@ static inline int fscrypt_ioctl_add_key(struct file *filp, void __user *arg) return -EOPNOTSUPP; } -static inline int -fscrypt_add_test_dummy_key(struct super_block *sb, - const struct fscrypt_dummy_policy *dummy_policy) -{ - return 0; -} - static inline int fscrypt_ioctl_remove_key(struct file *filp, void __user *arg) { return -EOPNOTSUPP;