Skip to content

Commit 3b6df59

Browse files
committed
fscrypt: use FSCRYPT_* definitions, not FS_*
Update fs/crypto/ to use the new names for the UAPI constants rather than the old names, then make the old definitions conditional on !__KERNEL__. Reviewed-by: Theodore Ts'o <tytso@mit.edu> Signed-off-by: Eric Biggers <ebiggers@google.com>
1 parent 2336d0d commit 3b6df59

6 files changed

Lines changed: 46 additions & 43 deletions

File tree

‎fs/crypto/crypto.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ void fscrypt_generate_iv(union fscrypt_iv *iv, u64 lblk_num,
141141
memset(iv, 0, ci->ci_mode->ivsize);
142142
iv->lblk_num = cpu_to_le64(lblk_num);
143143

144-
if (ci->ci_flags & FS_POLICY_FLAG_DIRECT_KEY)
144+
if (ci->ci_flags & FSCRYPT_POLICY_FLAG_DIRECT_KEY)
145145
memcpy(iv->nonce, ci->ci_nonce, FS_KEY_DERIVATION_NONCE_SIZE);
146146

147147
if (ci->ci_essiv_tfm != NULL)

‎fs/crypto/fname.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ bool fscrypt_fname_encrypted_size(const struct inode *inode, u32 orig_len,
182182
u32 max_len, u32 *encrypted_len_ret)
183183
{
184184
int padding = 4 << (inode->i_crypt_info->ci_flags &
185-
FS_POLICY_FLAGS_PAD_MASK);
185+
FSCRYPT_POLICY_FLAGS_PAD_MASK);
186186
u32 encrypted_len;
187187

188188
if (orig_len > max_len)

‎fs/crypto/fscrypt_private.h‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ struct fscrypt_context {
3434
u8 contents_encryption_mode;
3535
u8 filenames_encryption_mode;
3636
u8 flags;
37-
u8 master_key_descriptor[FS_KEY_DESCRIPTOR_SIZE];
37+
u8 master_key_descriptor[FSCRYPT_KEY_DESCRIPTOR_SIZE];
3838
u8 nonce[FS_KEY_DERIVATION_NONCE_SIZE];
3939
} __packed;
4040

@@ -84,7 +84,7 @@ struct fscrypt_info {
8484
u8 ci_data_mode;
8585
u8 ci_filename_mode;
8686
u8 ci_flags;
87-
u8 ci_master_key_descriptor[FS_KEY_DESCRIPTOR_SIZE];
87+
u8 ci_master_key_descriptor[FSCRYPT_KEY_DESCRIPTOR_SIZE];
8888
u8 ci_nonce[FS_KEY_DERIVATION_NONCE_SIZE];
8989
};
9090

@@ -98,16 +98,16 @@ typedef enum {
9898
static inline bool fscrypt_valid_enc_modes(u32 contents_mode,
9999
u32 filenames_mode)
100100
{
101-
if (contents_mode == FS_ENCRYPTION_MODE_AES_128_CBC &&
102-
filenames_mode == FS_ENCRYPTION_MODE_AES_128_CTS)
101+
if (contents_mode == FSCRYPT_MODE_AES_128_CBC &&
102+
filenames_mode == FSCRYPT_MODE_AES_128_CTS)
103103
return true;
104104

105-
if (contents_mode == FS_ENCRYPTION_MODE_AES_256_XTS &&
106-
filenames_mode == FS_ENCRYPTION_MODE_AES_256_CTS)
105+
if (contents_mode == FSCRYPT_MODE_AES_256_XTS &&
106+
filenames_mode == FSCRYPT_MODE_AES_256_CTS)
107107
return true;
108108

109-
if (contents_mode == FS_ENCRYPTION_MODE_ADIANTUM &&
110-
filenames_mode == FS_ENCRYPTION_MODE_ADIANTUM)
109+
if (contents_mode == FSCRYPT_MODE_ADIANTUM &&
110+
filenames_mode == FSCRYPT_MODE_ADIANTUM)
111111
return true;
112112

113113
return false;

‎fs/crypto/keyinfo.c‎

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
static struct crypto_shash *essiv_hash_tfm;
2222

23-
/* Table of keys referenced by FS_POLICY_FLAG_DIRECT_KEY policies */
23+
/* Table of keys referenced by DIRECT_KEY policies */
2424
static DEFINE_HASHTABLE(fscrypt_master_keys, 6); /* 6 bits = 64 buckets */
2525
static DEFINE_SPINLOCK(fscrypt_master_keys_lock);
2626

@@ -77,7 +77,7 @@ static int derive_key_aes(const u8 *master_key,
7777
*/
7878
static struct key *
7979
find_and_lock_process_key(const char *prefix,
80-
const u8 descriptor[FS_KEY_DESCRIPTOR_SIZE],
80+
const u8 descriptor[FSCRYPT_KEY_DESCRIPTOR_SIZE],
8181
unsigned int min_keysize,
8282
const struct fscrypt_key **payload_ret)
8383
{
@@ -87,7 +87,7 @@ find_and_lock_process_key(const char *prefix,
8787
const struct fscrypt_key *payload;
8888

8989
description = kasprintf(GFP_NOFS, "%s%*phN", prefix,
90-
FS_KEY_DESCRIPTOR_SIZE, descriptor);
90+
FSCRYPT_KEY_DESCRIPTOR_SIZE, descriptor);
9191
if (!description)
9292
return ERR_PTR(-ENOMEM);
9393

@@ -105,7 +105,7 @@ find_and_lock_process_key(const char *prefix,
105105
payload = (const struct fscrypt_key *)ukp->data;
106106

107107
if (ukp->datalen != sizeof(struct fscrypt_key) ||
108-
payload->size < 1 || payload->size > FS_MAX_KEY_SIZE) {
108+
payload->size < 1 || payload->size > FSCRYPT_MAX_KEY_SIZE) {
109109
fscrypt_warn(NULL,
110110
"key with description '%s' has invalid payload",
111111
key->description);
@@ -129,32 +129,32 @@ find_and_lock_process_key(const char *prefix,
129129
}
130130

131131
static struct fscrypt_mode available_modes[] = {
132-
[FS_ENCRYPTION_MODE_AES_256_XTS] = {
132+
[FSCRYPT_MODE_AES_256_XTS] = {
133133
.friendly_name = "AES-256-XTS",
134134
.cipher_str = "xts(aes)",
135135
.keysize = 64,
136136
.ivsize = 16,
137137
},
138-
[FS_ENCRYPTION_MODE_AES_256_CTS] = {
138+
[FSCRYPT_MODE_AES_256_CTS] = {
139139
.friendly_name = "AES-256-CTS-CBC",
140140
.cipher_str = "cts(cbc(aes))",
141141
.keysize = 32,
142142
.ivsize = 16,
143143
},
144-
[FS_ENCRYPTION_MODE_AES_128_CBC] = {
144+
[FSCRYPT_MODE_AES_128_CBC] = {
145145
.friendly_name = "AES-128-CBC",
146146
.cipher_str = "cbc(aes)",
147147
.keysize = 16,
148148
.ivsize = 16,
149149
.needs_essiv = true,
150150
},
151-
[FS_ENCRYPTION_MODE_AES_128_CTS] = {
151+
[FSCRYPT_MODE_AES_128_CTS] = {
152152
.friendly_name = "AES-128-CTS-CBC",
153153
.cipher_str = "cts(cbc(aes))",
154154
.keysize = 16,
155155
.ivsize = 16,
156156
},
157-
[FS_ENCRYPTION_MODE_ADIANTUM] = {
157+
[FSCRYPT_MODE_ADIANTUM] = {
158158
.friendly_name = "Adiantum",
159159
.cipher_str = "adiantum(xchacha12,aes)",
160160
.keysize = 32,
@@ -192,7 +192,7 @@ static int find_and_derive_key(const struct inode *inode,
192192
const struct fscrypt_key *payload;
193193
int err;
194194

195-
key = find_and_lock_process_key(FS_KEY_DESC_PREFIX,
195+
key = find_and_lock_process_key(FSCRYPT_KEY_DESC_PREFIX,
196196
ctx->master_key_descriptor,
197197
mode->keysize, &payload);
198198
if (key == ERR_PTR(-ENOKEY) && inode->i_sb->s_cop->key_prefix) {
@@ -203,7 +203,7 @@ static int find_and_derive_key(const struct inode *inode,
203203
if (IS_ERR(key))
204204
return PTR_ERR(key);
205205

206-
if (ctx->flags & FS_POLICY_FLAG_DIRECT_KEY) {
206+
if (ctx->flags & FSCRYPT_POLICY_FLAG_DIRECT_KEY) {
207207
if (mode->ivsize < offsetofend(union fscrypt_iv, nonce)) {
208208
fscrypt_warn(inode,
209209
"Direct key mode not allowed with %s",
@@ -272,14 +272,14 @@ allocate_skcipher_for_mode(struct fscrypt_mode *mode, const u8 *raw_key,
272272
return ERR_PTR(err);
273273
}
274274

275-
/* Master key referenced by FS_POLICY_FLAG_DIRECT_KEY policy */
275+
/* Master key referenced by DIRECT_KEY policy */
276276
struct fscrypt_master_key {
277277
struct hlist_node mk_node;
278278
refcount_t mk_refcount;
279279
const struct fscrypt_mode *mk_mode;
280280
struct crypto_skcipher *mk_ctfm;
281-
u8 mk_descriptor[FS_KEY_DESCRIPTOR_SIZE];
282-
u8 mk_raw[FS_MAX_KEY_SIZE];
281+
u8 mk_descriptor[FSCRYPT_KEY_DESCRIPTOR_SIZE];
282+
u8 mk_raw[FSCRYPT_MAX_KEY_SIZE];
283283
};
284284

285285
static void free_master_key(struct fscrypt_master_key *mk)
@@ -320,13 +320,13 @@ find_or_insert_master_key(struct fscrypt_master_key *to_insert,
320320
* raw key, and use crypto_memneq() when comparing raw keys.
321321
*/
322322

323-
BUILD_BUG_ON(sizeof(hash_key) > FS_KEY_DESCRIPTOR_SIZE);
323+
BUILD_BUG_ON(sizeof(hash_key) > FSCRYPT_KEY_DESCRIPTOR_SIZE);
324324
memcpy(&hash_key, ci->ci_master_key_descriptor, sizeof(hash_key));
325325

326326
spin_lock(&fscrypt_master_keys_lock);
327327
hash_for_each_possible(fscrypt_master_keys, mk, mk_node, hash_key) {
328328
if (memcmp(ci->ci_master_key_descriptor, mk->mk_descriptor,
329-
FS_KEY_DESCRIPTOR_SIZE) != 0)
329+
FSCRYPT_KEY_DESCRIPTOR_SIZE) != 0)
330330
continue;
331331
if (mode != mk->mk_mode)
332332
continue;
@@ -370,7 +370,7 @@ fscrypt_get_master_key(const struct fscrypt_info *ci, struct fscrypt_mode *mode,
370370
goto err_free_mk;
371371
}
372372
memcpy(mk->mk_descriptor, ci->ci_master_key_descriptor,
373-
FS_KEY_DESCRIPTOR_SIZE);
373+
FSCRYPT_KEY_DESCRIPTOR_SIZE);
374374
memcpy(mk->mk_raw, raw_key, mode->keysize);
375375

376376
return find_or_insert_master_key(mk, raw_key, mode, ci);
@@ -448,8 +448,8 @@ static int init_essiv_generator(struct fscrypt_info *ci, const u8 *raw_key,
448448

449449
/*
450450
* Given the encryption mode and key (normally the derived key, but for
451-
* FS_POLICY_FLAG_DIRECT_KEY mode it's the master key), set up the inode's
452-
* symmetric cipher transform object(s).
451+
* DIRECT_KEY mode it's the master key), set up the inode's symmetric cipher
452+
* transform object(s).
453453
*/
454454
static int setup_crypto_transform(struct fscrypt_info *ci,
455455
struct fscrypt_mode *mode,
@@ -459,7 +459,7 @@ static int setup_crypto_transform(struct fscrypt_info *ci,
459459
struct crypto_skcipher *ctfm;
460460
int err;
461461

462-
if (ci->ci_flags & FS_POLICY_FLAG_DIRECT_KEY) {
462+
if (ci->ci_flags & FSCRYPT_POLICY_FLAG_DIRECT_KEY) {
463463
mk = fscrypt_get_master_key(ci, mode, raw_key, inode);
464464
if (IS_ERR(mk))
465465
return PTR_ERR(mk);
@@ -476,7 +476,7 @@ static int setup_crypto_transform(struct fscrypt_info *ci,
476476
if (mode->needs_essiv) {
477477
/* ESSIV implies 16-byte IVs which implies !DIRECT_KEY */
478478
WARN_ON(mode->ivsize != AES_BLOCK_SIZE);
479-
WARN_ON(ci->ci_flags & FS_POLICY_FLAG_DIRECT_KEY);
479+
WARN_ON(ci->ci_flags & FSCRYPT_POLICY_FLAG_DIRECT_KEY);
480480

481481
err = init_essiv_generator(ci, raw_key, mode->keysize);
482482
if (err) {
@@ -530,9 +530,10 @@ int fscrypt_get_encryption_info(struct inode *inode)
530530
/* Fake up a context for an unencrypted directory */
531531
memset(&ctx, 0, sizeof(ctx));
532532
ctx.format = FS_ENCRYPTION_CONTEXT_FORMAT_V1;
533-
ctx.contents_encryption_mode = FS_ENCRYPTION_MODE_AES_256_XTS;
534-
ctx.filenames_encryption_mode = FS_ENCRYPTION_MODE_AES_256_CTS;
535-
memset(ctx.master_key_descriptor, 0x42, FS_KEY_DESCRIPTOR_SIZE);
533+
ctx.contents_encryption_mode = FSCRYPT_MODE_AES_256_XTS;
534+
ctx.filenames_encryption_mode = FSCRYPT_MODE_AES_256_CTS;
535+
memset(ctx.master_key_descriptor, 0x42,
536+
FSCRYPT_KEY_DESCRIPTOR_SIZE);
536537
} else if (res != sizeof(ctx)) {
537538
fscrypt_warn(inode,
538539
"Unknown encryption context size (%d bytes)", res);
@@ -545,7 +546,7 @@ int fscrypt_get_encryption_info(struct inode *inode)
545546
return -EINVAL;
546547
}
547548

548-
if (ctx.flags & ~FS_POLICY_FLAGS_VALID) {
549+
if (ctx.flags & ~FSCRYPT_POLICY_FLAGS_VALID) {
549550
fscrypt_warn(inode, "Unknown encryption context flags (0x%02x)",
550551
ctx.flags);
551552
return -EINVAL;
@@ -559,7 +560,7 @@ int fscrypt_get_encryption_info(struct inode *inode)
559560
crypt_info->ci_data_mode = ctx.contents_encryption_mode;
560561
crypt_info->ci_filename_mode = ctx.filenames_encryption_mode;
561562
memcpy(crypt_info->ci_master_key_descriptor, ctx.master_key_descriptor,
562-
FS_KEY_DESCRIPTOR_SIZE);
563+
FSCRYPT_KEY_DESCRIPTOR_SIZE);
563564
memcpy(crypt_info->ci_nonce, ctx.nonce, FS_KEY_DERIVATION_NONCE_SIZE);
564565

565566
mode = select_encryption_mode(crypt_info, inode);

‎fs/crypto/policy.c‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ static bool is_encryption_context_consistent_with_policy(
2222
const struct fscrypt_policy *policy)
2323
{
2424
return memcmp(ctx->master_key_descriptor, policy->master_key_descriptor,
25-
FS_KEY_DESCRIPTOR_SIZE) == 0 &&
25+
FSCRYPT_KEY_DESCRIPTOR_SIZE) == 0 &&
2626
(ctx->flags == policy->flags) &&
2727
(ctx->contents_encryption_mode ==
2828
policy->contents_encryption_mode) &&
@@ -37,13 +37,13 @@ static int create_encryption_context_from_policy(struct inode *inode,
3737

3838
ctx.format = FS_ENCRYPTION_CONTEXT_FORMAT_V1;
3939
memcpy(ctx.master_key_descriptor, policy->master_key_descriptor,
40-
FS_KEY_DESCRIPTOR_SIZE);
40+
FSCRYPT_KEY_DESCRIPTOR_SIZE);
4141

4242
if (!fscrypt_valid_enc_modes(policy->contents_encryption_mode,
4343
policy->filenames_encryption_mode))
4444
return -EINVAL;
4545

46-
if (policy->flags & ~FS_POLICY_FLAGS_VALID)
46+
if (policy->flags & ~FSCRYPT_POLICY_FLAGS_VALID)
4747
return -EINVAL;
4848

4949
ctx.contents_encryption_mode = policy->contents_encryption_mode;
@@ -128,7 +128,7 @@ int fscrypt_ioctl_get_policy(struct file *filp, void __user *arg)
128128
policy.filenames_encryption_mode = ctx.filenames_encryption_mode;
129129
policy.flags = ctx.flags;
130130
memcpy(policy.master_key_descriptor, ctx.master_key_descriptor,
131-
FS_KEY_DESCRIPTOR_SIZE);
131+
FSCRYPT_KEY_DESCRIPTOR_SIZE);
132132

133133
if (copy_to_user(arg, &policy, sizeof(policy)))
134134
return -EFAULT;
@@ -202,7 +202,7 @@ int fscrypt_has_permitted_context(struct inode *parent, struct inode *child)
202202
if (parent_ci && child_ci) {
203203
return memcmp(parent_ci->ci_master_key_descriptor,
204204
child_ci->ci_master_key_descriptor,
205-
FS_KEY_DESCRIPTOR_SIZE) == 0 &&
205+
FSCRYPT_KEY_DESCRIPTOR_SIZE) == 0 &&
206206
(parent_ci->ci_data_mode == child_ci->ci_data_mode) &&
207207
(parent_ci->ci_filename_mode ==
208208
child_ci->ci_filename_mode) &&
@@ -219,7 +219,7 @@ int fscrypt_has_permitted_context(struct inode *parent, struct inode *child)
219219

220220
return memcmp(parent_ctx.master_key_descriptor,
221221
child_ctx.master_key_descriptor,
222-
FS_KEY_DESCRIPTOR_SIZE) == 0 &&
222+
FSCRYPT_KEY_DESCRIPTOR_SIZE) == 0 &&
223223
(parent_ctx.contents_encryption_mode ==
224224
child_ctx.contents_encryption_mode) &&
225225
(parent_ctx.filenames_encryption_mode ==
@@ -257,7 +257,7 @@ int fscrypt_inherit_context(struct inode *parent, struct inode *child,
257257
ctx.filenames_encryption_mode = ci->ci_filename_mode;
258258
ctx.flags = ci->ci_flags;
259259
memcpy(ctx.master_key_descriptor, ci->ci_master_key_descriptor,
260-
FS_KEY_DESCRIPTOR_SIZE);
260+
FSCRYPT_KEY_DESCRIPTOR_SIZE);
261261
get_random_bytes(ctx.nonce, FS_KEY_DERIVATION_NONCE_SIZE);
262262
BUILD_BUG_ON(sizeof(ctx) != FSCRYPT_SET_CONTEXT_MAX_SIZE);
263263
res = parent->i_sb->s_cop->set_context(child, &ctx,

‎include/uapi/linux/fscrypt.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ struct fscrypt_key {
5555
/**********************************************************************/
5656

5757
/* old names; don't add anything new here! */
58+
#ifndef __KERNEL__
5859
#define FS_KEY_DESCRIPTOR_SIZE FSCRYPT_KEY_DESCRIPTOR_SIZE
5960
#define FS_POLICY_FLAGS_PAD_4 FSCRYPT_POLICY_FLAGS_PAD_4
6061
#define FS_POLICY_FLAGS_PAD_8 FSCRYPT_POLICY_FLAGS_PAD_8
@@ -76,5 +77,6 @@ struct fscrypt_key {
7677
#define FS_KEY_DESC_PREFIX FSCRYPT_KEY_DESC_PREFIX
7778
#define FS_KEY_DESC_PREFIX_SIZE FSCRYPT_KEY_DESC_PREFIX_SIZE
7879
#define FS_MAX_KEY_SIZE FSCRYPT_MAX_KEY_SIZE
80+
#endif /* !__KERNEL__ */
7981

8082
#endif /* _UAPI_LINUX_FSCRYPT_H */

0 commit comments

Comments
 (0)