inode.c (c376222960ae91d5ffb9197ee36771aaed1d9f90) | inode.c (dd2a3b7ad98f8482cae481cad89dfed5eee48365) |
---|---|
1/** 2 * eCryptfs: Linux filesystem encryption layer 3 * 4 * Copyright (C) 1997-2004 Erez Zadok 5 * Copyright (C) 2001-2004 Stony Brook University | 1/** 2 * eCryptfs: Linux filesystem encryption layer 3 * 4 * Copyright (C) 1997-2004 Erez Zadok 5 * Copyright (C) 2001-2004 Stony Brook University |
6 * Copyright (C) 2004-2006 International Business Machines Corp. | 6 * Copyright (C) 2004-2007 International Business Machines Corp. |
7 * Author(s): Michael A. Halcrow <mahalcro@us.ibm.com> 8 * Michael C. Thompsion <mcthomps@us.ibm.com> 9 * 10 * This program is free software; you can redistribute it and/or 11 * modify it under the terms of the GNU General Public License as 12 * published by the Free Software Foundation; either version 2 of the 13 * License, or (at your option) any later version. 14 * --- 149 unchanged lines hidden (view full) --- 164 ECRYPTFS_SET_FLAG( 165 ecryptfs_inode_to_private(inode)->crypt_stat.flags, 166 ECRYPTFS_SECURITY_WARNING); 167 ecryptfs_printk(KERN_WARNING, "Error attempting to fill zeros " 168 "in file; rc = [%d]\n", rc); 169 goto out; 170 } 171 i_size_write(inode, 0); | 7 * Author(s): Michael A. Halcrow <mahalcro@us.ibm.com> 8 * Michael C. Thompsion <mcthomps@us.ibm.com> 9 * 10 * This program is free software; you can redistribute it and/or 11 * modify it under the terms of the GNU General Public License as 12 * published by the Free Software Foundation; either version 2 of the 13 * License, or (at your option) any later version. 14 * --- 149 unchanged lines hidden (view full) --- 164 ECRYPTFS_SET_FLAG( 165 ecryptfs_inode_to_private(inode)->crypt_stat.flags, 166 ECRYPTFS_SECURITY_WARNING); 167 ecryptfs_printk(KERN_WARNING, "Error attempting to fill zeros " 168 "in file; rc = [%d]\n", rc); 169 goto out; 170 } 171 i_size_write(inode, 0); |
172 ecryptfs_write_inode_size_to_header(lower_file, lower_inode, inode); | 172 ecryptfs_write_inode_size_to_metadata(lower_file, lower_inode, inode, 173 ecryptfs_dentry, 174 ECRYPTFS_LOWER_I_MUTEX_NOT_HELD); |
173 ECRYPTFS_SET_FLAG(ecryptfs_inode_to_private(inode)->crypt_stat.flags, 174 ECRYPTFS_NEW_FILE); 175out: 176 return rc; 177} 178 179/** 180 * ecryptfs_initialize_file --- 39 unchanged lines hidden (view full) --- 220 ECRYPTFS_SET_FLAG(crypt_stat->flags, ECRYPTFS_NEW_FILE); 221 ecryptfs_printk(KERN_DEBUG, "Initializing crypto context\n"); 222 rc = ecryptfs_new_file_context(ecryptfs_dentry); 223 if (rc) { 224 ecryptfs_printk(KERN_DEBUG, "Error creating new file " 225 "context\n"); 226 goto out_fput; 227 } | 175 ECRYPTFS_SET_FLAG(ecryptfs_inode_to_private(inode)->crypt_stat.flags, 176 ECRYPTFS_NEW_FILE); 177out: 178 return rc; 179} 180 181/** 182 * ecryptfs_initialize_file --- 39 unchanged lines hidden (view full) --- 222 ECRYPTFS_SET_FLAG(crypt_stat->flags, ECRYPTFS_NEW_FILE); 223 ecryptfs_printk(KERN_DEBUG, "Initializing crypto context\n"); 224 rc = ecryptfs_new_file_context(ecryptfs_dentry); 225 if (rc) { 226 ecryptfs_printk(KERN_DEBUG, "Error creating new file " 227 "context\n"); 228 goto out_fput; 229 } |
228 rc = ecryptfs_write_headers(ecryptfs_dentry, lower_file); | 230 rc = ecryptfs_write_metadata(ecryptfs_dentry, lower_file); |
229 if (rc) { 230 ecryptfs_printk(KERN_DEBUG, "Error writing headers\n"); 231 goto out_fput; 232 } 233 rc = grow_file(ecryptfs_dentry, lower_file, inode, lower_inode); 234out_fput: 235 if ((rc = ecryptfs_close_lower_file(lower_file))) 236 printk(KERN_ERR "Error closing lower_file\n"); --- 120 unchanged lines hidden (view full) --- 357 } 358 if (!nd) { 359 ecryptfs_printk(KERN_DEBUG, "We have a NULL nd, just leave" 360 "as we *think* we are about to unlink\n"); 361 goto out; 362 } 363 /* Released in this function */ 364 page_virt = kmem_cache_zalloc(ecryptfs_header_cache_2, | 231 if (rc) { 232 ecryptfs_printk(KERN_DEBUG, "Error writing headers\n"); 233 goto out_fput; 234 } 235 rc = grow_file(ecryptfs_dentry, lower_file, inode, lower_inode); 236out_fput: 237 if ((rc = ecryptfs_close_lower_file(lower_file))) 238 printk(KERN_ERR "Error closing lower_file\n"); --- 120 unchanged lines hidden (view full) --- 359 } 360 if (!nd) { 361 ecryptfs_printk(KERN_DEBUG, "We have a NULL nd, just leave" 362 "as we *think* we are about to unlink\n"); 363 goto out; 364 } 365 /* Released in this function */ 366 page_virt = kmem_cache_zalloc(ecryptfs_header_cache_2, |
365 GFP_USER); | 367 GFP_USER); |
366 if (!page_virt) { 367 rc = -ENOMEM; 368 ecryptfs_printk(KERN_ERR, 369 "Cannot ecryptfs_kmalloc a page\n"); 370 goto out_dput; 371 } | 368 if (!page_virt) { 369 rc = -ENOMEM; 370 ecryptfs_printk(KERN_ERR, 371 "Cannot ecryptfs_kmalloc a page\n"); 372 goto out_dput; 373 } |
372 373 rc = ecryptfs_read_header_region(page_virt, lower_dentry, nd->mnt); | |
374 crypt_stat = &ecryptfs_inode_to_private(dentry->d_inode)->crypt_stat; 375 if (!ECRYPTFS_CHECK_FLAG(crypt_stat->flags, ECRYPTFS_POLICY_APPLIED)) 376 ecryptfs_set_default_sizes(crypt_stat); | 374 crypt_stat = &ecryptfs_inode_to_private(dentry->d_inode)->crypt_stat; 375 if (!ECRYPTFS_CHECK_FLAG(crypt_stat->flags, ECRYPTFS_POLICY_APPLIED)) 376 ecryptfs_set_default_sizes(crypt_stat); |
377 rc = ecryptfs_read_and_validate_header_region(page_virt, lower_dentry, 378 nd->mnt); |
|
377 if (rc) { | 379 if (rc) { |
378 rc = 0; 379 ecryptfs_printk(KERN_WARNING, "Error reading header region;" 380 " assuming unencrypted\n"); 381 } else { 382 if (!contains_ecryptfs_marker(page_virt 383 + ECRYPTFS_FILE_SIZE_BYTES)) { | 380 rc = ecryptfs_read_and_validate_xattr_region(page_virt, dentry); 381 if (rc) { 382 printk(KERN_DEBUG "Valid metadata not found in header " 383 "region or xattr region; treating file as " 384 "unencrypted\n"); 385 rc = 0; |
384 kmem_cache_free(ecryptfs_header_cache_2, page_virt); 385 goto out; 386 } | 386 kmem_cache_free(ecryptfs_header_cache_2, page_virt); 387 goto out; 388 } |
387 memcpy(&file_size, page_virt, sizeof(file_size)); 388 file_size = be64_to_cpu(file_size); 389 i_size_write(dentry->d_inode, (loff_t)file_size); | 389 crypt_stat->flags |= ECRYPTFS_METADATA_IN_XATTR; |
390 } | 390 } |
391 memcpy(&file_size, page_virt, sizeof(file_size)); 392 file_size = be64_to_cpu(file_size); 393 i_size_write(dentry->d_inode, (loff_t)file_size); |
|
391 kmem_cache_free(ecryptfs_header_cache_2, page_virt); 392 goto out; 393 394out_dput: 395 dput(lower_dentry); 396 d_drop(dentry); 397out: 398 return ERR_PTR(rc); --- 377 unchanged lines hidden (view full) --- 776 if (new_length > i_size) { 777 rc = ecryptfs_fill_zeros(&fake_ecryptfs_file, new_length); 778 if (rc) { 779 ecryptfs_printk(KERN_ERR, 780 "Problem with fill_zeros\n"); 781 goto out_fput; 782 } 783 i_size_write(inode, new_length); | 394 kmem_cache_free(ecryptfs_header_cache_2, page_virt); 395 goto out; 396 397out_dput: 398 dput(lower_dentry); 399 d_drop(dentry); 400out: 401 return ERR_PTR(rc); --- 377 unchanged lines hidden (view full) --- 779 if (new_length > i_size) { 780 rc = ecryptfs_fill_zeros(&fake_ecryptfs_file, new_length); 781 if (rc) { 782 ecryptfs_printk(KERN_ERR, 783 "Problem with fill_zeros\n"); 784 goto out_fput; 785 } 786 i_size_write(inode, new_length); |
784 rc = ecryptfs_write_inode_size_to_header(lower_file, 785 lower_dentry->d_inode, 786 inode); | 787 rc = ecryptfs_write_inode_size_to_metadata( 788 lower_file, lower_dentry->d_inode, inode, dentry, 789 ECRYPTFS_LOWER_I_MUTEX_NOT_HELD); |
787 if (rc) { | 790 if (rc) { |
788 ecryptfs_printk(KERN_ERR, 789 "Problem with ecryptfs_write" 790 "_inode_size\n"); | 791 printk(KERN_ERR "Problem with " 792 "ecryptfs_write_inode_size_to_metadata; " 793 "rc = [%d]\n", rc); |
791 goto out_fput; 792 } 793 } else { /* new_length < i_size_read(inode) */ 794 vmtruncate(inode, new_length); | 794 goto out_fput; 795 } 796 } else { /* new_length < i_size_read(inode) */ 797 vmtruncate(inode, new_length); |
795 ecryptfs_write_inode_size_to_header(lower_file, 796 lower_dentry->d_inode, 797 inode); | 798 rc = ecryptfs_write_inode_size_to_metadata( 799 lower_file, lower_dentry->d_inode, inode, dentry, 800 ECRYPTFS_LOWER_I_MUTEX_NOT_HELD); 801 if (rc) { 802 printk(KERN_ERR "Problem with " 803 "ecryptfs_write_inode_size_to_metadata; " 804 "rc = [%d]\n", rc); 805 goto out_fput; 806 } |
798 /* We are reducing the size of the ecryptfs file, and need to 799 * know if we need to reduce the size of the lower file. */ 800 lower_size_before_truncate = 801 upper_size_to_lower_size(crypt_stat, i_size); 802 lower_size_after_truncate = 803 upper_size_to_lower_size(crypt_stat, new_length); 804 if (lower_size_after_truncate < lower_size_before_truncate) 805 vmtruncate(lower_dentry->d_inode, --- 70 unchanged lines hidden (view full) --- 876 goto out; 877 } 878 rc = notify_change(lower_dentry, ia); 879out: 880 fsstack_copy_attr_all(inode, lower_inode, NULL); 881 return rc; 882} 883 | 807 /* We are reducing the size of the ecryptfs file, and need to 808 * know if we need to reduce the size of the lower file. */ 809 lower_size_before_truncate = 810 upper_size_to_lower_size(crypt_stat, i_size); 811 lower_size_after_truncate = 812 upper_size_to_lower_size(crypt_stat, new_length); 813 if (lower_size_after_truncate < lower_size_before_truncate) 814 vmtruncate(lower_dentry->d_inode, --- 70 unchanged lines hidden (view full) --- 885 goto out; 886 } 887 rc = notify_change(lower_dentry, ia); 888out: 889 fsstack_copy_attr_all(inode, lower_inode, NULL); 890 return rc; 891} 892 |
884static int | 893int |
885ecryptfs_setxattr(struct dentry *dentry, const char *name, const void *value, 886 size_t size, int flags) 887{ 888 int rc = 0; 889 struct dentry *lower_dentry; 890 891 lower_dentry = ecryptfs_dentry_to_lower(dentry); 892 if (!lower_dentry->d_inode->i_op->setxattr) { 893 rc = -ENOSYS; 894 goto out; 895 } 896 mutex_lock(&lower_dentry->d_inode->i_mutex); 897 rc = lower_dentry->d_inode->i_op->setxattr(lower_dentry, name, value, 898 size, flags); 899 mutex_unlock(&lower_dentry->d_inode->i_mutex); 900out: 901 return rc; 902} 903 | 894ecryptfs_setxattr(struct dentry *dentry, const char *name, const void *value, 895 size_t size, int flags) 896{ 897 int rc = 0; 898 struct dentry *lower_dentry; 899 900 lower_dentry = ecryptfs_dentry_to_lower(dentry); 901 if (!lower_dentry->d_inode->i_op->setxattr) { 902 rc = -ENOSYS; 903 goto out; 904 } 905 mutex_lock(&lower_dentry->d_inode->i_mutex); 906 rc = lower_dentry->d_inode->i_op->setxattr(lower_dentry, name, value, 907 size, flags); 908 mutex_unlock(&lower_dentry->d_inode->i_mutex); 909out: 910 return rc; 911} 912 |
904static ssize_t | 913ssize_t |
905ecryptfs_getxattr(struct dentry *dentry, const char *name, void *value, 906 size_t size) 907{ 908 int rc = 0; 909 struct dentry *lower_dentry; 910 911 lower_dentry = ecryptfs_dentry_to_lower(dentry); 912 if (!lower_dentry->d_inode->i_op->getxattr) { --- 99 unchanged lines hidden --- | 914ecryptfs_getxattr(struct dentry *dentry, const char *name, void *value, 915 size_t size) 916{ 917 int rc = 0; 918 struct dentry *lower_dentry; 919 920 lower_dentry = ecryptfs_dentry_to_lower(dentry); 921 if (!lower_dentry->d_inode->i_op->getxattr) { --- 99 unchanged lines hidden --- |