From: Eric Biggers <ebiggers@kernel.org>
To: linux-fscrypt@vger.kernel.org, linux-ext4@vger.kernel.org,
linux-f2fs-devel@lists.sourceforge.net
Cc: Lukas Czerner <lczerner@redhat.com>,
Theodore Ts'o <tytso@mit.edu>, Jaegeuk Kim <jaegeuk@kernel.org>,
Jeff Layton <jlayton@kernel.org>
Subject: [PATCH v2 3/7] fscrypt: factor out fscrypt_policy_to_key_spec()
Date: Sat, 30 Apr 2022 22:08:53 -0700 [thread overview]
Message-ID: <20220501050857.538984-4-ebiggers@kernel.org> (raw)
In-Reply-To: <20220501050857.538984-1-ebiggers@kernel.org>
From: Eric Biggers <ebiggers@google.com>
Factor out a function that builds the fscrypt_key_specifier for an
fscrypt_policy. Before this was only needed when finding the key for a
file, but now it will also be needed for test_dummy_encryption support.
Signed-off-by: Eric Biggers <ebiggers@google.com>
---
fs/crypto/fscrypt_private.h | 2 ++
fs/crypto/keysetup.c | 20 +++-----------------
fs/crypto/policy.c | 20 ++++++++++++++++++++
3 files changed, 25 insertions(+), 17 deletions(-)
diff --git a/fs/crypto/fscrypt_private.h b/fs/crypto/fscrypt_private.h
index 5b0a9e6478b5d..f32d0ee91e70e 100644
--- a/fs/crypto/fscrypt_private.h
+++ b/fs/crypto/fscrypt_private.h
@@ -621,6 +621,8 @@ int fscrypt_setup_v1_file_key_via_subscribed_keyrings(struct fscrypt_info *ci);
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);
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 eede186b04ce3..571d220d6e226 100644
--- a/fs/crypto/keysetup.c
+++ b/fs/crypto/keysetup.c
@@ -425,23 +425,9 @@ static int setup_file_encryption_key(struct fscrypt_info *ci,
if (err)
return err;
- switch (ci->ci_policy.version) {
- case FSCRYPT_POLICY_V1:
- mk_spec.type = FSCRYPT_KEY_SPEC_TYPE_DESCRIPTOR;
- memcpy(mk_spec.u.descriptor,
- ci->ci_policy.v1.master_key_descriptor,
- FSCRYPT_KEY_DESCRIPTOR_SIZE);
- break;
- case FSCRYPT_POLICY_V2:
- mk_spec.type = FSCRYPT_KEY_SPEC_TYPE_IDENTIFIER;
- memcpy(mk_spec.u.identifier,
- ci->ci_policy.v2.master_key_identifier,
- FSCRYPT_KEY_IDENTIFIER_SIZE);
- break;
- default:
- WARN_ON(1);
- return -EINVAL;
- }
+ err = fscrypt_policy_to_key_spec(&ci->ci_policy, &mk_spec);
+ if (err)
+ return err;
key = fscrypt_find_master_key(ci->ci_inode->i_sb, &mk_spec);
if (IS_ERR(key)) {
diff --git a/fs/crypto/policy.c b/fs/crypto/policy.c
index ed3d623724cdd..2a11276913a98 100644
--- a/fs/crypto/policy.c
+++ b/fs/crypto/policy.c
@@ -32,6 +32,26 @@ bool fscrypt_policies_equal(const union fscrypt_policy *policy1,
return !memcmp(policy1, policy2, fscrypt_policy_size(policy1));
}
+int fscrypt_policy_to_key_spec(const union fscrypt_policy *policy,
+ struct fscrypt_key_specifier *key_spec)
+{
+ switch (policy->version) {
+ case FSCRYPT_POLICY_V1:
+ key_spec->type = FSCRYPT_KEY_SPEC_TYPE_DESCRIPTOR;
+ memcpy(key_spec->u.descriptor, policy->v1.master_key_descriptor,
+ FSCRYPT_KEY_DESCRIPTOR_SIZE);
+ return 0;
+ case FSCRYPT_POLICY_V2:
+ key_spec->type = FSCRYPT_KEY_SPEC_TYPE_IDENTIFIER;
+ memcpy(key_spec->u.identifier, policy->v2.master_key_identifier,
+ FSCRYPT_KEY_IDENTIFIER_SIZE);
+ return 0;
+ default:
+ WARN_ON(1);
+ return -EINVAL;
+ }
+}
+
static const union fscrypt_policy *
fscrypt_get_dummy_policy(struct super_block *sb)
{
--
2.36.0
WARNING: multiple messages have this Message-ID (diff)
From: Eric Biggers <ebiggers@kernel.org>
To: linux-fscrypt@vger.kernel.org, linux-ext4@vger.kernel.org,
linux-f2fs-devel@lists.sourceforge.net
Cc: Jeff Layton <jlayton@kernel.org>,
Lukas Czerner <lczerner@redhat.com>,
Theodore Ts'o <tytso@mit.edu>, Jaegeuk Kim <jaegeuk@kernel.org>
Subject: [f2fs-dev] [PATCH v2 3/7] fscrypt: factor out fscrypt_policy_to_key_spec()
Date: Sat, 30 Apr 2022 22:08:53 -0700 [thread overview]
Message-ID: <20220501050857.538984-4-ebiggers@kernel.org> (raw)
In-Reply-To: <20220501050857.538984-1-ebiggers@kernel.org>
From: Eric Biggers <ebiggers@google.com>
Factor out a function that builds the fscrypt_key_specifier for an
fscrypt_policy. Before this was only needed when finding the key for a
file, but now it will also be needed for test_dummy_encryption support.
Signed-off-by: Eric Biggers <ebiggers@google.com>
---
fs/crypto/fscrypt_private.h | 2 ++
fs/crypto/keysetup.c | 20 +++-----------------
fs/crypto/policy.c | 20 ++++++++++++++++++++
3 files changed, 25 insertions(+), 17 deletions(-)
diff --git a/fs/crypto/fscrypt_private.h b/fs/crypto/fscrypt_private.h
index 5b0a9e6478b5d..f32d0ee91e70e 100644
--- a/fs/crypto/fscrypt_private.h
+++ b/fs/crypto/fscrypt_private.h
@@ -621,6 +621,8 @@ int fscrypt_setup_v1_file_key_via_subscribed_keyrings(struct fscrypt_info *ci);
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);
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 eede186b04ce3..571d220d6e226 100644
--- a/fs/crypto/keysetup.c
+++ b/fs/crypto/keysetup.c
@@ -425,23 +425,9 @@ static int setup_file_encryption_key(struct fscrypt_info *ci,
if (err)
return err;
- switch (ci->ci_policy.version) {
- case FSCRYPT_POLICY_V1:
- mk_spec.type = FSCRYPT_KEY_SPEC_TYPE_DESCRIPTOR;
- memcpy(mk_spec.u.descriptor,
- ci->ci_policy.v1.master_key_descriptor,
- FSCRYPT_KEY_DESCRIPTOR_SIZE);
- break;
- case FSCRYPT_POLICY_V2:
- mk_spec.type = FSCRYPT_KEY_SPEC_TYPE_IDENTIFIER;
- memcpy(mk_spec.u.identifier,
- ci->ci_policy.v2.master_key_identifier,
- FSCRYPT_KEY_IDENTIFIER_SIZE);
- break;
- default:
- WARN_ON(1);
- return -EINVAL;
- }
+ err = fscrypt_policy_to_key_spec(&ci->ci_policy, &mk_spec);
+ if (err)
+ return err;
key = fscrypt_find_master_key(ci->ci_inode->i_sb, &mk_spec);
if (IS_ERR(key)) {
diff --git a/fs/crypto/policy.c b/fs/crypto/policy.c
index ed3d623724cdd..2a11276913a98 100644
--- a/fs/crypto/policy.c
+++ b/fs/crypto/policy.c
@@ -32,6 +32,26 @@ bool fscrypt_policies_equal(const union fscrypt_policy *policy1,
return !memcmp(policy1, policy2, fscrypt_policy_size(policy1));
}
+int fscrypt_policy_to_key_spec(const union fscrypt_policy *policy,
+ struct fscrypt_key_specifier *key_spec)
+{
+ switch (policy->version) {
+ case FSCRYPT_POLICY_V1:
+ key_spec->type = FSCRYPT_KEY_SPEC_TYPE_DESCRIPTOR;
+ memcpy(key_spec->u.descriptor, policy->v1.master_key_descriptor,
+ FSCRYPT_KEY_DESCRIPTOR_SIZE);
+ return 0;
+ case FSCRYPT_POLICY_V2:
+ key_spec->type = FSCRYPT_KEY_SPEC_TYPE_IDENTIFIER;
+ memcpy(key_spec->u.identifier, policy->v2.master_key_identifier,
+ FSCRYPT_KEY_IDENTIFIER_SIZE);
+ return 0;
+ default:
+ WARN_ON(1);
+ return -EINVAL;
+ }
+}
+
static const union fscrypt_policy *
fscrypt_get_dummy_policy(struct super_block *sb)
{
--
2.36.0
_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
next prev parent reply other threads:[~2022-05-01 5:13 UTC|newest]
Thread overview: 42+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-05-01 5:08 [PATCH v2 0/7] test_dummy_encryption fixes and cleanups Eric Biggers
2022-05-01 5:08 ` [f2fs-dev] " Eric Biggers
2022-05-01 5:08 ` [PATCH v2 1/7] ext4: only allow test_dummy_encryption when supported Eric Biggers
2022-05-01 5:08 ` [f2fs-dev] " Eric Biggers
2022-05-11 12:50 ` Ritesh Harjani
2022-05-11 12:50 ` [f2fs-dev] " Ritesh Harjani
2022-05-11 17:18 ` Eric Biggers
2022-05-11 17:18 ` [f2fs-dev] " Eric Biggers
2022-05-01 5:08 ` [PATCH v2 2/7] f2fs: reject test_dummy_encryption when !CONFIG_FS_ENCRYPTION Eric Biggers
2022-05-01 5:08 ` [f2fs-dev] " Eric Biggers
2022-05-01 5:08 ` Eric Biggers [this message]
2022-05-01 5:08 ` [f2fs-dev] [PATCH v2 3/7] fscrypt: factor out fscrypt_policy_to_key_spec() Eric Biggers
2022-05-01 5:08 ` [PATCH v2 4/7] fscrypt: add new helper functions for test_dummy_encryption Eric Biggers
2022-05-01 5:08 ` [f2fs-dev] " Eric Biggers
2022-05-01 5:08 ` [PATCH v2 5/7] ext4: fix up test_dummy_encryption handling for new mount API Eric Biggers
2022-05-01 5:08 ` [f2fs-dev] " Eric Biggers
2022-05-09 23:40 ` Eric Biggers
2022-05-09 23:40 ` [f2fs-dev] " Eric Biggers
2022-05-11 17:54 ` Ritesh Harjani
2022-05-11 17:54 ` Ritesh Harjani
2022-05-11 18:03 ` Eric Biggers
2022-05-11 18:03 ` Eric Biggers
2022-05-13 10:58 ` Ritesh Harjani
2022-05-13 10:58 ` Ritesh Harjani
2022-05-13 22:24 ` Eric Biggers
2022-05-13 22:24 ` [f2fs-dev] " Eric Biggers
2022-05-13 11:07 ` Ritesh Harjani
2022-05-13 11:07 ` [f2fs-dev] " Ritesh Harjani
2022-05-13 21:59 ` Eric Biggers
2022-05-13 21:59 ` [f2fs-dev] " Eric Biggers
2022-05-01 5:08 ` [PATCH v2 6/7] f2fs: use the updated test_dummy_encryption helper functions Eric Biggers
2022-05-01 5:08 ` [f2fs-dev] " Eric Biggers
2022-05-01 5:08 ` [PATCH v2 7/7] fscrypt: remove fscrypt_set_test_dummy_encryption() Eric Biggers
2022-05-01 5:08 ` [f2fs-dev] " Eric Biggers
2022-05-09 23:36 ` [PATCH v2 0/7] test_dummy_encryption fixes and cleanups Eric Biggers
2022-05-09 23:36 ` [f2fs-dev] " Eric Biggers
2022-05-10 23:23 ` Jaegeuk Kim
2022-05-10 23:23 ` [f2fs-dev] " Jaegeuk Kim
2022-05-13 19:36 ` Theodore Ts'o
2022-05-13 19:36 ` [f2fs-dev] " Theodore Ts'o
2022-05-13 23:26 ` Eric Biggers
2022-05-13 23:26 ` [f2fs-dev] " 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=20220501050857.538984-4-ebiggers@kernel.org \
--to=ebiggers@kernel.org \
--cc=jaegeuk@kernel.org \
--cc=jlayton@kernel.org \
--cc=lczerner@redhat.com \
--cc=linux-ext4@vger.kernel.org \
--cc=linux-f2fs-devel@lists.sourceforge.net \
--cc=linux-fscrypt@vger.kernel.org \
--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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.