From: Li Wang <liwang@nudt.edu.cn>
To: Tyler Hicks <tyhicks@canonical.com>
Cc: ecryptfs@vger.kernel.org, linux-kernel@vger.kernel.org,
Li Wang <liwang@nudt.edu.cn>,
Yunchuan Wen <wenyunchuan@kylinos.com.cn>
Subject: [PATCH 1/3] eCryptfs: Write bug for non-ecryptfs file
Date: Fri, 17 Feb 2012 00:36:48 +0800 [thread overview]
Message-ID: <529380691.15452@eyou.net> (raw)
Message-ID: <1329410210-2712-1-git-send-email-liwang@nudt.edu.cn> (raw)
The following code segment in ecryptfs_write_begin(mmap.c) is problematic,
1 if (!PageUptodate(page)) {
2 if (!(crypt_stat->flags & ECRYPTFS_ENCRYPTED)) {
3 ...
4 } else if(crypt_stat->flags & ECRYPTFS_VIEW_AS_ENCRYPTED) {
5 ...
6 } else {
7 if (prev_page_end_size >= i_size_read(page->mapping->host)) {
8 zero_user(page, 0, PAGE_CACHE_SIZE);
9 }
10 ...
11 }
12 ...
13 /* Writing to a new page, and creating a small hole from start
14 * of page? Zero it out. */
15 if ((i_size_read(mapping->host)==prev_page_end_size) && (pos!=0))
16 zero_user(page, 0, PAGE_CACHE_SIZE);
1 The check on 'pos!=0' for the IF statement in line 15 implies that while
pos==0, the page needs not be zeroed. Unfortunately, that is not true,
suppose an empty non-ecryptfs file has been created beforehand, currently the
writter want to write at pos==0 with a length of m bytes, m<PAGE_CACHE_SIZE,
now the page will not be zeroed, and set to Uptodate! Then the data within
(m,PAGE_CACHE_SIZE) read by any reader will be undefined.
2 Even remove 'pos!=0', there is further more a case which does not be taken
into account,
if a file satisfies (i_size_read(mapping->host) > prev_page_end_size), and is
non-ecryptfs file, then the page is not zeroed, but the data within
(i_size_read(mapping->host), (prev_page_end_size+1)<<PAGE_CACHE_SHIFT) need
be zeroed as well.
3 For ecryptfs file, if satisfies (prev_page_end_size == i_size_read(page->
mapping->host) && pos!=0, this page will be double zeroed.
This patch solves the above problem.
Signed-off-by: Li Wang <liwang@nudt.edu.cn>
Signed-off-by: Yunchuan Wen <wenyunchuan@kylinos.com.cn>
---
fs/ecryptfs/mmap.c | 7 ++-----
1 files changed, 2 insertions(+), 5 deletions(-)
diff --git a/fs/ecryptfs/mmap.c b/fs/ecryptfs/mmap.c
index 10ec695..27c0da8 100644
--- a/fs/ecryptfs/mmap.c
+++ b/fs/ecryptfs/mmap.c
@@ -308,6 +308,8 @@ static int ecryptfs_write_begin(struct file *file,
&ecryptfs_inode_to_private(mapping->host)->crypt_stat;
if (!(crypt_stat->flags & ECRYPTFS_ENCRYPTED)) {
+ if ((i_size_read(mapping->host) >> PAGE_CACHE_SHIFT) <= index)
+ zero_user(page, 0, PAGE_CACHE_SIZE);
rc = ecryptfs_read_lower_page_segment(
page, index, 0, PAGE_CACHE_SIZE, mapping->host);
if (rc) {
@@ -379,11 +381,6 @@ static int ecryptfs_write_begin(struct file *file,
}
}
}
- /* Writing to a new page, and creating a small hole from start
- * of page? Zero it out. */
- if ((i_size_read(mapping->host) == prev_page_end_size)
- && (pos != 0))
- zero_user(page, 0, PAGE_CACHE_SIZE);
out:
if (unlikely(rc)) {
unlock_page(page);
--
1.7.6.5
WARNING: multiple messages have this Message-ID (diff)
From: Li Wang <liwang@nudt.edu.cn>
To: Tyler Hicks <tyhicks@canonical.com>
Cc: <ecryptfs@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
Li Wang <liwang@nudt.edu.cn>,
Yunchuan Wen <wenyunchuan@kylinos.com.cn>
Subject: [PATCH 1/3] eCryptfs: Write bug for non-ecryptfs file
Date: Fri, 17 Feb 2012 00:36:48 +0800 [thread overview]
Message-ID: <529380691.15452@eyou.net> (raw)
Message-ID: <1329410210-2712-1-git-send-email-liwang@nudt.edu.cn> (raw)
The following code segment in ecryptfs_write_begin(mmap.c) is problematic,
1 if (!PageUptodate(page)) {
2 if (!(crypt_stat->flags & ECRYPTFS_ENCRYPTED)) {
3 ...
4 } else if(crypt_stat->flags & ECRYPTFS_VIEW_AS_ENCRYPTED) {
5 ...
6 } else {
7 if (prev_page_end_size >= i_size_read(page->mapping->host)) {
8 zero_user(page, 0, PAGE_CACHE_SIZE);
9 }
10 ...
11 }
12 ...
13 /* Writing to a new page, and creating a small hole from start
14 * of page? Zero it out. */
15 if ((i_size_read(mapping->host)==prev_page_end_size) && (pos!=0))
16 zero_user(page, 0, PAGE_CACHE_SIZE);
1 The check on 'pos!=0' for the IF statement in line 15 implies that while
pos==0, the page needs not be zeroed. Unfortunately, that is not true,
suppose an empty non-ecryptfs file has been created beforehand, currently the
writter want to write at pos==0 with a length of m bytes, m<PAGE_CACHE_SIZE,
now the page will not be zeroed, and set to Uptodate! Then the data within
(m,PAGE_CACHE_SIZE) read by any reader will be undefined.
2 Even remove 'pos!=0', there is further more a case which does not be taken
into account,
if a file satisfies (i_size_read(mapping->host) > prev_page_end_size), and is
non-ecryptfs file, then the page is not zeroed, but the data within
(i_size_read(mapping->host), (prev_page_end_size+1)<<PAGE_CACHE_SHIFT) need
be zeroed as well.
3 For ecryptfs file, if satisfies (prev_page_end_size == i_size_read(page->
mapping->host) && pos!=0, this page will be double zeroed.
This patch solves the above problem.
Signed-off-by: Li Wang <liwang@nudt.edu.cn>
Signed-off-by: Yunchuan Wen <wenyunchuan@kylinos.com.cn>
---
fs/ecryptfs/mmap.c | 7 ++-----
1 files changed, 2 insertions(+), 5 deletions(-)
diff --git a/fs/ecryptfs/mmap.c b/fs/ecryptfs/mmap.c
index 10ec695..27c0da8 100644
--- a/fs/ecryptfs/mmap.c
+++ b/fs/ecryptfs/mmap.c
@@ -308,6 +308,8 @@ static int ecryptfs_write_begin(struct file *file,
&ecryptfs_inode_to_private(mapping->host)->crypt_stat;
if (!(crypt_stat->flags & ECRYPTFS_ENCRYPTED)) {
+ if ((i_size_read(mapping->host) >> PAGE_CACHE_SHIFT) <= index)
+ zero_user(page, 0, PAGE_CACHE_SIZE);
rc = ecryptfs_read_lower_page_segment(
page, index, 0, PAGE_CACHE_SIZE, mapping->host);
if (rc) {
@@ -379,11 +381,6 @@ static int ecryptfs_write_begin(struct file *file,
}
}
}
- /* Writing to a new page, and creating a small hole from start
- * of page? Zero it out. */
- if ((i_size_read(mapping->host) == prev_page_end_size)
- && (pos != 0))
- zero_user(page, 0, PAGE_CACHE_SIZE);
out:
if (unlikely(rc)) {
unlock_page(page);
--
1.7.6.5
next reply other threads:[~2012-02-16 8:42 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-02-16 16:36 Li Wang [this message]
2012-02-16 16:36 ` [PATCH 1/3] eCryptfs: Write bug for non-ecryptfs file Li Wang
2012-02-16 16:36 ` Li Wang
2012-02-16 16:36 ` [PATCH 2/3] eCryptfs: Remove redundant IF statement Li Wang
2012-02-16 16:36 ` Li Wang
2012-02-16 16:36 ` Li Wang
2012-02-16 16:36 ` [PATCH 3/3] eCryptfs: Remove unreached codes Li Wang
2012-02-16 16:36 ` Li Wang
2012-02-16 16:36 ` Li Wang
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=529380691.15452@eyou.net \
--to=liwang@nudt.edu.cn \
--cc=ecryptfs@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=tyhicks@canonical.com \
--cc=wenyunchuan@kylinos.com.cn \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.