lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <067f905e4f3b71727cfada291b090896463ef796.1726024117.git.bo.wu@vivo.com>
Date: Tue, 10 Sep 2024 21:57:22 -0600
From: Wu Bo <bo.wu@...o.com>
To: linux-kernel@...r.kernel.org
Cc: Jaegeuk Kim <jaegeuk@...nel.org>,
	Chao Yu <chao@...nel.org>,
	linux-f2fs-devel@...ts.sourceforge.net,
	Wu Bo <wubo.oduw@...il.com>,
	Wu Bo <bo.wu@...o.com>
Subject: [PATCH v2 09/13] f2fs: fix data loss during inline tail writing

This is detected by xfstest generic/114. The inline data needs to be
read out before writing to avoid losing the already inline data.

Signed-off-by: Wu Bo <bo.wu@...o.com>
---
 fs/f2fs/data.c | 3 ++-
 fs/f2fs/file.c | 7 ++++++-
 2 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c
index 476325a26d4e..275c5739993e 100644
--- a/fs/f2fs/data.c
+++ b/fs/f2fs/data.c
@@ -3477,7 +3477,8 @@ static int prepare_write_begin(struct f2fs_sb_info *sbi,
 			if (inode->i_nlink)
 				set_page_private_inline(ipage);
 			goto out;
-		}
+		} else if (f2fs_exist_data(inode))
+			f2fs_do_read_inline_data(page_folio(page), ipage);
 	}
 
 	if (!f2fs_lookup_read_extent_cache_block(inode, index,
diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c
index 2551403a5b83..64ea0bfc2e1e 100644
--- a/fs/f2fs/file.c
+++ b/fs/f2fs/file.c
@@ -4729,7 +4729,7 @@ static int f2fs_preallocate_blocks(struct kiocb *iocb, struct iov_iter *iter,
 
 	if (f2fs_has_inline_tail(inode) &&
 			(pos + count > MAX_INLINE_TAIL(inode))) {
-		ret = f2fs_clear_inline_tail(inode, true);
+		ret = f2fs_convert_inline_tail(inode);
 		if (ret)
 			return ret;
 	}
@@ -4842,6 +4842,7 @@ static ssize_t f2fs_dio_write_iter(struct kiocb *iocb, struct iov_iter *from,
 	if (iocb->ki_flags & IOCB_NOWAIT) {
 		/* f2fs_convert_inline_inode() and block allocation can block */
 		if (f2fs_has_inline_data(inode) ||
+		    f2fs_has_inline_tail(inode) ||
 		    !f2fs_overwrite_io(inode, pos, count)) {
 			ret = -EAGAIN;
 			goto out;
@@ -4861,6 +4862,10 @@ static ssize_t f2fs_dio_write_iter(struct kiocb *iocb, struct iov_iter *from,
 		if (ret)
 			goto out;
 
+		ret = f2fs_convert_inline_tail(inode);
+		if (ret)
+			goto out;
+
 		f2fs_down_read(&fi->i_gc_rwsem[WRITE]);
 		if (do_opu)
 			f2fs_down_read(&fi->i_gc_rwsem[READ]);
-- 
2.35.3


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