eCryptfs: fix a couple type promotion bugs [Linux 4.9.187]

This Linux kernel change "eCryptfs: fix a couple type promotion bugs" is included in the Linux 4.9.187 release. This change is authored by Dan Carpenter <dan.carpenter [at] oracle.com> on Wed Jul 4 12:35:56 2018 +0300. The commit for this change in Linux stable tree is e23504d (patch) which is from upstream commit 0bdf8a8. The same Linux upstream change may have been applied to various maintained Linux releases and you can find all Linux releases containing changes from upstream 0bdf8a8.

eCryptfs: fix a couple type promotion bugs

commit 0bdf8a8245fdea6f075a5fede833a5fcf1b3466c upstream.

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 <[email protected]>
[tyhicks: Use "if/else if" rather than "if/if"]
Cc: [email protected]
Signed-off-by: Tyler Hicks <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>

There are 12 lines of Linux source code added/deleted in this change. Code changes to Linux kernel are as follows.

 fs/ecryptfs/crypto.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/fs/ecryptfs/crypto.c b/fs/ecryptfs/crypto.c
index e5e29f8..cb77e7e 100644
--- a/fs/ecryptfs/crypto.c
+++ b/fs/ecryptfs/crypto.c
@@ -1034,8 +1034,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);
@@ -1397,8 +1399,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);

Leave a Reply

Your email address will not be published. Required fields are marked *