Skip to content

Commit 410fc4c

Browse files
committed
Merge tag 'ecryptfs-3.6-rc1-fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/tyhicks/ecryptfs
Pull ecryptfs fixes from Tyler Hicks: - Fixes a bug when the lower filesystem mount options include 'acl', but the eCryptfs mount options do not - Cleanups in the messaging code - Better handling of empty files in the lower filesystem to improve usability. Failed file creations are now cleaned up and empty lower files are converted into eCryptfs during open(). - The write-through cache changes are being reverted due to bugs that are not easy to fix. Stability outweighs the performance enhancements here. - Improvement to the mount code to catch unsupported ciphers specified in the mount options * tag 'ecryptfs-3.6-rc1-fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/tyhicks/ecryptfs: eCryptfs: check for eCryptfs cipher support at mount eCryptfs: Revert to a writethrough cache model eCryptfs: Initialize empty lower files when opening them eCryptfs: Unlink lower inode when ecryptfs_create() fails eCryptfs: Make all miscdev functions use daemon ptr in file private_data eCryptfs: Remove unused messaging declarations and function eCryptfs: Copy up POSIX ACL and read-only flags from lower mount
2 parents 630103e + 5f5b331 commit 410fc4c

7 files changed

Lines changed: 158 additions & 316 deletions

File tree

‎fs/ecryptfs/ecryptfs_kernel.h‎

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -385,19 +385,14 @@ struct ecryptfs_msg_ctx {
385385
struct mutex mux;
386386
};
387387

