@@ -1024,25 +1024,25 @@ int ecryptfs_new_file_context(struct dentry *ecryptfs_dentry)
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
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
*/
1032
- static int contains_ecryptfs_marker (char * data )
1032
+ static int ecryptfs_validate_marker (char * data )
1033
1033
{
1034
1034
u32 m_1 , m_2 ;
1035
1035
1036
1036
m_1 = get_unaligned_be32 (data );
1037
1037
m_2 = get_unaligned_be32 (data + 4 );
1038
1038
if ((m_1 ^ MAGIC_ECRYPTFS_MARKER ) == m_2 )
1039
- return 1 ;
1039
+ return 0 ;
1040
1040
ecryptfs_printk (KERN_DEBUG , "m_1 = [0x%.8x]; m_2 = [0x%.8x]; "
1041
1041
"MAGIC_ECRYPTFS_MARKER = [0x%.8x]\n" , m_1 , m_2 ,
1042
1042
MAGIC_ECRYPTFS_MARKER );
1043
1043
ecryptfs_printk (KERN_DEBUG , "(m_1 ^ MAGIC_ECRYPTFS_MARKER) = "
1044
1044
"[0x%.8x]\n" , (m_1 ^ MAGIC_ECRYPTFS_MARKER ));
1045
- return 0 ;
1045
+ return - EINVAL ;
1046
1046
}
1047
1047
1048
1048
struct ecryptfs_flag_map_elem {
@@ -1201,27 +1201,19 @@ int ecryptfs_cipher_code_to_string(char *str, u8 cipher_code)
1201
1201
return rc ;
1202
1202
}
1203
1203
1204
- int ecryptfs_read_and_validate_header_region (char * data ,
1205
- struct inode * ecryptfs_inode )
1204
+ int ecryptfs_read_and_validate_header_region (struct inode * inode )
1206
1205
{
1207
- struct ecryptfs_crypt_stat * crypt_stat =
1208
- & ( ecryptfs_inode_to_private ( ecryptfs_inode ) -> crypt_stat ) ;
1206
+ u8 file_size [ ECRYPTFS_SIZE_AND_MARKER_BYTES ];
1207
+ u8 * marker = file_size + ECRYPTFS_FILE_SIZE_BYTES ;
1209
1208
int rc ;
1210
1209
1211
- if (crypt_stat -> extent_size == 0 )
1212
- crypt_stat -> extent_size = ECRYPTFS_DEFAULT_EXTENT_SIZE ;
1213
- rc = ecryptfs_read_lower (data , 0 , crypt_stat -> extent_size ,
1214
- ecryptfs_inode );
1215
- if (rc < 0 ) {
1216
- printk (KERN_ERR "%s: Error reading header region; rc = [%d]\n" ,
1217
- __func__ , rc );
1218
- goto out ;
1219
- }
1220
- if (!contains_ecryptfs_marker (data + ECRYPTFS_FILE_SIZE_BYTES )) {
1221
- rc = - EINVAL ;
1222
- } else
1223
- rc = 0 ;
1224
- out :
1210
+ rc = ecryptfs_read_lower (file_size , 0 , ECRYPTFS_SIZE_AND_MARKER_BYTES ,
1211
+ inode );
1212
+ if (rc < ECRYPTFS_SIZE_AND_MARKER_BYTES )
1213
+ return rc >= 0 ? - EINVAL : rc ;
1214
+ rc = ecryptfs_validate_marker (marker );
1215
+ if (!rc )
1216
+ ecryptfs_i_size_init (file_size , inode );
1225
1217
return rc ;
1226
1218
}
1227
1219
@@ -1242,8 +1234,7 @@ ecryptfs_write_header_metadata(char *virt,
1242
1234
(* written ) = 6 ;
1243
1235
}
1244
1236
1245
- struct kmem_cache * ecryptfs_header_cache_1 ;
1246
- struct kmem_cache * ecryptfs_header_cache_2 ;
1237
+ struct kmem_cache * ecryptfs_header_cache ;
1247
1238
1248
1239
/**
1249
1240
* ecryptfs_write_headers_virt
@@ -1496,11 +1487,9 @@ static int ecryptfs_read_headers_virt(char *page_virt,
1496
1487
crypt_stat -> mount_crypt_stat = & ecryptfs_superblock_to_private (
1497
1488
ecryptfs_dentry -> d_sb )-> mount_crypt_stat ;
1498
1489
offset = ECRYPTFS_FILE_SIZE_BYTES ;
1499
- rc = contains_ecryptfs_marker (page_virt + offset );
1500
- if (rc == 0 ) {
1501
- rc = - EINVAL ;
1490
+ rc = ecryptfs_validate_marker (page_virt + offset );
1491
+ if (rc )
1502
1492
goto out ;
1503
- }
1504
1493
if (!(crypt_stat -> flags & ECRYPTFS_I_SIZE_INITIALIZED ))
1505
1494
ecryptfs_i_size_init (page_virt , ecryptfs_dentry -> d_inode );
1506
1495
offset += MAGIC_ECRYPTFS_MARKER_SIZE_BYTES ;
@@ -1567,20 +1556,21 @@ int ecryptfs_read_xattr_region(char *page_virt, struct inode *ecryptfs_inode)
1567
1556
return rc ;
1568
1557
}
1569
1558
1570
- int ecryptfs_read_and_validate_xattr_region (char * page_virt ,
1571
- struct dentry * ecryptfs_dentry )
1559
+ int ecryptfs_read_and_validate_xattr_region (struct dentry * dentry ,
1560
+ struct inode * inode )
1572
1561
{
1562
+ u8 file_size [ECRYPTFS_SIZE_AND_MARKER_BYTES ];
1563
+ u8 * marker = file_size + ECRYPTFS_FILE_SIZE_BYTES ;
1573
1564
int rc ;
1574
1565
1575
- rc = ecryptfs_read_xattr_region (page_virt , ecryptfs_dentry -> d_inode );
1576
- if (rc )
1577
- goto out ;
1578
- if (!contains_ecryptfs_marker (page_virt + ECRYPTFS_FILE_SIZE_BYTES )) {
1579
- printk (KERN_WARNING "Valid data found in [%s] xattr, but "
1580
- "the marker is invalid\n" , ECRYPTFS_XATTR_NAME );
1581
- rc = - EINVAL ;
1582
- }
1583
- out :
1566
+ rc = ecryptfs_getxattr_lower (ecryptfs_dentry_to_lower (dentry ),
1567
+ ECRYPTFS_XATTR_NAME , file_size ,
1568
+ ECRYPTFS_SIZE_AND_MARKER_BYTES );
1569
+ if (rc < ECRYPTFS_SIZE_AND_MARKER_BYTES )
1570
+ return rc >= 0 ? - EINVAL : rc ;
1571
+ rc = ecryptfs_validate_marker (marker );
1572
+ if (!rc )
1573
+ ecryptfs_i_size_init (file_size , inode );
1584
1574
return rc ;
1585
1575
}
1586
1576
@@ -1610,7 +1600,7 @@ int ecryptfs_read_metadata(struct dentry *ecryptfs_dentry)
1610
1600
ecryptfs_copy_mount_wide_flags_to_inode_flags (crypt_stat ,
1611
1601
mount_crypt_stat );
1612
1602
/* Read the first page from the underlying file */
1613
- page_virt = kmem_cache_alloc (ecryptfs_header_cache_1 , GFP_USER );
1603
+ page_virt = kmem_cache_alloc (ecryptfs_header_cache , GFP_USER );
1614
1604
if (!page_virt ) {
1615
1605
rc = - ENOMEM ;
1616
1606
printk (KERN_ERR "%s: Unable to allocate page_virt\n" ,
@@ -1655,7 +1645,7 @@ int ecryptfs_read_metadata(struct dentry *ecryptfs_dentry)
1655
1645
out :
1656
1646
if (page_virt ) {
1657
1647
memset (page_virt , 0 , PAGE_CACHE_SIZE );
1658
- kmem_cache_free (ecryptfs_header_cache_1 , page_virt );
1648
+ kmem_cache_free (ecryptfs_header_cache , page_virt );
1659
1649
}
1660
1650
return rc ;
1661
1651
}
0 commit comments