Skip to content

Commit 886da8b

Browse files
committed
fscrypt: make fscrypt_msg() take inode instead of super_block
Most of the warning and error messages in fs/crypto/ are for situations related to a specific inode, not merely to a super_block. So to make things easier, make fscrypt_msg() take an inode rather than a super_block, and make it print the inode number. Note: This is the same approach I'm taking for fsverity_msg(). Signed-off-by: Eric Biggers <ebiggers@google.com>
1 parent 1c5100a commit 886da8b

5 files changed

Lines changed: 28 additions & 35 deletions

File tree

‎fs/crypto/crypto.c‎

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -188,10 +188,8 @@ int fscrypt_crypt_block(const struct inode *inode, fscrypt_direction_t rw,
188188
res = crypto_wait_req(crypto_skcipher_encrypt(req), &wait);
189189
skcipher_request_free(req);
190190
if (res) {
191-
fscrypt_err(inode->i_sb,
192-
"%scryption failed for inode %lu, block %llu: %d",
193-
(rw == FS_DECRYPT ? "de" : "en"),
194-
inode->i_ino, lblk_num, res);
191+
fscrypt_err(inode, "%scryption failed for block %llu: %d",
192+
(rw == FS_DECRYPT ? "De" : "En"), lblk_num, res);
195193
return res;
196194
}
197195
return 0;
@@ -453,7 +451,7 @@ int fscrypt_initialize(unsigned int cop_flags)
453451
return res;
454452
}
455453

