linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] fuse: do not write whole page while page straddles i_size
@ 2019-04-17 20:04 Liu Bo
  2019-04-18 11:19 ` Miklos Szeredi
  0 siblings, 1 reply; 3+ messages in thread
From: Liu Bo @ 2019-04-17 20:04 UTC (permalink / raw)
  To: linux-fsdevel; +Cc: Miklos Szeredi

From: Xiaoguang Wang <xiaoguang.wang@linux.alibaba.com>

If page straddles i_size and we write the whole page, the fuse
user-space filesystem may extend file size, it will confuse users.

Before this patch:
xfs_io -t -f \
        -c "truncate 5120" \
        -c "pwrite -S 0x58 0 5120"      \
        -c "mmap -rw 0 5120"            \
        -c "mwrite -S 0x59 2048 3072" \
        -c "close"      \
        testfile
testfile's length will be 8192 bytes, with this patch, testfile's
length will be 5120 bytes.

Signed-off-by: Xiaoguang Wang <xiaoguang.wang@linux.alibaba.com>
Signed-off-by: Liu Bo <bo.liu@linux.alibaba.com>
---
 fs/fuse/file.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/fs/fuse/file.c b/fs/fuse/file.c
index 06096b60f1df..44e76b00e985 100644
--- a/fs/fuse/file.c
+++ b/fs/fuse/file.c
@@ -1863,6 +1863,8 @@ static int fuse_writepages_fill(struct page *page,
 	struct page *tmp_page;
 	bool is_writeback;
 	int err;
+	loff_t size;
+	unsigned int len;
 
 	if (!data->ff) {
 		err = -EIO;
@@ -1940,7 +1942,12 @@ static int fuse_writepages_fill(struct page *page,
 	copy_highpage(tmp_page, page);
 	req->pages[req->num_pages] = tmp_page;
 	req->page_descs[req->num_pages].offset = 0;
-	req->page_descs[req->num_pages].length = PAGE_SIZE;
+	size = i_size_read(inode);
+	if (page->index == size >> PAGE_SHIFT)
+		len = size & ~PAGE_MASK;
+	else
+		len = PAGE_SIZE;
+	req->page_descs[req->num_pages].length = len;
 
 	inc_wb_stat(&inode_to_bdi(inode)->wb, WB_WRITEBACK);
 	inc_node_page_state(tmp_page, NR_WRITEBACK_TEMP);
-- 
2.20.1.2.gb21ebb6


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] fuse: do not write whole page while page straddles i_size
  2019-04-17 20:04 [PATCH] fuse: do not write whole page while page straddles i_size Liu Bo
@ 2019-04-18 11:19 ` Miklos Szeredi
  2019-04-18 20:30   ` Liu Bo
  0 siblings, 1 reply; 3+ messages in thread
From: Miklos Szeredi @ 2019-04-18 11:19 UTC (permalink / raw)
  To: Liu Bo; +Cc: linux-fsdevel, Miklos Szeredi

On Wed, Apr 17, 2019 at 10:04 PM Liu Bo <bo.liu@linux.alibaba.com> wrote:
>
> From: Xiaoguang Wang <xiaoguang.wang@linux.alibaba.com>
>
> If page straddles i_size and we write the whole page, the fuse
> user-space filesystem may extend file size, it will confuse users.
>
> Before this patch:
> xfs_io -t -f \
>         -c "truncate 5120" \
>         -c "pwrite -S 0x58 0 5120"      \
>         -c "mmap -rw 0 5120"            \
>         -c "mwrite -S 0x59 2048 3072" \
>         -c "close"      \
>         testfile
> testfile's length will be 8192 bytes, with this patch, testfile's
> length will be 5120 bytes.

Cannot reproduce this.  The file size should be cropped in
fuse_flush_writepages() and the above test case produces the expected
result, so I'm not sure how were you able to get 8192 byte file.

Thanks,
Miklos

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] fuse: do not write whole page while page straddles i_size
  2019-04-18 11:19 ` Miklos Szeredi
@ 2019-04-18 20:30   ` Liu Bo
  0 siblings, 0 replies; 3+ messages in thread
From: Liu Bo @ 2019-04-18 20:30 UTC (permalink / raw)
  To: Miklos Szeredi; +Cc: linux-fsdevel, Miklos Szeredi

On Thu, Apr 18, 2019 at 01:19:10PM +0200, Miklos Szeredi wrote:
> On Wed, Apr 17, 2019 at 10:04 PM Liu Bo <bo.liu@linux.alibaba.com> wrote:
> >
> > From: Xiaoguang Wang <xiaoguang.wang@linux.alibaba.com>
> >
> > If page straddles i_size and we write the whole page, the fuse
> > user-space filesystem may extend file size, it will confuse users.
> >
> > Before this patch:
> > xfs_io -t -f \
> >         -c "truncate 5120" \
> >         -c "pwrite -S 0x58 0 5120"      \
> >         -c "mmap -rw 0 5120"            \
> >         -c "mwrite -S 0x59 2048 3072" \
> >         -c "close"      \
> >         testfile
> > testfile's length will be 8192 bytes, with this patch, testfile's
> > length will be 5120 bytes.
> 
> Cannot reproduce this.  The file size should be cropped in
> fuse_flush_writepages() and the above test case produces the expected
> result, so I'm not sure how were you able to get 8192 byte file.

Hmm, this was found by fstests while testing against virtiofs 0.1
daemon code, which doesn't handle file size from fuse_in_head.  but
now with 0.2, /me couldn't reproduce it, either.

Please ignore the patch as well.

thanks,
-liubo

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2019-04-18 20:30 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-04-17 20:04 [PATCH] fuse: do not write whole page while page straddles i_size Liu Bo
2019-04-18 11:19 ` Miklos Szeredi
2019-04-18 20:30   ` Liu Bo

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 NNTP newsgroup(s).