diff options
Diffstat (limited to 'fs/ecryptfs/crypto.c')
-rw-r--r-- | fs/ecryptfs/crypto.c | 75 |
1 files changed, 20 insertions, 55 deletions
diff --git a/fs/ecryptfs/crypto.c b/fs/ecryptfs/crypto.c index 58609bde3b9..68b19ab0481 100644 --- a/fs/ecryptfs/crypto.c +++ b/fs/ecryptfs/crypto.c | |||
@@ -417,17 +417,6 @@ static int ecryptfs_encrypt_extent(struct page *enc_extent_page, | |||
417 | (unsigned long long)(extent_base + extent_offset), rc); | 417 | (unsigned long long)(extent_base + extent_offset), rc); |
418 | goto out; | 418 | goto out; |
419 | } | 419 | } |
420 | if (unlikely(ecryptfs_verbosity > 0)) { | ||
421 | ecryptfs_printk(KERN_DEBUG, "Encrypting extent " | ||
422 | "with iv:\n"); | ||
423 | ecryptfs_dump_hex(extent_iv, crypt_stat->iv_bytes); | ||
424 | ecryptfs_printk(KERN_DEBUG, "First 8 bytes before " | ||
425 | "encryption:\n"); | ||
426 | ecryptfs_dump_hex((char *) | ||
427 | (page_address(page) | ||
428 | + (extent_offset * crypt_stat->extent_size)), | ||
429 | 8); | ||
430 | } | ||
431 | rc = ecryptfs_encrypt_page_offset(crypt_stat, enc_extent_page, 0, | 420 | rc = ecryptfs_encrypt_page_offset(crypt_stat, enc_extent_page, 0, |
432 | page, (extent_offset | 421 | page, (extent_offset |
433 | * crypt_stat->extent_size), | 422 | * crypt_stat->extent_size), |
@@ -440,14 +429,6 @@ static int ecryptfs_encrypt_extent(struct page *enc_extent_page, | |||
440 | goto out; | 429 | goto out; |
441 | } | 430 | } |
442 | rc = 0; | 431 | rc = 0; |
443 | if (unlikely(ecryptfs_verbosity > 0)) { | ||
444 | ecryptfs_printk(KERN_DEBUG, "Encrypt extent [0x%.16llx]; " | ||
445 | "rc = [%d]\n", | ||
446 | (unsigned long long)(extent_base + extent_offset), rc); | ||
447 | ecryptfs_printk(KERN_DEBUG, "First 8 bytes after " | ||
448 | "encryption:\n"); | ||
449 | ecryptfs_dump_hex((char *)(page_address(enc_extent_page)), 8); | ||
450 | } | ||
451 | out: | 432 | out: |
452 | return rc; | 433 | return rc; |
453 | } | 434 | } |
@@ -543,17 +524,6 @@ static int ecryptfs_decrypt_extent(struct page *page, | |||
543 | (unsigned long long)(extent_base + extent_offset), rc); | 524 | (unsigned long long)(extent_base + extent_offset), rc); |
544 | goto out; | 525 | goto out; |
545 | } | 526 | } |
546 | if (unlikely(ecryptfs_verbosity > 0)) { | ||
547 | ecryptfs_printk(KERN_DEBUG, "Decrypting extent " | ||
548 | "with iv:\n"); | ||
549 | ecryptfs_dump_hex(extent_iv, crypt_stat->iv_bytes); | ||
550 | ecryptfs_printk(KERN_DEBUG, "First 8 bytes before " | ||
551 | "decryption:\n"); | ||
552 | ecryptfs_dump_hex((char *) | ||
553 | (page_address(enc_extent_page) | ||
554 | + (extent_offset * crypt_stat->extent_size)), | ||
555 | 8); | ||
556 | } | ||
557 | rc = ecryptfs_decrypt_page_offset(crypt_stat, page, | 527 | rc = ecryptfs_decrypt_page_offset(crypt_stat, page, |
558 | (extent_offset | 528 | (extent_offset |
559 | * crypt_stat->extent_size), | 529 | * crypt_stat->extent_size), |
@@ -567,16 +537,6 @@ static int ecryptfs_decrypt_extent(struct page *page, | |||
567 | goto out; | 537 | goto out; |
568 | } | 538 | } |
569 | rc = 0; | 539 | rc = 0; |
570 | if (unlikely(ecryptfs_verbosity > 0)) { | ||
571 | ecryptfs_printk(KERN_DEBUG, "Decrypt extent [0x%.16llx]; " | ||
572 | "rc = [%d]\n", | ||
573 | (unsigned long long)(extent_base + extent_offset), rc); | ||
574 | ecryptfs_printk(KERN_DEBUG, "First 8 bytes after " | ||
575 | "decryption:\n"); | ||
576 | ecryptfs_dump_hex((char *)(page_address(page) | ||
577 | + (extent_offset | ||
578 | * crypt_stat->extent_size)), 8); | ||
579 | } | ||
580 | out: | 540 | out: |
581 | return rc; | 541 | return rc; |
582 | } | 542 | } |
@@ -967,7 +927,7 @@ static void ecryptfs_set_default_crypt_stat_vals( | |||
967 | 927 | ||
968 | /** | 928 | /** |
969 | * ecryptfs_new_file_context | 929 | * ecryptfs_new_file_context |
970 | * @ecryptfs_dentry: The eCryptfs dentry | 930 | * @ecryptfs_inode: The eCryptfs inode |
971 | * | 931 | * |
972 | * If the crypto context for the file has not yet been established, | 932 | * If the crypto context for the file has not yet been established, |
973 | * this is where we do that. Establishing a new crypto context | 933 | * this is where we do that. Establishing a new crypto context |
@@ -984,13 +944,13 @@ static void ecryptfs_set_default_crypt_stat_vals( | |||
984 | * | 944 | * |
985 | * Returns zero on success; non-zero otherwise | 945 | * Returns zero on success; non-zero otherwise |
986 | */ | 946 | */ |
987 | int ecryptfs_new_file_context(struct dentry *ecryptfs_dentry) | 947 | int ecryptfs_new_file_context(struct inode *ecryptfs_inode) |
988 | { | 948 | { |
989 | struct ecryptfs_crypt_stat *crypt_stat = | 949 | struct ecryptfs_crypt_stat *crypt_stat = |
990 | &ecryptfs_inode_to_private(ecryptfs_dentry->d_inode)->crypt_stat; | 950 | &ecryptfs_inode_to_private(ecryptfs_inode)->crypt_stat; |
991 | struct ecryptfs_mount_crypt_stat *mount_crypt_stat = | 951 | struct ecryptfs_mount_crypt_stat *mount_crypt_stat = |
992 | &ecryptfs_superblock_to_private( | 952 | &ecryptfs_superblock_to_private( |
993 | ecryptfs_dentry->d_sb)->mount_crypt_stat; | 953 | ecryptfs_inode->i_sb)->mount_crypt_stat; |
994 | int cipher_name_len; | 954 | int cipher_name_len; |
995 | int rc = 0; | 955 | int rc = 0; |
996 | 956 | ||
@@ -1299,12 +1259,12 @@ static int ecryptfs_write_headers_virt(char *page_virt, size_t max, | |||
1299 | } | 1259 | } |
1300 | 1260 | ||
1301 | static int | 1261 | static int |
1302 | ecryptfs_write_metadata_to_contents(struct dentry *ecryptfs_dentry, | 1262 | ecryptfs_write_metadata_to_contents(struct inode *ecryptfs_inode, |
1303 | char *virt, size_t virt_len) | 1263 | char *virt, size_t virt_len) |
1304 | { | 1264 | { |
1305 | int rc; | 1265 | int rc; |
1306 | 1266 | ||
1307 | rc = ecryptfs_write_lower(ecryptfs_dentry->d_inode, virt, | 1267 | rc = ecryptfs_write_lower(ecryptfs_inode, virt, |
1308 | 0, virt_len); | 1268 | 0, virt_len); |
1309 | if (rc < 0) | 1269 | if (rc < 0) |
1310 | printk(KERN_ERR "%s: Error attempting to write header " | 1270 | printk(KERN_ERR "%s: Error attempting to write header " |
@@ -1338,7 +1298,8 @@ static unsigned long ecryptfs_get_zeroed_pages(gfp_t gfp_mask, | |||
1338 | 1298 | ||
1339 | /** | 1299 | /** |
1340 | * ecryptfs_write_metadata | 1300 | * ecryptfs_write_metadata |
1341 | * @ecryptfs_dentry: The eCryptfs dentry | 1301 | * @ecryptfs_dentry: The eCryptfs dentry, which should be negative |
1302 | * @ecryptfs_inode: The newly created eCryptfs inode | ||
1342 | * | 1303 | * |
1343 | * Write the file headers out. This will likely involve a userspace | 1304 | * Write the file headers out. This will likely involve a userspace |
1344 | * callout, in which the session key is encrypted with one or more | 1305 | * callout, in which the session key is encrypted with one or more |
@@ -1348,10 +1309,11 @@ static unsigned long ecryptfs_get_zeroed_pages(gfp_t gfp_mask, | |||
1348 | * | 1309 | * |
1349 | * Returns zero on success; non-zero on error | 1310 | * Returns zero on success; non-zero on error |
1350 | */ | 1311 | */ |
1351 | int ecryptfs_write_metadata(struct dentry *ecryptfs_dentry) | 1312 | int ecryptfs_write_metadata(struct dentry *ecryptfs_dentry, |
1313 | struct inode *ecryptfs_inode) | ||
1352 | { | 1314 | { |
1353 | struct ecryptfs_crypt_stat *crypt_stat = | 1315 | struct ecryptfs_crypt_stat *crypt_stat = |
1354 | &ecryptfs_inode_to_private(ecryptfs_dentry->d_inode)->crypt_stat; | 1316 | &ecryptfs_inode_to_private(ecryptfs_inode)->crypt_stat; |
1355 | unsigned int order; | 1317 | unsigned int order; |
1356 | char *virt; | 1318 | char *virt; |
1357 | size_t virt_len; | 1319 | size_t virt_len; |
@@ -1391,7 +1353,7 @@ int ecryptfs_write_metadata(struct dentry *ecryptfs_dentry) | |||
1391 | rc = ecryptfs_write_metadata_to_xattr(ecryptfs_dentry, virt, | 1353 | rc = ecryptfs_write_metadata_to_xattr(ecryptfs_dentry, virt, |
1392 | size); | 1354 | size); |
1393 | else | 1355 | else |
1394 | rc = ecryptfs_write_metadata_to_contents(ecryptfs_dentry, virt, | 1356 | rc = ecryptfs_write_metadata_to_contents(ecryptfs_inode, virt, |
1395 | virt_len); | 1357 | virt_len); |
1396 | if (rc) { | 1358 | if (rc) { |
1397 | printk(KERN_ERR "%s: Error writing metadata out to lower file; " | 1359 | printk(KERN_ERR "%s: Error writing metadata out to lower file; " |
@@ -1618,7 +1580,8 @@ int ecryptfs_read_metadata(struct dentry *ecryptfs_dentry) | |||
1618 | rc = ecryptfs_read_xattr_region(page_virt, ecryptfs_inode); | 1580 | rc = ecryptfs_read_xattr_region(page_virt, ecryptfs_inode); |
1619 | if (rc) { | 1581 | if (rc) { |
1620 | printk(KERN_DEBUG "Valid eCryptfs headers not found in " | 1582 | printk(KERN_DEBUG "Valid eCryptfs headers not found in " |
1621 | "file header region or xattr region\n"); | 1583 | "file header region or xattr region, inode %lu\n", |
1584 | ecryptfs_inode->i_ino); | ||
1622 | rc = -EINVAL; | 1585 | rc = -EINVAL; |
1623 | goto out; | 1586 | goto out; |
1624 | } | 1587 | } |
@@ -1627,7 +1590,8 @@ int ecryptfs_read_metadata(struct dentry *ecryptfs_dentry) | |||
1627 | ECRYPTFS_DONT_VALIDATE_HEADER_SIZE); | 1590 | ECRYPTFS_DONT_VALIDATE_HEADER_SIZE); |
1628 | if (rc) { | 1591 | if (rc) { |
1629 | printk(KERN_DEBUG "Valid eCryptfs headers not found in " | 1592 | printk(KERN_DEBUG "Valid eCryptfs headers not found in " |
1630 | "file xattr region either\n"); | 1593 | "file xattr region either, inode %lu\n", |
1594 | ecryptfs_inode->i_ino); | ||
1631 | rc = -EINVAL; | 1595 | rc = -EINVAL; |
1632 | } | 1596 | } |
1633 | if (crypt_stat->mount_crypt_stat->flags | 1597 | if (crypt_stat->mount_crypt_stat->flags |
@@ -1638,7 +1602,8 @@ int ecryptfs_read_metadata(struct dentry *ecryptfs_dentry) | |||
1638 | "crypto metadata only in the extended attribute " | 1602 | "crypto metadata only in the extended attribute " |
1639 | "region, but eCryptfs was mounted without " | 1603 | "region, but eCryptfs was mounted without " |
1640 | "xattr support enabled. eCryptfs will not treat " | 1604 | "xattr support enabled. eCryptfs will not treat " |
1641 | "this like an encrypted file.\n"); | 1605 | "this like an encrypted file, inode %lu\n", |
1606 | ecryptfs_inode->i_ino); | ||
1642 | rc = -EINVAL; | 1607 | rc = -EINVAL; |
1643 | } | 1608 | } |
1644 | } | 1609 | } |
@@ -1943,7 +1908,7 @@ static unsigned char *portable_filename_chars = ("-.0123456789ABCD" | |||
1943 | 1908 | ||
1944 | /* We could either offset on every reverse map or just pad some 0x00's | 1909 | /* We could either offset on every reverse map or just pad some 0x00's |
1945 | * at the front here */ | 1910 | * at the front here */ |
1946 | static const unsigned char filename_rev_map[] = { | 1911 | static const unsigned char filename_rev_map[256] = { |
1947 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 7 */ | 1912 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 7 */ |
1948 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 15 */ | 1913 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 15 */ |
1949 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 23 */ | 1914 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 23 */ |
@@ -1959,7 +1924,7 @@ static const unsigned char filename_rev_map[] = { | |||
1959 | 0x00, 0x26, 0x27, 0x28, 0x29, 0x2A, 0x2B, 0x2C, /* 103 */ | 1924 | 0x00, 0x26, 0x27, 0x28, 0x29, 0x2A, 0x2B, 0x2C, /* 103 */ |
1960 | 0x2D, 0x2E, 0x2F, 0x30, 0x31, 0x32, 0x33, 0x34, /* 111 */ | 1925 | 0x2D, 0x2E, 0x2F, 0x30, 0x31, 0x32, 0x33, 0x34, /* 111 */ |
1961 | 0x35, 0x36, 0x37, 0x38, 0x39, 0x3A, 0x3B, 0x3C, /* 119 */ | 1926 | 0x35, 0x36, 0x37, 0x38, 0x39, 0x3A, 0x3B, 0x3C, /* 119 */ |
1962 | 0x3D, 0x3E, 0x3F | 1927 | 0x3D, 0x3E, 0x3F /* 123 - 255 initialized to 0x00 */ |
1963 | }; | 1928 | }; |
1964 | 1929 | ||
1965 | /** | 1930 | /** |