diff options
| author | Dan Carpenter <dan.carpenter@oracle.com> | 2018-07-04 05:35:56 -0400 |
|---|---|---|
| committer | Tyler Hicks <tyhicks@canonical.com> | 2019-02-16 17:42:47 -0500 |
| commit | 0bdf8a8245fdea6f075a5fede833a5fcf1b3466c (patch) | |
| tree | c599abcee8b22ab95caa56f7e628026f1ed4cd8d | |
| parent | 5ded5871030eb75017639148da0a58931dfbfc25 (diff) | |
eCryptfs: fix a couple type promotion bugs
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>
| -rw-r--r-- | fs/ecryptfs/crypto.c | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/fs/ecryptfs/crypto.c b/fs/ecryptfs/crypto.c index 4dd842f72846..708f931c36f1 100644 --- a/fs/ecryptfs/crypto.c +++ b/fs/ecryptfs/crypto.c | |||
| @@ -1018,8 +1018,10 @@ int ecryptfs_read_and_validate_header_region(struct inode *inode) | |||
| 1018 | 1018 | ||
| 1019 | rc = ecryptfs_read_lower(file_size, 0, ECRYPTFS_SIZE_AND_MARKER_BYTES, | 1019 | rc = ecryptfs_read_lower(file_size, 0, ECRYPTFS_SIZE_AND_MARKER_BYTES, |
| 1020 | inode); | 1020 | inode); |
| 1021 | if (rc < ECRYPTFS_SIZE_AND_MARKER_BYTES) | 1021 | if (rc < 0) |
| 1022 | return rc >= 0 ? -EINVAL : rc; | 1022 | return rc; |
| 1023 | else if (rc < ECRYPTFS_SIZE_AND_MARKER_BYTES) | ||
| 1024 | return -EINVAL; | ||
| 1023 | rc = ecryptfs_validate_marker(marker); | 1025 | rc = ecryptfs_validate_marker(marker); |
| 1024 | if (!rc) | 1026 | if (!rc) |
| 1025 | ecryptfs_i_size_init(file_size, inode); | 1027 | ecryptfs_i_size_init(file_size, inode); |
| @@ -1381,8 +1383,10 @@ int ecryptfs_read_and_validate_xattr_region(struct dentry *dentry, | |||
| 1381 | ecryptfs_inode_to_lower(inode), | 1383 | ecryptfs_inode_to_lower(inode), |
| 1382 | ECRYPTFS_XATTR_NAME, file_size, | 1384 | ECRYPTFS_XATTR_NAME, file_size, |
| 1383 | ECRYPTFS_SIZE_AND_MARKER_BYTES); | 1385 | ECRYPTFS_SIZE_AND_MARKER_BYTES); |
| 1384 | if (rc < ECRYPTFS_SIZE_AND_MARKER_BYTES) | 1386 | if (rc < 0) |
| 1385 | return rc >= 0 ? -EINVAL : rc; | 1387 | return rc; |
| 1388 | else if (rc < ECRYPTFS_SIZE_AND_MARKER_BYTES) | ||
| 1389 | return -EINVAL; | ||
| 1386 | rc = ecryptfs_validate_marker(marker); | 1390 | rc = ecryptfs_validate_marker(marker); |
| 1387 | if (!rc) | 1391 | if (!rc) |
| 1388 | ecryptfs_i_size_init(file_size, inode); | 1392 | ecryptfs_i_size_init(file_size, inode); |
