From: Michael Halcrow 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 Signed-off-by: Andrew Morton --- fs/ecryptfs/file.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff -puN fs/ecryptfs/file.c~ecryptfs-file-operations-readdir-fix-for-seeking-in-directory-streams fs/ecryptfs/file.c --- a/fs/ecryptfs/file.c~ecryptfs-file-operations-readdir-fix-for-seeking-in-directory-streams +++ a/fs/ecryptfs/file.c @@ -137,7 +137,6 @@ ecryptfs_filldir(void *dirent, const cha int 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, @@ -169,6 +168,7 @@ static int ecryptfs_readdir(struct file struct 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; @@ -211,18 +211,19 @@ static int ecryptfs_open(struct inode *i struct 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; if (!ECRYPTFS_CHECK_FLAG(crypt_stat->flags, ECRYPTFS_POLICY_APPLIED)) { _