diff options
Diffstat (limited to 'fs/ecryptfs')
-rw-r--r-- | fs/ecryptfs/crypto.c | 37 |
1 files changed, 14 insertions, 23 deletions
diff --git a/fs/ecryptfs/crypto.c b/fs/ecryptfs/crypto.c index e2832bc7869a..7b99917ffadc 100644 --- a/fs/ecryptfs/crypto.c +++ b/fs/ecryptfs/crypto.c | |||
@@ -33,6 +33,7 @@ | |||
33 | #include <linux/crypto.h> | 33 | #include <linux/crypto.h> |
34 | #include <linux/file.h> | 34 | #include <linux/file.h> |
35 | #include <linux/scatterlist.h> | 35 | #include <linux/scatterlist.h> |
36 | #include <asm/unaligned.h> | ||
36 | #include "ecryptfs_kernel.h" | 37 | #include "ecryptfs_kernel.h" |
37 | 38 | ||
38 | static int | 39 | static int |
@@ -1032,10 +1033,8 @@ static int contains_ecryptfs_marker(char *data) | |||
1032 | { | 1033 | { |
1033 | u32 m_1, m_2; | 1034 | u32 m_1, m_2; |
1034 | 1035 | ||
1035 | memcpy(&m_1, data, 4); | 1036 | m_1 = get_unaligned_be32(data); |
1036 | m_1 = be32_to_cpu(m_1); | 1037 | m_2 = get_unaligned_be32(data + 4); |
1037 | memcpy(&m_2, (data + 4), 4); | ||
1038 | m_2 = be32_to_cpu(m_2); | ||
1039 | if ((m_1 ^ MAGIC_ECRYPTFS_MARKER) == m_2) | 1038 | if ((m_1 ^ MAGIC_ECRYPTFS_MARKER) == m_2) |
1040 | return 1; | 1039 | return 1; |
1041 | 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]; " |
@@ -1073,8 +1072,7 @@ static int ecryptfs_process_flags(struct ecryptfs_crypt_stat *crypt_stat, | |||
1073 | int i; | 1072 | int i; |
1074 | u32 flags; | 1073 | u32 flags; |
1075 | 1074 | ||
1076 | memcpy(&flags, page_virt, 4); | 1075 | flags = get_unaligned_be32(page_virt); |
1077 | flags = be32_to_cpu(flags); | ||
1078 | for (i = 0; i < ((sizeof(ecryptfs_flag_map) | 1076 | for (i = 0; i < ((sizeof(ecryptfs_flag_map) |
1079 | / sizeof(struct ecryptfs_flag_map_elem))); i++) | 1077 | / sizeof(struct ecryptfs_flag_map_elem))); i++) |
1080 | if (flags & ecryptfs_flag_map[i].file_flag) { | 1078 | if (flags & ecryptfs_flag_map[i].file_flag) { |
@@ -1100,11 +1098,9 @@ static void write_ecryptfs_marker(char *page_virt, size_t *written) | |||
1100 | 1098 | ||
1101 | get_random_bytes(&m_1, (MAGIC_ECRYPTFS_MARKER_SIZE_BYTES / 2)); | 1099 | get_random_bytes(&m_1, (MAGIC_ECRYPTFS_MARKER_SIZE_BYTES / 2)); |
1102 | m_2 = (m_1 ^ MAGIC_ECRYPTFS_MARKER); | 1100 | m_2 = (m_1 ^ MAGIC_ECRYPTFS_MARKER); |
1103 | m_1 = cpu_to_be32(m_1); | 1101 | put_unaligned_be32(m_1, page_virt); |
1104 | memcpy(page_virt, &m_1, (MAGIC_ECRYPTFS_MARKER_SIZE_BYTES / 2)); | 1102 | page_virt += (MAGIC_ECRYPTFS_MARKER_SIZE_BYTES / 2); |
1105 | m_2 = cpu_to_be32(m_2); | 1103 | put_unaligned_be32(m_2, page_virt); |
1106 | memcpy(page_virt + (MAGIC_ECRYPTFS_MARKER_SIZE_BYTES / 2), &m_2, | ||
1107 | (MAGIC_ECRYPTFS_MARKER_SIZE_BYTES / 2)); | ||
1108 | (*written) = MAGIC_ECRYPTFS_MARKER_SIZE_BYTES; | 1104 | (*written) = MAGIC_ECRYPTFS_MARKER_SIZE_BYTES; |
1109 | } | 1105 | } |
1110 | 1106 | ||
@@ -1121,8 +1117,7 @@ write_ecryptfs_flags(char *page_virt, struct ecryptfs_crypt_stat *crypt_stat, | |||
1121 | flags |= ecryptfs_flag_map[i].file_flag; | 1117 | flags |= ecryptfs_flag_map[i].file_flag; |
1122 | /* Version is in top 8 bits of the 32-bit flag vector */ | 1118 | /* Version is in top 8 bits of the 32-bit flag vector */ |
1123 | flags |= ((((u8)crypt_stat->file_version) << 24) & 0xFF000000); | 1119 | flags |= ((((u8)crypt_stat->file_version) << 24) & 0xFF000000); |
1124 | flags = cpu_to_be32(flags); | 1120 | put_unaligned_be32(flags, page_virt); |
1125 | memcpy(page_virt, &flags, 4); | ||
1126 | (*written) = 4; | 1121 | (*written) = 4; |
1127 | } | 1122 | } |
1128 | 1123 | ||
@@ -1238,11 +1233,9 @@ ecryptfs_write_header_metadata(char *virt, | |||
1238 | num_header_extents_at_front = | 1233 | num_header_extents_at_front = |
1239 | (u16)(crypt_stat->num_header_bytes_at_front | 1234 | (u16)(crypt_stat->num_header_bytes_at_front |
1240 | / crypt_stat->extent_size); | 1235 | / crypt_stat->extent_size); |
1241 | header_extent_size = cpu_to_be32(header_extent_size); | 1236 | put_unaligned_be32(header_extent_size, virt); |
1242 | memcpy(virt, &header_extent_size, 4); | ||
1243 | virt += 4; | 1237 | virt += 4; |
1244 | num_header_extents_at_front = cpu_to_be16(num_header_extents_at_front); | 1238 | put_unaligned_be16(num_header_extents_at_front, virt); |
1245 | memcpy(virt, &num_header_extents_at_front, 2); | ||
1246 | (*written) = 6; | 1239 | (*written) = 6; |
1247 | } | 1240 | } |
1248 | 1241 | ||
@@ -1410,15 +1403,13 @@ static int parse_header_metadata(struct ecryptfs_crypt_stat *crypt_stat, | |||
1410 | u32 header_extent_size; | 1403 | u32 header_extent_size; |
1411 | u16 num_header_extents_at_front; | 1404 | u16 num_header_extents_at_front; |
1412 | 1405 | ||
1413 | memcpy(&header_extent_size, virt, sizeof(u32)); | 1406 | header_extent_size = get_unaligned_be32(virt); |
1414 | header_extent_size = be32_to_cpu(header_extent_size); | 1407 | virt += sizeof(__be32); |
1415 | virt += sizeof(u32); | 1408 | num_header_extents_at_front = get_unaligned_be16(virt); |
1416 | memcpy(&num_header_extents_at_front, virt, sizeof(u16)); | ||
1417 | num_header_extents_at_front = be16_to_cpu(num_header_extents_at_front); | ||
1418 | crypt_stat->num_header_bytes_at_front = | 1409 | crypt_stat->num_header_bytes_at_front = |
1419 | (((size_t)num_header_extents_at_front | 1410 | (((size_t)num_header_extents_at_front |
1420 | * (size_t)header_extent_size)); | 1411 | * (size_t)header_extent_size)); |
1421 | (*bytes_read) = (sizeof(u32) + sizeof(u16)); | 1412 | (*bytes_read) = (sizeof(__be32) + sizeof(__be16)); |
1422 | if ((validate_header_size == ECRYPTFS_VALIDATE_HEADER_SIZE) | 1413 | if ((validate_header_size == ECRYPTFS_VALIDATE_HEADER_SIZE) |
1423 | && (crypt_stat->num_header_bytes_at_front | 1414 | && (crypt_stat->num_header_bytes_at_front |
1424 | < ECRYPTFS_MINIMUM_HEADER_EXTENT_SIZE)) { | 1415 | < ECRYPTFS_MINIMUM_HEADER_EXTENT_SIZE)) { |