eCryptfs: Remove unnecessary grow_file() function
authorTyler Hicks <tyhicks@linux.vnet.ibm.com>
Wed, 23 Feb 2011 06:14:19 +0000 (00:14 -0600)
committerTyler Hicks <tyhicks@linux.vnet.ibm.com>
Mon, 28 Mar 2011 06:47:43 +0000 (01:47 -0500)
When creating a new eCryptfs file, the crypto metadata is written out
and then the lower file was being "grown" with 4 kB of encrypted zeroes.
I suspect that growing the encrypted file was to prevent an information
leak that the unencrypted file was empty. However, the unencrypted file
size is stored, in plaintext, in the metadata so growing the file is
unnecessary.

Signed-off-by: Tyler Hicks <tyhicks@linux.vnet.ibm.com>
fs/ecryptfs/crypto.c
fs/ecryptfs/inode.c

index bfd8b680e6481a205dd07d89f3ec401e057abf31..98a2a314ea684121c3b96ff314c77f9b943e8c3e 100644 (file)
@@ -1389,6 +1389,7 @@ int ecryptfs_write_metadata(struct dentry *ecryptfs_dentry)
                rc = -ENOMEM;
                goto out;
        }
+       /* Zeroed page ensures the in-header unencrypted i_size is set to 0 */
        rc = ecryptfs_write_headers_virt(virt, virt_len, &size, crypt_stat,
                                         ecryptfs_dentry);
        if (unlikely(rc)) {
index b592938a84bc40281d8ee80fc5585783bf7ed1d9..8fa365acb78935159366686a23f7aef1b6c6e69f 100644 (file)
@@ -142,26 +142,6 @@ out:
        return rc;
 }
 
-/**
- * grow_file
- * @ecryptfs_dentry: the eCryptfs dentry
- *
- * This is the code which will grow the file to its correct size.
- */
-static int grow_file(struct dentry *ecryptfs_dentry)
-{
-       struct inode *ecryptfs_inode = ecryptfs_dentry->d_inode;
-       char zero_virt[] = { 0x00 };
-       int rc = 0;
-
-       rc = ecryptfs_write(ecryptfs_inode, zero_virt, 0, 1);
-       i_size_write(ecryptfs_inode, 0);
-       rc = ecryptfs_write_inode_size_to_metadata(ecryptfs_inode);
-       ecryptfs_inode_to_private(ecryptfs_inode)->crypt_stat.flags |=
-               ECRYPTFS_NEW_FILE;
-       return rc;
-}
-
 /**
  * ecryptfs_initialize_file
  *
@@ -202,9 +182,6 @@ static int ecryptfs_initialize_file(struct dentry *ecryptfs_dentry)
                printk(KERN_ERR "Error writing headers; rc = [%d]\n", rc);
                goto out;
        }
-       rc = grow_file(ecryptfs_dentry);
-       if (rc)
-               printk(KERN_ERR "Error growing file; rc = [%d]\n", rc);
 out:
        return rc;
 }