388-
struct ecryptfs_daemon;
389-
390388
struct ecryptfs_daemon {
391389
#define ECRYPTFS_DAEMON_IN_READ 0x00000001
392390
#define ECRYPTFS_DAEMON_IN_POLL 0x00000002
393391
#define ECRYPTFS_DAEMON_ZOMBIE 0x00000004
394392
#define ECRYPTFS_DAEMON_MISCDEV_OPEN 0x00000008
395393
u32 flags;
396394
u32 num_queued_msg_ctx;
397-
struct pid *pid;
398-
uid_t euid;
399-
struct user_namespace *user_ns;
400-
struct task_struct *task;
395+
struct file *file;
401396
struct mutex mux;
402397
struct list_head msg_ctx_out_queue;
403398
wait_queue_head_t wait;
@@ -554,6 +549,8 @@ extern struct kmem_cache *ecryptfs_key_tfm_cache;
554549
struct inode *ecryptfs_get_inode(struct inode *lower_inode,
555550
struct super_block *sb);
556551
void ecryptfs_i_size_init(const char *page_virt, struct inode *inode);
552+
int ecryptfs_initialize_file(struct dentry *ecryptfs_dentry,
553+
struct inode *ecryptfs_inode);
557554
int ecryptfs_decode_and_decrypt_filename(char **decrypted_name,
558555
size_t *decrypted_name_size,
559556
struct dentry *ecryptfs_dentry,
@@ -607,13 +604,8 @@ int
607604
ecryptfs_setxattr(struct dentry *dentry, const char *name, const void *value,
608605
size_t size, int flags);
609606
int ecryptfs_read_xattr_region(char *page_virt, struct inode *ecryptfs_inode);
610-
int ecryptfs_process_helo(uid_t euid, struct user_namespace *user_ns,
611-
struct pid *pid);
612-
int ecryptfs_process_quit(uid_t euid, struct user_namespace *user_ns,
613-
struct pid *pid);
614-
int ecryptfs_process_response(struct ecryptfs_message *msg, uid_t euid,
615-
struct user_namespace *user_ns, struct pid *pid,
616-
u32 seq);
607+
int ecryptfs_process_response(struct ecryptfs_daemon *daemon,
608+
struct ecryptfs_message *msg, u32 seq);
617609
int ecryptfs_send_message(char *data, int data_len,
618610
struct ecryptfs_msg_ctx **msg_ctx);
619611
int ecryptfs_wait_for_response(struct ecryptfs_msg_ctx *msg_ctx,
@@ -658,8 +650,7 @@ int ecryptfs_read_lower_page_segment(struct page *page_for_ecryptfs,
658650
struct inode *ecryptfs_inode);
659651
struct page *ecryptfs_get_locked_page(struct inode *inode, loff_t index);
660652
int ecryptfs_exorcise_daemon(struct ecryptfs_daemon *daemon);
661-
int ecryptfs_find_daemon_by_euid(struct ecryptfs_daemon **daemon, uid_t euid,
662-
struct user_namespace *user_ns);
653+
int ecryptfs_find_daemon_by_euid(struct ecryptfs_daemon **daemon);
663654
int ecryptfs_parse_packet_length(unsigned char *data, size_t *size,
664655
size_t *length_size);
665656
int ecryptfs_write_packet_length(char *dest, size_t size,
@@ -671,8 +662,7 @@ int ecryptfs_send_miscdev(char *data, size_t data_size,
671662
u16 msg_flags, struct ecryptfs_daemon *daemon);
672663
void ecryptfs_msg_ctx_alloc_to_free(struct ecryptfs_msg_ctx *msg_ctx);
673664
int
674-
ecryptfs_spawn_daemon(struct ecryptfs_daemon **daemon, uid_t euid,
675-
struct user_namespace *user_ns, struct pid *pid);
665+
ecryptfs_spawn_daemon(struct ecryptfs_daemon **daemon, struct file *file);
676666
int ecryptfs_init_kthread(void);
677667
void ecryptfs_destroy_kthread(void);
678668
int ecryptfs_privileged_open(struct file **lower_file,

‎fs/ecryptfs/file.c‎

Lines changed: 40 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -138,29 +138,50 @@ static int ecryptfs_readdir(struct file *file, void *dirent, filldir_t filldir)
138138
return rc;
139139
}
140140

141-
static void ecryptfs_vma_close(struct vm_area_struct *vma)
142-
{
143-
filemap_write_and_wait(vma->vm_file->f_mapping);
144-
}
145-
146-
static const struct vm_operations_struct ecryptfs_file_vm_ops = {
147-
.close = ecryptfs_vma_close,
148-
.fault = filemap_fault,
149-
};
141+
struct kmem_cache *ecryptfs_file_info_cache;
150142

151-
static int ecryptfs_file_mmap(struct file *file, struct vm_area_struct *vma)
143+
static int read_or_initialize_metadata(struct dentry *dentry)
152144
{
145+
struct inode *inode = dentry->d_inode;
146+
struct ecryptfs_mount_crypt_stat *mount_crypt_stat;
147+
struct ecryptfs_crypt_stat *crypt_stat;
153148
int rc;
154149

155-
rc = generic_file_mmap(file, vma);
150+
crypt_stat = &ecryptfs_inode_to_private(inode)->crypt_stat;
151+
mount_crypt_stat = &ecryptfs_superblock_to_private(
152+
inode->i_sb)->mount_crypt_stat;
153+
mutex_lock(&crypt_stat->cs_mutex);
154+
155+
if (crypt_stat->flags & ECRYPTFS_POLICY_APPLIED &&
156+
crypt_stat->flags & ECRYPTFS_KEY_VALID) {
157+
rc = 0;
158+
goto out;
159+
}
160+
161+
rc = ecryptfs_read_metadata(dentry);
156162
if (!rc)
157-
vma->vm_ops = &ecryptfs_file_vm_ops;
163+
goto out;
164+
165+
if (mount_crypt_stat->flags & ECRYPTFS_PLAINTEXT_PASSTHROUGH_ENABLED) {
166+
crypt_stat->flags &= ~(ECRYPTFS_I_SIZE_INITIALIZED
167+
| ECRYPTFS_ENCRYPTED);
168+
rc = 0;
169+
goto out;
170+
}
158171

172+
if (!(mount_crypt_stat->flags & ECRYPTFS_XATTR_METADATA_ENABLED) &&
173+
!i_size_read(ecryptfs_inode_to_lower(inode))) {
174+
rc = ecryptfs_initialize_file(dentry, inode);
175+
if (!rc)
176+
goto out;
177+
}
178+
179+
rc = -EIO;
180+
out:
181+
mutex_unlock(&crypt_stat->cs_mutex);
159182
return rc;
160183
}
161184

162-
struct kmem_cache *ecryptfs_file_info_cache;
163-
164185
/**
165186
* ecryptfs_open
166187
* @inode: inode speciying file to open
@@ -236,32 +257,9 @@ static int ecryptfs_open(struct inode *inode, struct file *file)
236257
rc = 0;
237258
goto out;
238259
}
239-
mutex_lock(&crypt_stat->cs_mutex);
240-
if (!(crypt_stat->flags & ECRYPTFS_POLICY_APPLIED)
241-
|| !(crypt_stat->flags & ECRYPTFS_KEY_VALID)) {
242-
rc = ecryptfs_read_metadata(ecryptfs_dentry);
243-
if (rc) {
244-
ecryptfs_printk(KERN_DEBUG,
245-
"Valid headers not found\n");
246-
if (!(mount_crypt_stat->flags
247-
& ECRYPTFS_PLAINTEXT_PASSTHROUGH_ENABLED)) {
248-
rc = -EIO;
249-
printk(KERN_WARNING "Either the lower file "
250-
"is not in a valid eCryptfs format, "
251-
"or the key could not be retrieved. "
252-
"Plaintext passthrough mode is not "
253-
"enabled; returning -EIO\n");
254-
mutex_unlock(&crypt_stat->cs_mutex);
255-
goto out_put;
256-
}
257-
rc = 0;
258-
crypt_stat->flags &= ~(ECRYPTFS_I_SIZE_INITIALIZED
259-
| ECRYPTFS_ENCRYPTED);
260-
mutex_unlock(&crypt_stat->cs_mutex);
261-
goto out;
262-
}
263-
}
264-
mutex_unlock(&crypt_stat->cs_mutex);
260+
rc = read_or_initialize_metadata(ecryptfs_dentry);
261+
if (rc)
262+
goto out_put;
265263
ecryptfs_printk(KERN_DEBUG, "inode w/ addr = [0x%p], i_ino = "
266264
"[0x%.16lx] size: [0x%.16llx]\n", inode, inode->i_ino,
267265
(unsigned long long)i_size_read(inode));
@@ -292,15 +290,7 @@ static int ecryptfs_release(struct inode *inode, struct file *file)
292290
static int
293291
ecryptfs_fsync(struct file *file, loff_t start, loff_t end, int datasync)
294292
{
295-
int rc = 0;
296-
297-
rc = generic_file_fsync(file, start, end, datasync);
298-
if (rc)
299-
goto out;
300-
rc = vfs_fsync_range(ecryptfs_file_to_lower(file), start, end,
301-
datasync);
302-
out:
303-
return rc;
293+
return vfs_fsync(ecryptfs_file_to_lower(file), datasync);
304294
}
305295

306296
static int ecryptfs_fasync(int fd, struct file *file, int flag)
@@ -369,7 +359,7 @@ const struct file_operations ecryptfs_main_fops = {
369359
#ifdef CONFIG_COMPAT
370360
.compat_ioctl = ecryptfs_compat_ioctl,
371361
#endif
372-
.mmap = ecryptfs_file_mmap,
362+
.mmap = generic_file_mmap,
373363
.open = ecryptfs_open,
374364
.flush = ecryptfs_flush,
375365
.release = ecryptfs_release,

‎fs/ecryptfs/inode.c‎

Lines changed: 34 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,31 @@ static int ecryptfs_interpose(struct dentry *lower_dentry,
143143
return 0;
144144
}
145145

146+
static int ecryptfs_do_unlink(struct inode *dir, struct dentry *dentry,
147+
struct inode *inode)
148+
{
149+
struct dentry *lower_dentry = ecryptfs_dentry_to_lower(dentry);
150+
struct inode *lower_dir_inode = ecryptfs_inode_to_lower(dir);
151+
struct dentry *lower_dir_dentry;
152+
int rc;
153+
154+
dget(lower_dentry);
155+
lower_dir_dentry = lock_parent(lower_dentry);
156+
rc = vfs_unlink(lower_dir_inode, lower_dentry);
157+
if (rc) {
158+
printk(KERN_ERR "Error in vfs_unlink; rc = [%d]\n", rc);
159+
goto out_unlock;
160+
}
161+
fsstack_copy_attr_times(dir, lower_dir_inode);
162+
set_nlink(inode, ecryptfs_inode_to_lower(inode)->i_nlink);
163+
inode->i_ctime = dir->i_ctime;
164+
d_drop(dentry);
165+
out_unlock:
166+
unlock_dir(lower_dir_dentry);
167+
dput(lower_dentry);
168+
return rc;
169+
}
170+
146171
/**
147172
* ecryptfs_do_create
148173
* @directory_inode: inode of the new file's dentry's parent in ecryptfs
@@ -182,8 +207,10 @@ ecryptfs_do_create(struct inode *directory_inode,
182207
}
183208
inode = __ecryptfs_get_inode(lower_dentry->d_inode,
184209
directory_inode->i_sb);
185-
if (IS_ERR(inode))
210+
if (IS_ERR(inode)) {
211+
vfs_unlink(lower_dir_dentry->d_inode, lower_dentry);
186212
goto out_lock;
213+
}
187214
fsstack_copy_attr_times(directory_inode, lower_dir_dentry->d_inode);
188215
fsstack_copy_inode_size(directory_inode, lower_dir_dentry->d_inode);
189216
out_lock:
@@ -200,8 +227,8 @@ ecryptfs_do_create(struct inode *directory_inode,
200227
*
201228
* Returns zero on success
202229
*/
203-
static int ecryptfs_initialize_file(struct dentry *ecryptfs_dentry,
204-
struct inode *ecryptfs_inode)
230+
int ecryptfs_initialize_file(struct dentry *ecryptfs_dentry,
231+
struct inode *ecryptfs_inode)
205232
{
206233
struct ecryptfs_crypt_stat *crypt_stat =
207234
&ecryptfs_inode_to_private(ecryptfs_inode)->crypt_stat;
@@ -264,7 +291,9 @@ ecryptfs_create(struct inode *directory_inode, struct dentry *ecryptfs_dentry,
264291
* that this on disk file is prepared to be an ecryptfs file */
265292
rc = ecryptfs_initialize_file(ecryptfs_dentry, ecryptfs_inode);
266293
if (rc) {
267-
drop_nlink(ecryptfs_inode);
294+
ecryptfs_do_unlink(directory_inode, ecryptfs_dentry,
295+
ecryptfs_inode);
296+
make_bad_inode(ecryptfs_inode);
268297
unlock_new_inode(ecryptfs_inode);
269298
iput(ecryptfs_inode);
270299
goto out;
@@ -466,27 +495,7 @@ static int ecryptfs_link(struct dentry *old_dentry, struct inode *dir,
466495

467496
static int ecryptfs_unlink(struct inode *dir, struct dentry *dentry)
468497
{
469-
int rc = 0;
470-
struct dentry *lower_dentry = ecryptfs_dentry_to_lower(dentry);
471-
struct inode *lower_dir_inode = ecryptfs_inode_to_lower(dir);
472-
struct dentry *lower_dir_dentry;
473-
474-
dget(lower_dentry);
475-
lower_dir_dentry = lock_parent(lower_dentry);
476-
rc = vfs_unlink(lower_dir_inode, lower_dentry);
477-
if (rc) {
478-
printk(KERN_ERR "Error in vfs_unlink; rc = [%d]\n", rc);
479-
goto out_unlock;
480-
}
481-
fsstack_copy_attr_times(dir, lower_dir_inode);
482-
set_nlink(dentry->d_inode,
483-
ecryptfs_inode_to_lower(dentry->d_inode)->i_nlink);
484-
dentry->d_inode->i_ctime = dir->i_ctime;
485-
d_drop(dentry);
486-
out_unlock:
487-
unlock_dir(lower_dir_dentry);
488-
dput(lower_dentry);
489-
return rc;
498+
return ecryptfs_do_unlink(dir, dentry, dentry->d_inode);
490499
}
491500

492501
static int ecryptfs_symlink(struct inode *dir, struct dentry *dentry,
@@ -961,12 +970,6 @@ static int ecryptfs_setattr(struct dentry *dentry, struct iattr *ia)
961970
goto out;
962971
}
963972

964-
if (S_ISREG(inode->i_mode)) {
965-
rc = filemap_write_and_wait(inode->i_mapping);
966-
if (rc)
967-
goto out;
968-
fsstack_copy_attr_all(inode, lower_inode);
969-
}
970973
memcpy(&lower_ia, ia, sizeof(lower_ia));
971974
if (ia->ia_valid & ATTR_FILE)
972975
lower_ia.ia_file = ecryptfs_file_to_lower(ia->ia_file);

‎fs/ecryptfs/main.c‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,7 @@ static int ecryptfs_parse_options(struct ecryptfs_sb_info *sbi, char *options,
279279
char *fnek_src;
280280
char *cipher_key_bytes_src;
281281
char *fn_cipher_key_bytes_src;
282+
u8 cipher_code;
282283

283284
*check_ruid = 0;
284285

@@ -420,6 +421,18 @@ static int ecryptfs_parse_options(struct ecryptfs_sb_info *sbi, char *options,
420421
&& !fn_cipher_key_bytes_set)
421422
mount_crypt_stat->global_default_fn_cipher_key_bytes =
422423
mount_crypt_stat->global_default_cipher_key_size;
424+
425+
cipher_code = ecryptfs_code_for_cipher_string(
426+
mount_crypt_stat->global_default_cipher_name,
427+
mount_crypt_stat->global_default_cipher_key_size);
428+
if (!cipher_code) {
429+
ecryptfs_printk(KERN_ERR,
430+
"eCryptfs doesn't support cipher: %s",
431+
mount_crypt_stat->global_default_cipher_name);
432+
rc = -EINVAL;
433+
goto out;
434+
}
435+
423436
mutex_lock(&key_tfm_list_mutex);
424437
if (!ecryptfs_tfm_exists(mount_crypt_stat->global_default_cipher_name,
425438
NULL)) {
@@ -540,6 +553,15 @@ static struct dentry *ecryptfs_mount(struct file_system_type *fs_type, int flags
540553
}
541554

542555
ecryptfs_set_superblock_lower(s, path.dentry->d_sb);
556+
557+
/**
558+
* Set the POSIX ACL flag based on whether they're enabled in the lower
559+
* mount. Force a read-only eCryptfs mount if the lower mount is ro.
560+
* Allow a ro eCryptfs mount even when the lower mount is rw.
561+
*/
562+
s->s_flags = flags & ~MS_POSIXACL;
563+
s->s_flags |= path.dentry->d_sb->s_flags & (MS_RDONLY | MS_POSIXACL);
564+
543565
s->s_maxbytes = path.dentry->d_sb->s_maxbytes;
544566
s->s_blocksize = path.dentry->d_sb->s_blocksize;
545567
s->s_magic = ECRYPTFS_SUPER_MAGIC;

0 commit comments

Comments
 (0)