ecryptfs: replace BUG_ON with error handling code
authorAditya Pakki <pakki001@umn.edu>
Fri, 14 Feb 2020 18:21:01 +0000 (12:21 -0600)
committerTyler Hicks <code@tyhicks.com>
Fri, 14 Feb 2020 20:07:46 +0000 (20:07 +0000)
In crypt_scatterlist, if the crypt_stat argument is not set up
correctly, the kernel crashes. Instead, by returning an error code
upstream, the error is handled safely.

The issue is detected via a static analysis tool written by us.

Fixes: 237fead619984 (ecryptfs: fs/Makefile and fs/Kconfig)
Signed-off-by: Aditya Pakki <pakki001@umn.edu>
Signed-off-by: Tyler Hicks <code@tyhicks.com>
fs/ecryptfs/crypto.c

index f91db24bbf3bcc0d4c095d788ab0f345e3b6b176..a064b408d841655dc246ed16f806c40f5e8c798f 100644 (file)
@@ -311,8 +311,10 @@ static int crypt_scatterlist(struct ecryptfs_crypt_stat *crypt_stat,
        struct extent_crypt_result ecr;
        int rc = 0;
 
-       BUG_ON(!crypt_stat || !crypt_stat->tfm
-              || !(crypt_stat->flags & ECRYPTFS_STRUCT_INITIALIZED));
+       if (!crypt_stat || !crypt_stat->tfm
+              || !(crypt_stat->flags & ECRYPTFS_STRUCT_INITIALIZED))
+               return -EINVAL;
+
        if (unlikely(ecryptfs_verbosity > 0)) {
                ecryptfs_printk(KERN_DEBUG, "Key size [%zd]; key:\n",
                                crypt_stat->key_size);