ecryptfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jason Xing <kerneljasonxing@gmail.com>
To: ecryptfs@vger.kernel.org
Cc: tyhicks@canonical.com, linux-kernel@vger.kernel.org,
	Jason Xing <kerneljasonxing@gmail.com>
Subject: [PATCH] ecryptfs: Fix stat command displays wrong file size in xattr region
Date: Thu, 22 Jun 2017 15:21:15 +0800	[thread overview]
Message-ID: <1498116075-2195-1-git-send-email-kerneljasonxing@gmail.com> (raw)

When doing ecryptfs_read_and_validate_xattr_region(), eCryptfs
reads only 16 bytes from xattr region. However, the lower filesystem
like ext4 always compares 16 with the size of ecryptfs xattr region
which is 81 bytes, and then it will return ERANGE (-34) and do not
read that region.

Signed-off-by: Jason Xing <kerneljasonxing@gmail.com>
---
 fs/ecryptfs/crypto.c | 33 +++++++++++++++++++++++++--------
 1 file changed, 25 insertions(+), 8 deletions(-)

diff --git a/fs/ecryptfs/crypto.c b/fs/ecryptfs/crypto.c
index e5e29f8..895140f 100644
--- a/fs/ecryptfs/crypto.c
+++ b/fs/ecryptfs/crypto.c
@@ -1389,19 +1389,36 @@ int ecryptfs_read_xattr_region(char *page_virt, struct inode *ecryptfs_inode)
 int ecryptfs_read_and_validate_xattr_region(struct dentry *dentry,
 					    struct inode *inode)
 {
-	u8 file_size[ECRYPTFS_SIZE_AND_MARKER_BYTES];
-	u8 *marker = file_size + ECRYPTFS_FILE_SIZE_BYTES;
+	char *page_virt;
 	int rc;
 
+	page_virt = kmem_cache_alloc(ecryptfs_header_cache, GFP_USER);
+	if (!page_virt) {
+		rc = -ENOMEM;
+		printk(KERN_ERR "%s: Unable to allocate page_virt\n",
+		       __func__);
+		goto out;
+	}
 	rc = ecryptfs_getxattr_lower(ecryptfs_dentry_to_lower(dentry),
 				     ecryptfs_inode_to_lower(inode),
-				     ECRYPTFS_XATTR_NAME, file_size,
-				     ECRYPTFS_SIZE_AND_MARKER_BYTES);
-	if (rc < ECRYPTFS_SIZE_AND_MARKER_BYTES)
-		return rc >= 0 ? -EINVAL : rc;
-	rc = ecryptfs_validate_marker(marker);
+				     ECRYPTFS_XATTR_NAME, page_virt,
+				     ECRYPTFS_DEFAULT_EXTENT_SIZE);
+	if (rc < 0) {
+		if (unlikely(ecryptfs_verbosity > 0))
+			printk(KERN_INFO "Error attempting to read the [%s] "
+			       "xattr from the lower file; return value = "
+			       "[%d]\n", ECRYPTFS_XATTR_NAME, rc);
+		rc = -EINVAL;
+		goto out;
+	}
+	rc = ecryptfs_validate_marker(page_virt + ECRYPTFS_FILE_SIZE_BYTES);
 	if (!rc)
-		ecryptfs_i_size_init(file_size, inode);
+		ecryptfs_i_size_init(page_virt, inode);
+out:
+	if (page_virt) {
+		memset(page_virt, 0, PAGE_SIZE);
+		kmem_cache_free(ecryptfs_header_cache, page_virt);
+	}
 	return rc;
 }
 
-- 
2.7.4

             reply	other threads:[~2017-06-22  7:23 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-06-22  7:21 Jason Xing [this message]
2017-10-14  3:00 ` [PATCH] ecryptfs: Fix stat command displays wrong file size in xattr region Jason Xing
2017-11-08  0:22 ` Tyler Hicks

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=1498116075-2195-1-git-send-email-kerneljasonxing@gmail.com \
    --to=kerneljasonxing@gmail.com \
    --cc=ecryptfs@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=tyhicks@canonical.com \
    /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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).