f2fs crypto: replace some BUG_ON()'s with error checks
authorJaegeuk Kim <jaegeuk@kernel.org>
Sat, 6 Feb 2016 03:19:01 +0000 (19:19 -0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 27 Oct 2017 08:23:18 +0000 (10:23 +0200)
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>
fs/f2fs/crypto.c
fs/f2fs/crypto_fname.c
fs/f2fs/crypto_key.c

index 4a62ef14e93275a881f967ceabd66c6bd306345c..d879c6c846b75c27833a9eefb4ab31e1e22a2192 100644 (file)
@@ -362,7 +362,6 @@ static int f2fs_page_crypto(struct f2fs_crypto_ctx *ctx,
        else
                res = crypto_ablkcipher_encrypt(req);
        if (res == -EINPROGRESS || res == -EBUSY) {
-               BUG_ON(req->base.data != &ecr);
                wait_for_completion(&ecr.completion);
                res = ecr.res;
        }
index 38349ed5ea51a352980d0d35067070b01308049f..0fce444dd5ae317cb48de02ee67d8754f5269b56 100644 (file)
@@ -124,7 +124,6 @@ static int f2fs_fname_encrypt(struct inode *inode,
        ablkcipher_request_set_crypt(req, &src_sg, &dst_sg, ciphertext_len, iv);
        res = crypto_ablkcipher_encrypt(req);
        if (res == -EINPROGRESS || res == -EBUSY) {
-               BUG_ON(req->base.data != &ecr);
                wait_for_completion(&ecr.completion);
                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);
        res = crypto_ablkcipher_decrypt(req);
        if (res == -EINPROGRESS || res == -EBUSY) {
-               BUG_ON(req->base.data != &ecr);
                wait_for_completion(&ecr.completion);
                res = ecr.res;
        }
index 18595d7a0efc611542832d98c10fc75667cfbdf0..81c87f7a32519bbae4269b79dad1cf876847e42e 100644 (file)
@@ -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);
        res = crypto_ablkcipher_encrypt(req);
        if (res == -EINPROGRESS || res == -EBUSY) {
-               BUG_ON(req->base.data != &ecr);
                wait_for_completion(&ecr.completion);
                res = ecr.res;
        }
@@ -189,7 +188,11 @@ int f2fs_get_encryption_info(struct inode *inode)
                keyring_key = NULL;
                goto out;
        }
-       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);
        if (ukp->datalen != sizeof(struct f2fs_encryption_key)) {
                res = -EINVAL;
@@ -198,7 +201,13 @@ int f2fs_get_encryption_info(struct inode *inode)
        master_key = (struct f2fs_encryption_key *)ukp->data;
        BUILD_BUG_ON(F2FS_AES_128_ECB_KEY_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,
                                  raw_key);
        if (res)