linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Peng Hao <flyingpenghao@gmail.com>
To: miklos@szeredi.hu
Cc: linux-fsdevel@vger.kernel.org
Subject: [PATCH]  fuse: fix possible write position calculation error
Date: Tue, 26 Oct 2021 10:34:42 +0800	[thread overview]
Message-ID: <20211026023442.76544-1-flyingpeng@tencent.com> (raw)

The 'written' that generic_file_direct_write return through
filemap_write_and_wait_range is not necessarily sequential,
and its iocb->ki_pos has not been updated.

Signed-off-by: Peng Hao <flyingpeng@tencent.com>
---
 fs/fuse/file.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/fs/fuse/file.c b/fs/fuse/file.c
index 26730e699d68..52aaa1fb484d 100644
--- a/fs/fuse/file.c
+++ b/fs/fuse/file.c
@@ -1314,14 +1314,12 @@ static ssize_t fuse_cache_write_iter(struct kiocb *iocb, struct iov_iter *from)
 		goto out;
 
 	if (iocb->ki_flags & IOCB_DIRECT) {
-		loff_t pos = iocb->ki_pos;
+		loff_t pos;
 		written = generic_file_direct_write(iocb, from);
 		if (written < 0 || !iov_iter_count(from))
 			goto out;
 
-		pos += written;
-
-		written_buffered = fuse_perform_write(iocb, mapping, from, pos);
+		written_buffered = fuse_perform_write(iocb, mapping, from, pos = iocb->ki_pos);
 		if (written_buffered < 0) {
 			err = written_buffered;
 			goto out;
-- 
2.27.0


             reply	other threads:[~2021-10-26  2:35 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-26  2:34 Peng Hao [this message]
  -- strict thread matches above, loose matches on Subject: below --
2021-11-03  1:15 [PATCH] fuse: fix possible write position calculation error Peng Hao
2021-11-04 12:17 ` Miklos Szeredi
2021-11-05  7:43   ` Hao Peng
2021-11-10 10:40     ` Miklos Szeredi
2021-11-11  1:40       ` Hao Peng

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=20211026023442.76544-1-flyingpeng@tencent.com \
    --to=flyingpenghao@gmail.com \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=miklos@szeredi.hu \
    /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 NNTP newsgroup(s).