static int ecryptfs_update_crypt_flag(struct dentry *dentry, int is_sensitive) { int rc = 0; struct inode *inode; struct inode *lower_inode; struct ecryptfs_crypt_stat *crypt_stat; u32 tmp_flags; crypt_stat = &ecryptfs_inode_to_private(dentry->d_inode)->crypt_stat; if (!(crypt_stat->flags & ECRYPTFS_STRUCT_INITIALIZED)) ecryptfs_init_crypt_stat(crypt_stat); inode = dentry->d_inode; lower_inode = ecryptfs_inode_to_lower(inode); mutex_lock(&crypt_stat->cs_mutex); rc = ecryptfs_get_lower_file(dentry, inode); if (rc) { mutex_unlock(&crypt_stat->cs_mutex); DEK_LOGE("ecryptfs_get_lower_file rc=%d\n", rc); goto out; } tmp_flags = crypt_stat->flags; if (is_sensitive) { crypt_stat->flags |= ECRYPTFS_DEK_IS_SENSITIVE; /* * Set sensirive for all the pages in the inode */ set_sensitive_mapping_pages(inode->i_mapping, 0, -1); } else{ crypt_stat->flags &= ~ECRYPTFS_DEK_IS_SENSITIVE; } rc = ecryptfs_write_metadata(dentry, inode); if (rc) { crypt_stat->flags = tmp_flags; mutex_unlock(&crypt_stat->cs_mutex); DEK_LOGE("ecryptfs_write_metadata rc=%d\n", rc); goto out; } rc = ecryptfs_write_inode_size_to_metadata(inode); if (rc) { mutex_unlock(&crypt_stat->cs_mutex); DEK_LOGE("Problem with " "ecryptfs_write_inode_size_to_metadata; " "rc = [%d]\n", rc); goto out; } ecryptfs_put_lower_file(inode); mutex_unlock(&crypt_stat->cs_mutex); out: fsstack_copy_attr_all(inode, lower_inode); return rc; }
/** * ecryptfs_alloc_inode - allocate an ecryptfs inode * @sb: Pointer to the ecryptfs super block * * Called to bring an inode into existence. * * Only handle allocation, setting up structures should be done in * ecryptfs_read_inode. This is because the kernel, between now and * then, will 0 out the private data pointer. * * Returns a pointer to a newly allocated inode, NULL otherwise */ static struct inode *ecryptfs_alloc_inode(struct super_block *sb) { struct ecryptfs_inode_info *inode_info; struct inode *inode = NULL; inode_info = kmem_cache_alloc(ecryptfs_inode_info_cache, GFP_KERNEL); if (unlikely(!inode_info)) goto out; ecryptfs_init_crypt_stat(&inode_info->crypt_stat); mutex_init(&inode_info->lower_file_mutex); inode_info->lower_file = NULL; inode = &inode_info->vfs_inode; out: return inode; }
static int ecryptfs_update_crypt_flag(struct dentry *dentry, int is_sensitive) { int rc = 0; struct dentry *lower_dentry; struct inode *inode; struct inode *lower_inode; struct ecryptfs_crypt_stat *crypt_stat; struct ecryptfs_mount_crypt_stat *mount_crypt_stat; crypt_stat = &ecryptfs_inode_to_private(dentry->d_inode)->crypt_stat; if (!(crypt_stat->flags & ECRYPTFS_STRUCT_INITIALIZED)) ecryptfs_init_crypt_stat(crypt_stat); inode = dentry->d_inode; lower_inode = ecryptfs_inode_to_lower(inode); lower_dentry = ecryptfs_dentry_to_lower(dentry); mutex_lock(&crypt_stat->cs_mutex); mount_crypt_stat = &ecryptfs_superblock_to_private( dentry->d_sb)->mount_crypt_stat; rc = ecryptfs_get_lower_file(dentry, inode); if (rc) { mutex_unlock(&crypt_stat->cs_mutex); DEK_LOGE("ecryptfs_get_lower_file rc=%d\n", rc); goto out; } if (is_sensitive) { crypt_stat->flags |= ECRYPTFS_DEK_IS_SENSITIVE; /* * Set sensirive for all the pages in the inode */ set_sensitive_mapping_pages(inode->i_mapping, 0, -1); } else{ crypt_stat->flags &= ~ECRYPTFS_DEK_IS_SENSITIVE; } rc = ecryptfs_write_metadata(dentry, inode); if (rc) { if (!(mount_crypt_stat->flags & ECRYPTFS_PLAINTEXT_PASSTHROUGH_ENABLED)) { rc = -EIO; DEK_LOGE("Either the lower file " "is not in a valid eCryptfs format, " "or the key could not be retrieved. " "Plaintext passthrough mode is not " "enabled; returning -EIO\n"); mutex_unlock(&crypt_stat->cs_mutex); DEK_LOGD("ecryptfs_write_metadata rc=%d\n", rc); goto out; } rc = 0; crypt_stat->flags &= ~(ECRYPTFS_I_SIZE_INITIALIZED | ECRYPTFS_ENCRYPTED); } rc = ecryptfs_write_inode_size_to_metadata(inode); if (rc) { mutex_unlock(&crypt_stat->cs_mutex); DEK_LOGE("Problem with " "ecryptfs_write_inode_size_to_metadata; " "rc = [%d]\n", rc); goto out; } ecryptfs_put_lower_file(inode); mutex_unlock(&crypt_stat->cs_mutex); out: fsstack_copy_attr_all(inode, lower_inode); return rc; }