456-
void fscrypt_msg(struct super_block *sb, const char *level,
454+
void fscrypt_msg(const struct inode *inode, const char *level,
457455
const char *fmt, ...)
458456
{
459457
static DEFINE_RATELIMIT_STATE(rs, DEFAULT_RATELIMIT_INTERVAL,
@@ -467,8 +465,9 @@ void fscrypt_msg(struct super_block *sb, const char *level,
467465
va_start(args, fmt);
468466
vaf.fmt = fmt;
469467
vaf.va = &args;
470-
if (sb)
471-
printk("%sfscrypt (%s): %pV\n", level, sb->s_id, &vaf);
468+
if (inode)
469+
printk("%sfscrypt (%s, inode %lu): %pV\n",
470+
level, inode->i_sb->s_id, inode->i_ino, &vaf);
472471
else
473472
printk("%sfscrypt: %pV\n", level, &vaf);
474473
va_end(args);

‎fs/crypto/fname.c‎

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,7 @@ int fname_encrypt(struct inode *inode, const struct qstr *iname,
7171
res = crypto_wait_req(crypto_skcipher_encrypt(req), &wait);
7272
skcipher_request_free(req);
7373
if (res < 0) {
74-
fscrypt_err(inode->i_sb,
75-
"Filename encryption failed for inode %lu: %d",
76-
inode->i_ino, res);
74+
fscrypt_err(inode, "Filename encryption failed: %d", res);
7775
return res;
7876
}
7977

@@ -117,9 +115,7 @@ static int fname_decrypt(struct inode *inode,
117115
res = crypto_wait_req(crypto_skcipher_decrypt(req), &wait);
118116
skcipher_request_free(req);
119117
if (res < 0) {
120-
fscrypt_err(inode->i_sb,
121-
"Filename decryption failed for inode %lu: %d",
122-
inode->i_ino, res);
118+
fscrypt_err(inode, "Filename decryption failed: %d", res);
123119
return res;
124120
}
125121

‎fs/crypto/fscrypt_private.h‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -125,12 +125,12 @@ extern struct page *fscrypt_alloc_bounce_page(gfp_t gfp_flags);
125125
extern const struct dentry_operations fscrypt_d_ops;
126126

127127
extern void __printf(3, 4) __cold
128-
fscrypt_msg(struct super_block *sb, const char *level, const char *fmt, ...);
128+
fscrypt_msg(const struct inode *inode, const char *level, const char *fmt, ...);
129129

130-
#define fscrypt_warn(sb, fmt, ...) \
131-
fscrypt_msg(sb, KERN_WARNING, fmt, ##__VA_ARGS__)
132-
#define fscrypt_err(sb, fmt, ...) \
133-
fscrypt_msg(sb, KERN_ERR, fmt, ##__VA_ARGS__)
130+
#define fscrypt_warn(inode, fmt, ...) \
131+
fscrypt_msg((inode), KERN_WARNING, fmt, ##__VA_ARGS__)
132+
#define fscrypt_err(inode, fmt, ...) \
133+
fscrypt_msg((inode), KERN_ERR, fmt, ##__VA_ARGS__)
134134

135135
#define FSCRYPT_MAX_IV_SIZE 32
136136

‎fs/crypto/hooks.c‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@ int fscrypt_file_open(struct inode *inode, struct file *filp)
3939
dir = dget_parent(file_dentry(filp));
4040
if (IS_ENCRYPTED(d_inode(dir)) &&
4141
!fscrypt_has_permitted_context(d_inode(dir), inode)) {
42-
fscrypt_warn(inode->i_sb,
43-
"inconsistent encryption contexts: %lu/%lu",
44-
d_inode(dir)->i_ino, inode->i_ino);
42+
fscrypt_warn(inode,
43+
"Inconsistent encryption context (parent directory: %lu)",
44+
d_inode(dir)->i_ino);
4545
err = -EPERM;
4646
}
4747
dput(dir);

‎fs/crypto/keyinfo.c‎

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -166,10 +166,9 @@ static struct fscrypt_mode *
166166
select_encryption_mode(const struct fscrypt_info *ci, const struct inode *inode)
167167
{
168168
if (!fscrypt_valid_enc_modes(ci->ci_data_mode, ci->ci_filename_mode)) {
169-
fscrypt_warn(inode->i_sb,
170-
"inode %lu uses unsupported encryption modes (contents mode %d, filenames mode %d)",
171-
inode->i_ino, ci->ci_data_mode,
172-
ci->ci_filename_mode);
169+
fscrypt_warn(inode,
170+
"Unsupported encryption modes (contents mode %d, filenames mode %d)",
171+
ci->ci_data_mode, ci->ci_filename_mode);
173172
return ERR_PTR(-EINVAL);
174173
}
175174

@@ -206,14 +205,14 @@ static int find_and_derive_key(const struct inode *inode,
206205

207206
if (ctx->flags & FS_POLICY_FLAG_DIRECT_KEY) {
208207
if (mode->ivsize < offsetofend(union fscrypt_iv, nonce)) {
209-
fscrypt_warn(inode->i_sb,
210-
"direct key mode not allowed with %s",
208+
fscrypt_warn(inode,
209+
"Direct key mode not allowed with %s",
211210
mode->friendly_name);
212211
err = -EINVAL;
213212
} else if (ctx->contents_encryption_mode !=
214213
ctx->filenames_encryption_mode) {
215-
fscrypt_warn(inode->i_sb,
216-
"direct key mode not allowed with different contents and filenames modes");
214+
fscrypt_warn(inode,
215+
"Direct key mode not allowed with different contents and filenames modes");
217216
err = -EINVAL;
218217
} else {
219218
memcpy(derived_key, payload->raw, mode->keysize);
@@ -238,9 +237,8 @@ allocate_skcipher_for_mode(struct fscrypt_mode *mode, const u8 *raw_key,
238237

239238
tfm = crypto_alloc_skcipher(mode->cipher_str, 0, 0);
240239
if (IS_ERR(tfm)) {
241-
fscrypt_warn(inode->i_sb,
242-
"error allocating '%s' transform for inode %lu: %ld",
243-
mode->cipher_str, inode->i_ino, PTR_ERR(tfm));
240+
fscrypt_warn(inode, "Error allocating '%s' transform: %ld",
241+
mode->cipher_str, PTR_ERR(tfm));
244242
return tfm;
245243
}
246244
if (unlikely(!mode->logged_impl_name)) {
@@ -471,9 +469,9 @@ static int setup_crypto_transform(struct fscrypt_info *ci,
471469

472470
err = init_essiv_generator(ci, raw_key, mode->keysize);
473471
if (err) {
474-
fscrypt_warn(inode->i_sb,
475-
"error initializing ESSIV generator for inode %lu: %d",
476-
inode->i_ino, err);
472+
fscrypt_warn(inode,
473+
"Error initializing ESSIV generator: %d",
474+
err);
477475
return err;
478476
}
479477
}

0 commit comments

Comments
 (0)