public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Michael Halcrow <mhalcrow@us.ibm.com>
To: akpm@osdl.org
Cc: LKML <linux-kernel@vger.kernel.org>
Subject: [PATCH] eCryptfs: readdir fix for seeking in directory streams
Date: Mon, 25 Sep 2006 15:48:47 -0500	[thread overview]
Message-ID: <20060925204846.GA3356@us.ibm.com> (raw)

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 <mhalcrow@us.ibm.com>

---

 fs/ecryptfs/file.c |   11 ++++++-----
 1 files changed, 6 insertions(+), 5 deletions(-)

1824c175c78c15138a900aa4e05fd29af21d4de1
diff --git a/fs/ecryptfs/file.c b/fs/ecryptfs/file.c
index 53dd53d..1cc2cc0 100644
--- a/fs/ecryptfs/file.c
+++ b/fs/ecryptfs/file.c
@@ -144,7 +144,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,
@@ -176,6 +175,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;
@@ -218,18 +218,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;
 	mutex_lock(&crypt_stat->cs_mutex);
-- 
1.3.3


                 reply	other threads:[~2006-09-25 20:49 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20060925204846.GA3356@us.ibm.com \
    --to=mhalcrow@us.ibm.com \
    --cc=akpm@osdl.org \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox