Skip to content

Commit 5970fba

Browse files
committed
fscrypt: make it clearer that key_prefix is deprecated
fscrypt_operations::key_prefix should not be set by any filesystems that aren't setting it already. This is already documented, but apparently it's not sufficiently clear, as both ceph and btrfs have tried to set it. Rename the field to legacy_key_prefix and improve the documentation to hopefully make it clearer. Link: https://lore.kernel.org/r/20230925055451.59499-2-ebiggers@kernel.org Signed-off-by: Eric Biggers <ebiggers@google.com>
1 parent 6465e26 commit 5970fba

5 files changed

Lines changed: 15 additions & 10 deletions

File tree

fs/crypto/keysetup_v1.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -299,15 +299,16 @@ int fscrypt_setup_v1_file_key(struct fscrypt_info *ci, const u8 *raw_master_key)
299299

300300
int fscrypt_setup_v1_file_key_via_subscribed_keyrings(struct fscrypt_info *ci)
301301
{
302+
const struct super_block *sb = ci->ci_inode->i_sb;
302303
struct key *key;
303304
const struct fscrypt_key *payload;
304305
int err;
305306

306307
key = find_and_lock_process_key(FSCRYPT_KEY_DESC_PREFIX,
307308
ci->ci_policy.v1.master_key_descriptor,
308309
ci->ci_mode->keysize, &payload);
309-
if (key == ERR_PTR(-ENOKEY) && ci->ci_inode->i_sb->s_cop->key_prefix) {
310-
key = find_and_lock_process_key(ci->ci_inode->i_sb->s_cop->key_prefix,
310+
if (key == ERR_PTR(-ENOKEY) && sb->s_cop->legacy_key_prefix) {
311+
key = find_and_lock_process_key(sb->s_cop->legacy_key_prefix,
311312
ci->ci_policy.v1.master_key_descriptor,
312313
ci->ci_mode->keysize, &payload);
313314
}

fs/ext4/crypto.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ static void ext4_get_ino_and_lblk_bits(struct super_block *sb,
240240
}
241241

242242
const struct fscrypt_operations ext4_cryptops = {
243-
.key_prefix = "ext4:",
243+
.legacy_key_prefix = "ext4:",
244244
.get_context = ext4_get_context,
245245
.set_context = ext4_set_context,
246246
.get_dummy_policy = ext4_get_dummy_policy,

fs/f2fs/super.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3231,7 +3231,7 @@ static struct block_device **f2fs_get_devices(struct super_block *sb,
32313231
}
32323232

32333233
static const struct fscrypt_operations f2fs_cryptops = {
3234-
.key_prefix = "f2fs:",
3234+
.legacy_key_prefix = "f2fs:",
32353235
.get_context = f2fs_get_context,
32363236
.set_context = f2fs_set_context,
32373237
.get_dummy_policy = f2fs_get_dummy_policy,

fs/ubifs/crypto.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ int ubifs_decrypt(const struct inode *inode, struct ubifs_data_node *dn,
8989

9090
const struct fscrypt_operations ubifs_crypt_operations = {
9191
.flags = FS_CFLG_OWN_PAGES,
92-
.key_prefix = "ubifs:",
92+
.legacy_key_prefix = "ubifs:",
9393
.get_context = ubifs_crypt_get_context,
9494
.set_context = ubifs_crypt_set_context,
9595
.empty_dir = ubifs_crypt_empty_dir,

include/linux/fscrypt.h

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,16 @@ struct fscrypt_operations {
7373
unsigned int flags;
7474

7575
/*
76-
* If set, this is a filesystem-specific key description prefix that
77-
* will be accepted for "logon" keys for v1 fscrypt policies, in
78-
* addition to the generic prefix "fscrypt:". This functionality is
79-
* deprecated, so new filesystems shouldn't set this field.
76+
* This field exists only for backwards compatibility reasons and should
77+
* only be set by the filesystems that are setting it already. It
78+
* contains the filesystem-specific key description prefix that is
79+
* accepted for "logon" keys for v1 fscrypt policies. This
80+
* functionality is deprecated in favor of the generic prefix
81+
* "fscrypt:", which itself is deprecated in favor of the filesystem
82+
* keyring ioctls such as FS_IOC_ADD_ENCRYPTION_KEY. Filesystems that
83+
* are newly adding fscrypt support should not set this field.
8084
*/
81-
const char *key_prefix;
85+
const char *legacy_key_prefix;
8286

8387
/*
8488
* Get the fscrypt context of the given inode.

0 commit comments

Comments
 (0)