aboutsummaryrefslogtreecommitdiffstats
path: root/fs/ecryptfs/crypto.c
diff options
context:
space:
mode:
authorTyler Hicks <tyhicks@linux.vnet.ibm.com>2011-05-02 01:39:54 -0400
committerTyler Hicks <tyhicks@linux.vnet.ibm.com>2011-05-29 15:24:24 -0400
commit7a86617e553f47761b10f57de472d7262562b7de (patch)
tree63ae402692eae9b062b3423b6d081ebe9a192d36 /fs/ecryptfs/crypto.c
parent3b06b3ebf44170c90c893c6c80916db6e922b9f2 (diff)
eCryptfs: Return useful code from contains_ecryptfs_marker
Instead of having the calling functions translate the true/false return code to either 0 or -EINVAL, have contains_ecryptfs_marker() return 0 or -EINVAL so that the calling functions can just reuse the return code. Also, rename the function to ecryptfs_validate_marker() to avoid callers mistakenly thinking that it returns true/false codes. Signed-off-by: Tyler Hicks <tyhicks@linux.vnet.ibm.com>
Diffstat (limited to 'fs/ecryptfs/crypto.c')
-rw-r--r--fs/ecryptfs/crypto.c26
1 files changed, 10 insertions, 16 deletions
diff --git a/fs/ecryptfs/crypto.c b/fs/ecryptfs/crypto.c
index f48c4987a15c..162f9baf9eb5 100644
--- a/fs/ecryptfs/crypto.c
+++ b/fs/ecryptfs/crypto.c
@@ -1024,25 +1024,25 @@ out:
1024} 1024}
1025 1025
1026/** 1026/**
1027 * contains_ecryptfs_marker - check for the ecryptfs marker 1027 * ecryptfs_validate_marker - check for the ecryptfs marker
1028 * @data: The data block in which to check 1028 * @data: The data block in which to check
1029 * 1029 *
1030 * Returns one if marker found; zero if not found 1030 * Returns zero if marker found; -EINVAL if not found
1031 */ 1031 */
1032static int contains_ecryptfs_marker(char *data) 1032static int ecryptfs_validate_marker(char *data)
1033{ 1033{
1034 u32 m_1, m_2; 1034 u32 m_1, m_2;
1035 1035
1036 m_1 = get_unaligned_be32(data); 1036 m_1 = get_unaligned_be32(data);
1037 m_2 = get_unaligned_be32(data + 4); 1037 m_2 = get_unaligned_be32(data + 4);
1038 if ((m_1 ^ MAGIC_ECRYPTFS_MARKER) == m_2) 1038 if ((m_1 ^ MAGIC_ECRYPTFS_MARKER) == m_2)
1039 return 1; 1039 return 0;
1040 ecryptfs_printk(KERN_DEBUG, "m_1 = [0x%.8x]; m_2 = [0x%.8x]; " 1040 ecryptfs_printk(KERN_DEBUG, "m_1 = [0x%.8x]; m_2 = [0x%.8x]; "
1041 "MAGIC_ECRYPTFS_MARKER = [0x%.8x]\n", m_1, m_2, 1041 "MAGIC_ECRYPTFS_MARKER = [0x%.8x]\n", m_1, m_2,
1042 MAGIC_ECRYPTFS_MARKER); 1042 MAGIC_ECRYPTFS_MARKER);
1043 ecryptfs_printk(KERN_DEBUG, "(m_1 ^ MAGIC_ECRYPTFS_MARKER) = " 1043 ecryptfs_printk(KERN_DEBUG, "(m_1 ^ MAGIC_ECRYPTFS_MARKER) = "
1044 "[0x%.8x]\n", (m_1 ^ MAGIC_ECRYPTFS_MARKER)); 1044 "[0x%.8x]\n", (m_1 ^ MAGIC_ECRYPTFS_MARKER));
1045 return 0; 1045 return -EINVAL;
1046} 1046}
1047 1047
1048struct ecryptfs_flag_map_elem { 1048struct ecryptfs_flag_map_elem {
@@ -1217,10 +1217,7 @@ int ecryptfs_read_and_validate_header_region(char *data,
1217 __func__, rc); 1217 __func__, rc);
1218 goto out; 1218 goto out;
1219 } 1219 }
1220 if (!contains_ecryptfs_marker(data + ECRYPTFS_FILE_SIZE_BYTES)) { 1220 rc = ecryptfs_validate_marker(data + ECRYPTFS_FILE_SIZE_BYTES);
1221 rc = -EINVAL;
1222 } else
1223 rc = 0;
1224out: 1221out:
1225 return rc; 1222 return rc;
1226} 1223}
@@ -1496,11 +1493,9 @@ static int ecryptfs_read_headers_virt(char *page_virt,
1496 crypt_stat->mount_crypt_stat = &ecryptfs_superblock_to_private( 1493 crypt_stat->mount_crypt_stat = &ecryptfs_superblock_to_private(
1497 ecryptfs_dentry->d_sb)->mount_crypt_stat; 1494 ecryptfs_dentry->d_sb)->mount_crypt_stat;
1498 offset = ECRYPTFS_FILE_SIZE_BYTES; 1495 offset = ECRYPTFS_FILE_SIZE_BYTES;
1499 rc = contains_ecryptfs_marker(page_virt + offset); 1496 rc = ecryptfs_validate_marker(page_virt + offset);
1500 if (rc == 0) { 1497 if (rc)
1501 rc = -EINVAL;
1502 goto out; 1498 goto out;
1503 }
1504 if (!(crypt_stat->flags & ECRYPTFS_I_SIZE_INITIALIZED)) 1499 if (!(crypt_stat->flags & ECRYPTFS_I_SIZE_INITIALIZED))
1505 ecryptfs_i_size_init(page_virt, ecryptfs_dentry->d_inode); 1500 ecryptfs_i_size_init(page_virt, ecryptfs_dentry->d_inode);
1506 offset += MAGIC_ECRYPTFS_MARKER_SIZE_BYTES; 1501 offset += MAGIC_ECRYPTFS_MARKER_SIZE_BYTES;
@@ -1575,11 +1570,10 @@ int ecryptfs_read_and_validate_xattr_region(char *page_virt,
1575 rc = ecryptfs_read_xattr_region(page_virt, inode); 1570 rc = ecryptfs_read_xattr_region(page_virt, inode);
1576 if (rc) 1571 if (rc)
1577 goto out; 1572 goto out;
1578 if (!contains_ecryptfs_marker(page_virt + ECRYPTFS_FILE_SIZE_BYTES)) { 1573 rc = ecryptfs_validate_marker(page_virt + ECRYPTFS_FILE_SIZE_BYTES);
1574 if (rc)
1579 printk(KERN_WARNING "Valid data found in [%s] xattr, but " 1575 printk(KERN_WARNING "Valid data found in [%s] xattr, but "
1580 "the marker is invalid\n", ECRYPTFS_XATTR_NAME); 1576 "the marker is invalid\n", ECRYPTFS_XATTR_NAME);
1581 rc = -EINVAL;
1582 }
1583out: 1577out:
1584 return rc; 1578 return rc;
1585} 1579}