Commit 886da8b3 authored by Eric Biggers's avatar Eric Biggers

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: default avatarEric Biggers <ebiggers@google.com>
parent 1c5100a2
...@@ -188,10 +188,8 @@ int fscrypt_crypt_block(const struct inode *inode, fscrypt_direction_t rw, ...@@ -188,10 +188,8 @@ int fscrypt_crypt_block(const struct inode *inode, fscrypt_direction_t rw,
res = crypto_wait_req(crypto_skcipher_encrypt(req), &wait); res = crypto_wait_req(crypto_skcipher_encrypt(req), &wait);
skcipher_request_free(req); skcipher_request_free(req);
if (res) { if (res) {
fscrypt_err(inode->i_sb, fscrypt_err(inode, "%scryption failed for block %llu: %d",
"%scryption failed for inode %lu, block %llu: %d", (rw == FS_DECRYPT ? "De" : "En"), lblk_num, res);
(rw == FS_DECRYPT ? "de" : "en"),
inode->i_ino, lblk_num, res);
return res; return res;
} }
return 0; return 0;
...@@ -453,7 +451,7 @@ int fscrypt_initialize(unsigned int cop_flags) ...@@ -453,7 +451,7 @@ int fscrypt_initialize(unsigned int cop_flags)
return res; return res;
} }
void fscrypt_msg(struct super_block *sb, const char *level, void fscrypt_msg(const struct inode *inode, const char *level,
const char *fmt, ...) const char *fmt, ...)
{ {
static DEFINE_RATELIMIT_STATE(rs, DEFAULT_RATELIMIT_INTERVAL, static DEFINE_RATELIMIT_STATE(rs, DEFAULT_RATELIMIT_INTERVAL,
...@@ -467,8 +465,9 @@ void fscrypt_msg(struct super_block *sb, const char *level, ...@@ -467,8 +465,9 @@ void fscrypt_msg(struct super_block *sb, const char *level,
va_start(args, fmt); va_start(args, fmt);
vaf.fmt = fmt; vaf.fmt = fmt;
vaf.va = &args; vaf.va = &args;
if (sb) if (inode)
printk("%sfscrypt (%s): %pV\n", level, sb->s_id, &vaf); printk("%sfscrypt (%s, inode %lu): %pV\n",
level, inode->i_sb->s_id, inode->i_ino, &vaf);
else else
printk("%sfscrypt: %pV\n", level, &vaf); printk("%sfscrypt: %pV\n", level, &vaf);
va_end(args); va_end(args);
......
...@@ -71,9 +71,7 @@ int fname_encrypt(struct inode *inode, const struct qstr *iname, ...@@ -71,9 +71,7 @@ int fname_encrypt(struct inode *inode, const struct qstr *iname,
res = crypto_wait_req(crypto_skcipher_encrypt(req), &wait); res = crypto_wait_req(crypto_skcipher_encrypt(req), &wait);
skcipher_request_free(req); skcipher_request_free(req);
if (res < 0) { if (res < 0) {
fscrypt_err(inode->i_sb, fscrypt_err(inode, "Filename encryption failed: %d", res);
"Filename encryption failed for inode %lu: %d",
inode->i_ino, res);
return res; return res;
} }
...@@ -117,9 +115,7 @@ static int fname_decrypt(struct inode *inode, ...@@ -117,9 +115,7 @@ static int fname_decrypt(struct inode *inode,
res = crypto_wait_req(crypto_skcipher_decrypt(req), &wait); res = crypto_wait_req(crypto_skcipher_decrypt(req), &wait);
skcipher_request_free(req); skcipher_request_free(req);
if (res < 0) { if (res < 0) {
fscrypt_err(inode->i_sb, fscrypt_err(inode, "Filename decryption failed: %d", res);
"Filename decryption failed for inode %lu: %d",
inode->i_ino, res);
return res; return res;
} }
......
...@@ -125,12 +125,12 @@ extern struct page *fscrypt_alloc_bounce_page(gfp_t gfp_flags); ...@@ -125,12 +125,12 @@ extern struct page *fscrypt_alloc_bounce_page(gfp_t gfp_flags);
extern const struct dentry_operations fscrypt_d_ops; extern const struct dentry_operations fscrypt_d_ops;
extern void __printf(3, 4) __cold extern void __printf(3, 4) __cold
fscrypt_msg(struct super_block *sb, const char *level, const char *fmt, ...); fscrypt_msg(const struct inode *inode, const char *level, const char *fmt, ...);
#define fscrypt_warn(sb, fmt, ...) \ #define fscrypt_warn(inode, fmt, ...) \
fscrypt_msg(sb, KERN_WARNING, fmt, ##__VA_ARGS__) fscrypt_msg((inode), KERN_WARNING, fmt, ##__VA_ARGS__)
#define fscrypt_err(sb, fmt, ...) \ #define fscrypt_err(inode, fmt, ...) \
fscrypt_msg(sb, KERN_ERR, fmt, ##__VA_ARGS__) fscrypt_msg((inode), KERN_ERR, fmt, ##__VA_ARGS__)
#define FSCRYPT_MAX_IV_SIZE 32 #define FSCRYPT_MAX_IV_SIZE 32
......
...@@ -39,9 +39,9 @@ int fscrypt_file_open(struct inode *inode, struct file *filp) ...@@ -39,9 +39,9 @@ int fscrypt_file_open(struct inode *inode, struct file *filp)
dir = dget_parent(file_dentry(filp)); dir = dget_parent(file_dentry(filp));
if (IS_ENCRYPTED(d_inode(dir)) && if (IS_ENCRYPTED(d_inode(dir)) &&
!fscrypt_has_permitted_context(d_inode(dir), inode)) { !fscrypt_has_permitted_context(d_inode(dir), inode)) {
fscrypt_warn(inode->i_sb, fscrypt_warn(inode,
"inconsistent encryption contexts: %lu/%lu", "Inconsistent encryption context (parent directory: %lu)",
d_inode(dir)->i_ino, inode->i_ino); d_inode(dir)->i_ino);
err = -EPERM; err = -EPERM;
} }
dput(dir); dput(dir);
......
...@@ -166,10 +166,9 @@ static struct fscrypt_mode * ...@@ -166,10 +166,9 @@ static struct fscrypt_mode *
select_encryption_mode(const struct fscrypt_info *ci, const struct inode *inode) select_encryption_mode(const struct fscrypt_info *ci, const struct inode *inode)
{ {
if (!fscrypt_valid_enc_modes(ci->ci_data_mode, ci->ci_filename_mode)) { if (!fscrypt_valid_enc_modes(ci->ci_data_mode, ci->ci_filename_mode)) {
fscrypt_warn(inode->i_sb, fscrypt_warn(inode,
"inode %lu uses unsupported encryption modes (contents mode %d, filenames mode %d)", "Unsupported encryption modes (contents mode %d, filenames mode %d)",
inode->i_ino, ci->ci_data_mode, ci->ci_data_mode, ci->ci_filename_mode);
ci->ci_filename_mode);
return ERR_PTR(-EINVAL); return ERR_PTR(-EINVAL);
} }
...@@ -206,14 +205,14 @@ static int find_and_derive_key(const struct inode *inode, ...@@ -206,14 +205,14 @@ static int find_and_derive_key(const struct inode *inode,
if (ctx->flags & FS_POLICY_FLAG_DIRECT_KEY) { if (ctx->flags & FS_POLICY_FLAG_DIRECT_KEY) {
if (mode->ivsize < offsetofend(union fscrypt_iv, nonce)) { if (mode->ivsize < offsetofend(union fscrypt_iv, nonce)) {
fscrypt_warn(inode->i_sb, fscrypt_warn(inode,
"direct key mode not allowed with %s", "Direct key mode not allowed with %s",
mode->friendly_name); mode->friendly_name);
err = -EINVAL; err = -EINVAL;
} else if (ctx->contents_encryption_mode != } else if (ctx->contents_encryption_mode !=
ctx->filenames_encryption_mode) { ctx->filenames_encryption_mode) {
fscrypt_warn(inode->i_sb, fscrypt_warn(inode,
"direct key mode not allowed with different contents and filenames modes"); "Direct key mode not allowed with different contents and filenames modes");
err = -EINVAL; err = -EINVAL;
} else { } else {
memcpy(derived_key, payload->raw, mode->keysize); memcpy(derived_key, payload->raw, mode->keysize);
...@@ -238,9 +237,8 @@ allocate_skcipher_for_mode(struct fscrypt_mode *mode, const u8 *raw_key, ...@@ -238,9 +237,8 @@ allocate_skcipher_for_mode(struct fscrypt_mode *mode, const u8 *raw_key,
tfm = crypto_alloc_skcipher(mode->cipher_str, 0, 0); tfm = crypto_alloc_skcipher(mode->cipher_str, 0, 0);
if (IS_ERR(tfm)) { if (IS_ERR(tfm)) {
fscrypt_warn(inode->i_sb, fscrypt_warn(inode, "Error allocating '%s' transform: %ld",
"error allocating '%s' transform for inode %lu: %ld", mode->cipher_str, PTR_ERR(tfm));
mode->cipher_str, inode->i_ino, PTR_ERR(tfm));
return tfm; return tfm;
} }
if (unlikely(!mode->logged_impl_name)) { if (unlikely(!mode->logged_impl_name)) {
...@@ -471,9 +469,9 @@ static int setup_crypto_transform(struct fscrypt_info *ci, ...@@ -471,9 +469,9 @@ static int setup_crypto_transform(struct fscrypt_info *ci,
err = init_essiv_generator(ci, raw_key, mode->keysize); err = init_essiv_generator(ci, raw_key, mode->keysize);
if (err) { if (err) {
fscrypt_warn(inode->i_sb, fscrypt_warn(inode,
"error initializing ESSIV generator for inode %lu: %d", "Error initializing ESSIV generator: %d",
inode->i_ino, err); err);
return err; return err;
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment