Skip to content

Commit 4db9f11

Browse files
Jaegeuk Kimgregkh
authored andcommitted
f2fs crypto: replace some BUG_ON()'s with error checks
commit 66aa3e1274fcf887e9d6501a68163270fc7718e7 upstream. This patch adopts: ext4 crypto: replace some BUG_ON()'s with error checks Signed-off-by: Theodore Ts'o <tytso@mit.edu> Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org> Signed-off-by: Eric Biggers <ebiggers@google.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 0f85c09 commit 4db9f11

3 files changed

Lines changed: 12 additions & 6 deletions

File tree

fs/f2fs/crypto.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,6 @@ static int f2fs_page_crypto(struct f2fs_crypto_ctx *ctx,
362362
else
363363
res = crypto_ablkcipher_encrypt(req);
364364
if (res == -EINPROGRESS || res == -EBUSY) {
365-
BUG_ON(req->base.data != &ecr);
366365
wait_for_completion(&ecr.completion);
367366
res = ecr.res;
368367
}

fs/f2fs/crypto_fname.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,6 @@ static int f2fs_fname_encrypt(struct inode *inode,
124124
ablkcipher_request_set_crypt(req, &src_sg, &dst_sg, ciphertext_len, iv);
125125
res = crypto_ablkcipher_encrypt(req);
126126
if (res == -EINPROGRESS || res == -EBUSY) {
127-
BUG_ON(req->base.data != &ecr);
128127
wait_for_completion(&ecr.completion);
129128
res = ecr.res;
130129
}
@@ -180,7 +179,6 @@ static int f2fs_fname_decrypt(struct inode *inode,
180179
ablkcipher_request_set_crypt(req, &src_sg, &dst_sg, iname->len, iv);
181180
res = crypto_ablkcipher_decrypt(req);
182181
if (res == -EINPROGRESS || res == -EBUSY) {
183-
BUG_ON(req->base.data != &ecr);
184182
wait_for_completion(&ecr.completion);
185183
res = ecr.res;
186184
}

fs/f2fs/crypto_key.c

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ static int f2fs_derive_key_aes(char deriving_key[F2FS_AES_128_ECB_KEY_SIZE],
7575
F2FS_AES_256_XTS_KEY_SIZE, NULL);
7676
res = crypto_ablkcipher_encrypt(req);
7777
if (res == -EINPROGRESS || res == -EBUSY) {
78-
BUG_ON(req->base.data != &ecr);
7978
wait_for_completion(&ecr.completion);
8079
res = ecr.res;
8180
}
@@ -189,7 +188,11 @@ int f2fs_get_encryption_info(struct inode *inode)
189188
keyring_key = NULL;
190189
goto out;
191190
}
192-
BUG_ON(keyring_key->type != &key_type_logon);
191+
if (keyring_key->type != &key_type_logon) {
192+
printk_once(KERN_WARNING "f2fs: key type must be logon\n");
193+
res = -ENOKEY;
194+
goto out;
195+
}
193196
ukp = user_key_payload(keyring_key);
194197
if (ukp->datalen != sizeof(struct f2fs_encryption_key)) {
195198
res = -EINVAL;
@@ -198,7 +201,13 @@ int f2fs_get_encryption_info(struct inode *inode)
198201
master_key = (struct f2fs_encryption_key *)ukp->data;
199202
BUILD_BUG_ON(F2FS_AES_128_ECB_KEY_SIZE !=
200203
F2FS_KEY_DERIVATION_NONCE_SIZE);
201-
BUG_ON(master_key->size != F2FS_AES_256_XTS_KEY_SIZE);
204+
if (master_key->size != F2FS_AES_256_XTS_KEY_SIZE) {
205+
printk_once(KERN_WARNING
206+
"f2fs: key size incorrect: %d\n",
207+
master_key->size);
208+
res = -ENOKEY;
209+
goto out;
210+
}
202211
res = f2fs_derive_key_aes(ctx.nonce, master_key->raw,
203212
raw_key);
204213
if (res)

0 commit comments

Comments
 (0)