eCryptfs: fix a couple type promotion bugs
authorDan Carpenter <dan.carpenter@oracle.com>
Wed, 4 Jul 2018 09:35:56 +0000 (12:35 +0300)
committerTyler Hicks <tyhicks@canonical.com>
Sat, 16 Feb 2019 22:42:47 +0000 (22:42 +0000)
ECRYPTFS_SIZE_AND_MARKER_BYTES is type size_t, so if "rc" is negative
that gets type promoted to a high positive value and treated as success.

Fixes: 778aeb42a708 ("eCryptfs: Cleanup and optimize ecryptfs_lookup_interpose()")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
[tyhicks: Use "if/else if" rather than "if/if"]
Cc: stable@vger.kernel.org
Signed-off-by: Tyler Hicks <tyhicks@canonical.com>
fs/ecryptfs/crypto.c

index 4dd842f728465591cc7982d635f544c0084b064a..708f931c36f14adace91af82229a6043386c9baf 100644 (file)
@@ -1018,8 +1018,10 @@ int ecryptfs_read_and_validate_header_region(struct inode *inode)
 
        rc = ecryptfs_read_lower(file_size, 0, ECRYPTFS_SIZE_AND_MARKER_BYTES,
                                 inode);
-       if (rc < ECRYPTFS_SIZE_AND_MARKER_BYTES)
-               return rc >= 0 ? -EINVAL : rc;
+       if (rc < 0)
+               return rc;
+       else if (rc < ECRYPTFS_SIZE_AND_MARKER_BYTES)
+               return -EINVAL;
        rc = ecryptfs_validate_marker(marker);
        if (!rc)
                ecryptfs_i_size_init(file_size, inode);
@@ -1381,8 +1383,10 @@ int ecryptfs_read_and_validate_xattr_region(struct dentry *dentry,
                                     ecryptfs_inode_to_lower(inode),
                                     ECRYPTFS_XATTR_NAME, file_size,
                                     ECRYPTFS_SIZE_AND_MARKER_BYTES);
-       if (rc < ECRYPTFS_SIZE_AND_MARKER_BYTES)
-               return rc >= 0 ? -EINVAL : rc;
+       if (rc < 0)
+               return rc;
+       else if (rc < ECRYPTFS_SIZE_AND_MARKER_BYTES)
+               return -EINVAL;
        rc = ecryptfs_validate_marker(marker);
        if (!rc)
                ecryptfs_i_size_init(file_size, inode);