f2fs crypto: replace some BUG_ON()'s with error checks
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>
This commit is contained in:
parent
8ef2af45ae
commit
66aa3e1274
|
@ -362,7 +362,6 @@ static int f2fs_page_crypto(struct f2fs_crypto_ctx *ctx,
|
||||||
else
|
else
|
||||||
res = crypto_ablkcipher_encrypt(req);
|
res = crypto_ablkcipher_encrypt(req);
|
||||||
if (res == -EINPROGRESS || res == -EBUSY) {
|
if (res == -EINPROGRESS || res == -EBUSY) {
|
||||||
BUG_ON(req->base.data != &ecr);
|
|
||||||
wait_for_completion(&ecr.completion);
|
wait_for_completion(&ecr.completion);
|
||||||
res = ecr.res;
|
res = ecr.res;
|
||||||
}
|
}
|
||||||
|
|
|
@ -124,7 +124,6 @@ static int f2fs_fname_encrypt(struct inode *inode,
|
||||||
ablkcipher_request_set_crypt(req, &src_sg, &dst_sg, ciphertext_len, iv);
|
ablkcipher_request_set_crypt(req, &src_sg, &dst_sg, ciphertext_len, iv);
|
||||||
res = crypto_ablkcipher_encrypt(req);
|
res = crypto_ablkcipher_encrypt(req);
|
||||||
if (res == -EINPROGRESS || res == -EBUSY) {
|
if (res == -EINPROGRESS || res == -EBUSY) {
|
||||||
BUG_ON(req->base.data != &ecr);
|
|
||||||
wait_for_completion(&ecr.completion);
|
wait_for_completion(&ecr.completion);
|
||||||
res = ecr.res;
|
res = ecr.res;
|
||||||
}
|
}
|
||||||
|
@ -180,7 +179,6 @@ static int f2fs_fname_decrypt(struct inode *inode,
|
||||||
ablkcipher_request_set_crypt(req, &src_sg, &dst_sg, iname->len, iv);
|
ablkcipher_request_set_crypt(req, &src_sg, &dst_sg, iname->len, iv);
|
||||||
res = crypto_ablkcipher_decrypt(req);
|
res = crypto_ablkcipher_decrypt(req);
|
||||||
if (res == -EINPROGRESS || res == -EBUSY) {
|
if (res == -EINPROGRESS || res == -EBUSY) {
|
||||||
BUG_ON(req->base.data != &ecr);
|
|
||||||
wait_for_completion(&ecr.completion);
|
wait_for_completion(&ecr.completion);
|
||||||
res = ecr.res;
|
res = ecr.res;
|
||||||
}
|
}
|
||||||
|
|
|
@ -75,7 +75,6 @@ static int f2fs_derive_key_aes(char deriving_key[F2FS_AES_128_ECB_KEY_SIZE],
|
||||||
F2FS_AES_256_XTS_KEY_SIZE, NULL);
|
F2FS_AES_256_XTS_KEY_SIZE, NULL);
|
||||||
res = crypto_ablkcipher_encrypt(req);
|
res = crypto_ablkcipher_encrypt(req);
|
||||||
if (res == -EINPROGRESS || res == -EBUSY) {
|
if (res == -EINPROGRESS || res == -EBUSY) {
|
||||||
BUG_ON(req->base.data != &ecr);
|
|
||||||
wait_for_completion(&ecr.completion);
|
wait_for_completion(&ecr.completion);
|
||||||
res = ecr.res;
|
res = ecr.res;
|
||||||
}
|
}
|
||||||
|
@ -198,7 +197,11 @@ int _f2fs_get_encryption_info(struct inode *inode)
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
crypt_info->ci_keyring_key = keyring_key;
|
crypt_info->ci_keyring_key = keyring_key;
|
||||||
BUG_ON(keyring_key->type != &key_type_logon);
|
if (keyring_key->type != &key_type_logon) {
|
||||||
|
printk_once(KERN_WARNING "f2fs: key type must be logon\n");
|
||||||
|
res = -ENOKEY;
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
ukp = user_key_payload(keyring_key);
|
ukp = user_key_payload(keyring_key);
|
||||||
if (ukp->datalen != sizeof(struct f2fs_encryption_key)) {
|
if (ukp->datalen != sizeof(struct f2fs_encryption_key)) {
|
||||||
res = -EINVAL;
|
res = -EINVAL;
|
||||||
|
@ -207,7 +210,13 @@ int _f2fs_get_encryption_info(struct inode *inode)
|
||||||
master_key = (struct f2fs_encryption_key *)ukp->data;
|
master_key = (struct f2fs_encryption_key *)ukp->data;
|
||||||
BUILD_BUG_ON(F2FS_AES_128_ECB_KEY_SIZE !=
|
BUILD_BUG_ON(F2FS_AES_128_ECB_KEY_SIZE !=
|
||||||
F2FS_KEY_DERIVATION_NONCE_SIZE);
|
F2FS_KEY_DERIVATION_NONCE_SIZE);
|
||||||
BUG_ON(master_key->size != F2FS_AES_256_XTS_KEY_SIZE);
|
if (master_key->size != F2FS_AES_256_XTS_KEY_SIZE) {
|
||||||
|
printk_once(KERN_WARNING
|
||||||
|
"f2fs: key size incorrect: %d\n",
|
||||||
|
master_key->size);
|
||||||
|
res = -ENOKEY;
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
res = f2fs_derive_key_aes(ctx.nonce, master_key->raw,
|
res = f2fs_derive_key_aes(ctx.nonce, master_key->raw,
|
||||||
raw_key);
|
raw_key);
|
||||||
if (res)
|
if (res)
|
||||||
|
|
Loading…
Reference in New Issue