eCryptfs: readdir fix for seeking in directory streams
PATCH 1/1 eCryptfs: readdir fix for seeking in directory streams
The lower file's f_pos needs to be set to the f_pos of the eCryptfs file passed into readdir() in order to correctly handle seeks on directory streams.
This patch also properly initializes the file_info struct to all 0's. This initialization is not strictly necessary for the code as it is currently in the kernel, but without this patch, nasty bugs can show up when anyone makes changes to the file_info struct (one such future change may include a pointer to persistent directory read state info).
Signed-off-by Michael Halcrow <[email protected]>
---
fs/ecryptfs/file.c | 11 ++++++----- 1 files changed, 6 insertions(+), 5 deletions(-)
1824c175c78c15138a900aa4e05fd29af21d4de1
fs/ecryptfs/file.c +6 -5
@@ -144,7 +144,6 @@ ecryptfs_filldir(void *dirent, const chaint decoded_length;char *decoded_name; - crypt_stat =ecryptfs_dentry_to_private (buf->dentry)->crypt_stat; buf->filldir_called++; decoded_length = ecryptfs_decode_filename(crypt_stat, name, namelen,
@@ -176,6 +175,7 @@ static int ecryptfs_readdir(struct filestruct ecryptfs_getdents_callback buf; lower_file =ecryptfs_file_to_lower (file); + lower_file->f_pos = file->f_pos; inode = file->f_dentry->d_inode;memset (&buf,0 ,sizeof (buf)); buf.dirent = dirent;
@@ -218,18 +218,19 @@ static int ecryptfs_open(struct inode *istruct inode *lower_inode =NULL ;struct file *lower_file =NULL ;struct vfsmount *lower_mnt; +struct ecryptfs_file_info *file_info;int lower_flags;/* Released in ecryptfs_release or end of function if failure */ -ecryptfs_set_file_private (file, -kmem_cache_alloc (ecryptfs_file_info_cache, -SLAB_KERNEL )); -if (!ecryptfs_file_to_private (file)) { + file_info =kmem_cache_alloc (ecryptfs_file_info_cache,SLAB_KERNEL ); +ecryptfs_set_file_private (file, file_info); +if (!file_info) {ecryptfs_printk (KERN_ERR ,"Error attempting to allocate memory\n" ); rc = -ENOMEM ; goto out; } +memset (file_info,0 ,sizeof (*file_info)); lower_dentry =ecryptfs_dentry_to_lower (ecryptfs_dentry); crypt_stat = &ecryptfs_inode_to_private (inode)->crypt_stat;mutex_lock (&crypt_stat->cs_mutex);
Signature · 1 line
1.3.3