Skip to content

Commit 41b2ad8

Browse files
committed
fscrypt: use WARN_ON_ONCE instead of WARN_ON
As per Linus's suggestion (https://lore.kernel.org/r/CAHk-=whefxRGyNGzCzG6BVeM=5vnvgb-XhSeFJVxJyAxAF8XRA@mail.gmail.com), use WARN_ON_ONCE instead of WARN_ON. This barely adds any extra overhead, and it makes it so that if any of these ever becomes reachable (they shouldn't, but that's the point), the logs can't be flooded. Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Eric Biggers <[email protected]>
1 parent 6f2656e commit 41b2ad8

File tree

8 files changed

+25
-25
lines changed

8 files changed

+25
-25
lines changed

fs/crypto/bio.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ static int fscrypt_zeroout_range_inline_crypt(const struct inode *inode,
6969
pblk << (blockbits - SECTOR_SHIFT);
7070
}
7171
ret = bio_add_page(bio, ZERO_PAGE(0), bytes_this_page, 0);
72-
if (WARN_ON(ret != bytes_this_page)) {
72+
if (WARN_ON_ONCE(ret != bytes_this_page)) {
7373
err = -EIO;
7474
goto out;
7575
}
@@ -147,7 +147,7 @@ int fscrypt_zeroout_range(const struct inode *inode, pgoff_t lblk,
147147
break;
148148
}
149149
nr_pages = i;
150-
if (WARN_ON(nr_pages <= 0))
150+
if (WARN_ON_ONCE(nr_pages <= 0))
151151
return -EINVAL;
152152

153153
/* This always succeeds since __GFP_DIRECT_RECLAIM is set. */
@@ -170,7 +170,7 @@ int fscrypt_zeroout_range(const struct inode *inode, pgoff_t lblk,
170170
offset += blocksize;
171171
if (offset == PAGE_SIZE || len == 0) {
172172
ret = bio_add_page(bio, pages[i++], offset, 0);
173-
if (WARN_ON(ret != offset)) {
173+
if (WARN_ON_ONCE(ret != offset)) {
174174
err = -EIO;
175175
goto out;
176176
}

fs/crypto/fname.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ int fscrypt_fname_encrypt(const struct inode *inode, const struct qstr *iname,
110110
* Copy the filename to the output buffer for encrypting in-place and
111111
* pad it with the needed number of NUL bytes.
112112
*/
113-
if (WARN_ON(olen < iname->len))
113+
if (WARN_ON_ONCE(olen < iname->len))
114114
return -ENOBUFS;
115115
memcpy(out, iname->name, iname->len);
116116
memset(out + iname->len, 0, olen - iname->len);
@@ -570,7 +570,7 @@ u64 fscrypt_fname_siphash(const struct inode *dir, const struct qstr *name)
570570
{
571571
const struct fscrypt_info *ci = dir->i_crypt_info;
572572

573-
WARN_ON(!ci->ci_dirhash_key_initialized);
573+
WARN_ON_ONCE(!ci->ci_dirhash_key_initialized);
574574

575575
return siphash(name->name, name->len, &ci->ci_dirhash_key);
576576
}

fs/crypto/fscrypt_private.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ static inline const u8 *fscrypt_context_nonce(const union fscrypt_context *ctx)
101101
case FSCRYPT_CONTEXT_V2:
102102
return ctx->v2.nonce;
103103
}
104-
WARN_ON(1);
104+
WARN_ON_ONCE(1);
105105
return NULL;
106106
}
107107

@@ -386,7 +386,7 @@ fscrypt_prepare_inline_crypt_key(struct fscrypt_prepared_key *prep_key,
386386
const u8 *raw_key,
387387
const struct fscrypt_info *ci)
388388
{
389-
WARN_ON(1);
389+
WARN_ON_ONCE(1);
390390
return -EOPNOTSUPP;
391391
}
392392

fs/crypto/hkdf.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ int fscrypt_init_hkdf(struct fscrypt_hkdf *hkdf, const u8 *master_key,
7979
return PTR_ERR(hmac_tfm);
8080
}
8181

82-
if (WARN_ON(crypto_shash_digestsize(hmac_tfm) != sizeof(prk))) {
82+
if (WARN_ON_ONCE(crypto_shash_digestsize(hmac_tfm) != sizeof(prk))) {
8383
err = -EINVAL;
8484
goto err_free_tfm;
8585
}
@@ -125,7 +125,7 @@ int fscrypt_hkdf_expand(const struct fscrypt_hkdf *hkdf, u8 context,
125125
u8 counter = 1;
126126
u8 tmp[HKDF_HASHLEN];
127127

128-
if (WARN_ON(okmlen > 255 * HKDF_HASHLEN))
128+
if (WARN_ON_ONCE(okmlen > 255 * HKDF_HASHLEN))
129129
return -EINVAL;
130130

131131
desc->tfm = hkdf->hmac_tfm;

fs/crypto/hooks.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@ const char *fscrypt_get_symlink(struct inode *inode, const void *caddr,
345345
int err;
346346

347347
/* This is for encrypted symlinks only */
348-
if (WARN_ON(!IS_ENCRYPTED(inode)))
348+
if (WARN_ON_ONCE(!IS_ENCRYPTED(inode)))
349349
return ERR_PTR(-EINVAL);
350350

351351
/* If the decrypted target is already cached, just return it. */

fs/crypto/keyring.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ void fscrypt_put_master_key(struct fscrypt_master_key *mk)
7373
* fscrypt_master_key struct itself after an RCU grace period ensures
7474
* that concurrent keyring lookups can no longer find it.
7575
*/
76-
WARN_ON(refcount_read(&mk->mk_active_refs) != 0);
76+
WARN_ON_ONCE(refcount_read(&mk->mk_active_refs) != 0);
7777
key_put(mk->mk_users);
7878
mk->mk_users = NULL;
7979
call_rcu(&mk->mk_rcu_head, fscrypt_free_master_key);
@@ -92,7 +92,7 @@ void fscrypt_put_master_key_activeref(struct super_block *sb,
9292
* destroying any subkeys embedded in it.
9393
*/
9494

95-
if (WARN_ON(!sb->s_master_keys))
95+
if (WARN_ON_ONCE(!sb->s_master_keys))
9696
return;
9797
spin_lock(&sb->s_master_keys->lock);
9898
hlist_del_rcu(&mk->mk_node);
@@ -102,8 +102,8 @@ void fscrypt_put_master_key_activeref(struct super_block *sb,
102102
* ->mk_active_refs == 0 implies that ->mk_secret is not present and
103103
* that ->mk_decrypted_inodes is empty.
104104
*/
105-
WARN_ON(is_master_key_secret_present(&mk->mk_secret));
106-
WARN_ON(!list_empty(&mk->mk_decrypted_inodes));
105+
WARN_ON_ONCE(is_master_key_secret_present(&mk->mk_secret));
106+
WARN_ON_ONCE(!list_empty(&mk->mk_decrypted_inodes));
107107

108108
for (i = 0; i <= FSCRYPT_MODE_MAX; i++) {
109109
fscrypt_destroy_prepared_key(
@@ -237,9 +237,9 @@ void fscrypt_destroy_keyring(struct super_block *sb)
237237
* with ->mk_secret. There should be no structural refs
238238
* beyond the one associated with the active ref.
239239
*/
240-
WARN_ON(refcount_read(&mk->mk_active_refs) != 1);
241-
WARN_ON(refcount_read(&mk->mk_struct_refs) != 1);
242-
WARN_ON(!is_master_key_secret_present(&mk->mk_secret));
240+
WARN_ON_ONCE(refcount_read(&mk->mk_active_refs) != 1);
241+
WARN_ON_ONCE(refcount_read(&mk->mk_struct_refs) != 1);
242+
WARN_ON_ONCE(!is_master_key_secret_present(&mk->mk_secret));
243243
wipe_master_key_secret(&mk->mk_secret);
244244
fscrypt_put_master_key_activeref(sb, mk);
245245
}

fs/crypto/keysetup.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ fscrypt_allocate_skcipher(struct fscrypt_mode *mode, const u8 *raw_key,
125125
pr_info("fscrypt: %s using implementation \"%s\"\n",
126126
mode->friendly_name, crypto_skcipher_driver_name(tfm));
127127
}
128-
if (WARN_ON(crypto_skcipher_ivsize(tfm) != mode->ivsize)) {
128+
if (WARN_ON_ONCE(crypto_skcipher_ivsize(tfm) != mode->ivsize)) {
129129
err = -EINVAL;
130130
goto err_free_tfm;
131131
}
@@ -199,7 +199,7 @@ static int setup_per_mode_enc_key(struct fscrypt_info *ci,
199199
unsigned int hkdf_infolen = 0;
200200
int err;
201201

202-
if (WARN_ON(mode_num > FSCRYPT_MODE_MAX))
202+
if (WARN_ON_ONCE(mode_num > FSCRYPT_MODE_MAX))
203203
return -EINVAL;
204204

205205
prep_key = &keys[mode_num];
@@ -282,8 +282,8 @@ int fscrypt_derive_dirhash_key(struct fscrypt_info *ci,
282282
void fscrypt_hash_inode_number(struct fscrypt_info *ci,
283283
const struct fscrypt_master_key *mk)
284284
{
285-
WARN_ON(ci->ci_inode->i_ino == 0);
286-
WARN_ON(!mk->mk_ino_hash_key_initialized);
285+
WARN_ON_ONCE(ci->ci_inode->i_ino == 0);
286+
WARN_ON_ONCE(!mk->mk_ino_hash_key_initialized);
287287

288288
ci->ci_hashed_ino = (u32)siphash_1u64(ci->ci_inode->i_ino,
289289
&mk->mk_ino_hash_key);
@@ -503,7 +503,7 @@ static int setup_file_encryption_key(struct fscrypt_info *ci,
503503
err = fscrypt_setup_v2_file_key(ci, mk, need_dirhash_key);
504504
break;
505505
default:
506-
WARN_ON(1);
506+
WARN_ON_ONCE(1);
507507
err = -EINVAL;
508508
break;
509509
}
@@ -577,7 +577,7 @@ fscrypt_setup_encryption_info(struct inode *inode,
577577
res = PTR_ERR(mode);
578578
goto out;
579579
}
580-
WARN_ON(mode->ivsize > FSCRYPT_MAX_IV_SIZE);
580+
WARN_ON_ONCE(mode->ivsize > FSCRYPT_MAX_IV_SIZE);
581581
crypt_info->ci_mode = mode;
582582

583583
res = setup_file_encryption_key(crypt_info, need_dirhash_key, &mk);

fs/crypto/policy.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ int fscrypt_policy_to_key_spec(const union fscrypt_policy *policy,
4848
FSCRYPT_KEY_IDENTIFIER_SIZE);
4949
return 0;
5050
default:
51-
WARN_ON(1);
51+
WARN_ON_ONCE(1);
5252
return -EINVAL;
5353
}
5454
}
@@ -463,7 +463,7 @@ static int set_encryption_policy(struct inode *inode,
463463
current->comm, current->pid);
464464
break;
465465
default:
466-
WARN_ON(1);
466+
WARN_ON_ONCE(1);
467467
return -EINVAL;
468468
}
469469

0 commit comments

Comments
 (0)