aboutsummaryrefslogtreecommitdiffstats
path: root/fs/ecryptfs/crypto.c
diff options
context:
space:
mode:
Diffstat (limited to 'fs/ecryptfs/crypto.c')
-rw-r--r--fs/ecryptfs/crypto.c49
1 files changed, 32 insertions, 17 deletions
diff --git a/fs/ecryptfs/crypto.c b/fs/ecryptfs/crypto.c
index bdca1f4b3a3e..8b65f289ee00 100644
--- a/fs/ecryptfs/crypto.c
+++ b/fs/ecryptfs/crypto.c
@@ -1324,14 +1324,13 @@ static int ecryptfs_write_headers_virt(char *page_virt, size_t max,
1324} 1324}
1325 1325
1326static int 1326static int
1327ecryptfs_write_metadata_to_contents(struct ecryptfs_crypt_stat *crypt_stat, 1327ecryptfs_write_metadata_to_contents(struct dentry *ecryptfs_dentry,
1328 struct dentry *ecryptfs_dentry, 1328 char *virt, size_t virt_len)
1329 char *virt)
1330{ 1329{
1331 int rc; 1330 int rc;
1332 1331
1333 rc = ecryptfs_write_lower(ecryptfs_dentry->d_inode, virt, 1332 rc = ecryptfs_write_lower(ecryptfs_dentry->d_inode, virt,
1334 0, crypt_stat->num_header_bytes_at_front); 1333 0, virt_len);
1335 if (rc) 1334 if (rc)
1336 printk(KERN_ERR "%s: Error attempting to write header " 1335 printk(KERN_ERR "%s: Error attempting to write header "
1337 "information to lower file; rc = [%d]\n", __func__, 1336 "information to lower file; rc = [%d]\n", __func__,
@@ -1341,7 +1340,6 @@ ecryptfs_write_metadata_to_contents(struct ecryptfs_crypt_stat *crypt_stat,
1341 1340
1342static int 1341static int
1343ecryptfs_write_metadata_to_xattr(struct dentry *ecryptfs_dentry, 1342ecryptfs_write_metadata_to_xattr(struct dentry *ecryptfs_dentry,
1344 struct ecryptfs_crypt_stat *crypt_stat,
1345 char *page_virt, size_t size) 1343 char *page_virt, size_t size)
1346{ 1344{
1347 int rc; 1345 int rc;
@@ -1351,6 +1349,17 @@ ecryptfs_write_metadata_to_xattr(struct dentry *ecryptfs_dentry,
1351 return rc; 1349 return rc;
1352} 1350}
1353 1351
1352static unsigned long ecryptfs_get_zeroed_pages(gfp_t gfp_mask,
1353 unsigned int order)
1354{
1355 struct page *page;
1356
1357 page = alloc_pages(gfp_mask | __GFP_ZERO, order);
1358 if (page)
1359 return (unsigned long) page_address(page);
1360 return 0;
1361}
1362
1354/** 1363/**
1355 * ecryptfs_write_metadata 1364 * ecryptfs_write_metadata
1356 * @ecryptfs_dentry: The eCryptfs dentry 1365 * @ecryptfs_dentry: The eCryptfs dentry
@@ -1367,7 +1376,9 @@ int ecryptfs_write_metadata(struct dentry *ecryptfs_dentry)
1367{ 1376{
1368 struct ecryptfs_crypt_stat *crypt_stat = 1377 struct ecryptfs_crypt_stat *crypt_stat =
1369 &ecryptfs_inode_to_private(ecryptfs_dentry->d_inode)->crypt_stat; 1378 &ecryptfs_inode_to_private(ecryptfs_dentry->d_inode)->crypt_stat;
1379 unsigned int order;
1370 char *virt; 1380 char *virt;
1381 size_t virt_len;
1371 size_t size = 0; 1382 size_t size = 0;
1372 int rc = 0; 1383 int rc = 0;
1373 1384
@@ -1383,33 +1394,35 @@ int ecryptfs_write_metadata(struct dentry *ecryptfs_dentry)
1383 rc = -EINVAL; 1394 rc = -EINVAL;
1384 goto out; 1395 goto out;
1385 } 1396 }
1397 virt_len = crypt_stat->num_header_bytes_at_front;
1398 order = get_order(virt_len);
1386 /* Released in this function */ 1399 /* Released in this function */
1387 virt = (char *)get_zeroed_page(GFP_KERNEL); 1400 virt = (char *)ecryptfs_get_zeroed_pages(GFP_KERNEL, order);
1388 if (!virt) { 1401 if (!virt) {
1389 printk(KERN_ERR "%s: Out of memory\n", __func__); 1402 printk(KERN_ERR "%s: Out of memory\n", __func__);
1390 rc = -ENOMEM; 1403 rc = -ENOMEM;
1391 goto out; 1404 goto out;
1392 } 1405 }
1393 rc = ecryptfs_write_headers_virt(virt, PAGE_CACHE_SIZE, &size, 1406 rc = ecryptfs_write_headers_virt(virt, virt_len, &size, crypt_stat,
1394 crypt_stat, ecryptfs_dentry); 1407 ecryptfs_dentry);
1395 if (unlikely(rc)) { 1408 if (unlikely(rc)) {
1396 printk(KERN_ERR "%s: Error whilst writing headers; rc = [%d]\n", 1409 printk(KERN_ERR "%s: Error whilst writing headers; rc = [%d]\n",
1397 __func__, rc); 1410 __func__, rc);
1398 goto out_free; 1411 goto out_free;
1399 } 1412 }
1400 if (crypt_stat->flags & ECRYPTFS_METADATA_IN_XATTR) 1413 if (crypt_stat->flags & ECRYPTFS_METADATA_IN_XATTR)
1401 rc = ecryptfs_write_metadata_to_xattr(ecryptfs_dentry, 1414 rc = ecryptfs_write_metadata_to_xattr(ecryptfs_dentry, virt,
1402 crypt_stat, virt, size); 1415 size);
1403 else 1416 else
1404 rc = ecryptfs_write_metadata_to_contents(crypt_stat, 1417 rc = ecryptfs_write_metadata_to_contents(ecryptfs_dentry, virt,
1405 ecryptfs_dentry, virt); 1418 virt_len);
1406 if (rc) { 1419 if (rc) {
1407 printk(KERN_ERR "%s: Error writing metadata out to lower file; " 1420 printk(KERN_ERR "%s: Error writing metadata out to lower file; "
1408 "rc = [%d]\n", __func__, rc); 1421 "rc = [%d]\n", __func__, rc);
1409 goto out_free; 1422 goto out_free;
1410 } 1423 }
1411out_free: 1424out_free:
1412 free_page((unsigned long)virt); 1425 free_pages((unsigned long)virt, order);
1413out: 1426out:
1414 return rc; 1427 return rc;
1415} 1428}
@@ -2208,17 +2221,19 @@ int ecryptfs_decode_and_decrypt_filename(char **plaintext_name,
2208 struct dentry *ecryptfs_dir_dentry, 2221 struct dentry *ecryptfs_dir_dentry,
2209 const char *name, size_t name_size) 2222 const char *name, size_t name_size)
2210{ 2223{
2224 struct ecryptfs_mount_crypt_stat *mount_crypt_stat =
2225 &ecryptfs_superblock_to_private(
2226 ecryptfs_dir_dentry->d_sb)->mount_crypt_stat;
2211 char *decoded_name; 2227 char *decoded_name;
2212 size_t decoded_name_size; 2228 size_t decoded_name_size;
2213 size_t packet_size; 2229 size_t packet_size;
2214 int rc = 0; 2230 int rc = 0;
2215 2231
2216 if ((name_size > ECRYPTFS_FNEK_ENCRYPTED_FILENAME_PREFIX_SIZE) 2232 if ((mount_crypt_stat->flags & ECRYPTFS_GLOBAL_ENCRYPT_FILENAMES)
2233 && !(mount_crypt_stat->flags & ECRYPTFS_ENCRYPTED_VIEW_ENABLED)
2234 && (name_size > ECRYPTFS_FNEK_ENCRYPTED_FILENAME_PREFIX_SIZE)
2217 && (strncmp(name, ECRYPTFS_FNEK_ENCRYPTED_FILENAME_PREFIX, 2235 && (strncmp(name, ECRYPTFS_FNEK_ENCRYPTED_FILENAME_PREFIX,
2218 ECRYPTFS_FNEK_ENCRYPTED_FILENAME_PREFIX_SIZE) == 0)) { 2236 ECRYPTFS_FNEK_ENCRYPTED_FILENAME_PREFIX_SIZE) == 0)) {
2219 struct ecryptfs_mount_crypt_stat *mount_crypt_stat =
2220 &ecryptfs_superblock_to_private(
2221 ecryptfs_dir_dentry->d_sb)->mount_crypt_stat;
2222 const char *orig_name = name; 2237 const char *orig_name = name;
2223 size_t orig_name_size = name_size; 2238 size_t orig_name_size = name_size;
2224 2239