linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] exfat: fix file not locking when writing zeros in exfat_file_mmap()
@ 2024-01-24  5:00 Yuezhang.Mo
  2024-01-24  5:21 ` Matthew Wilcox
  0 siblings, 1 reply; 12+ messages in thread
From: Yuezhang.Mo @ 2024-01-24  5:00 UTC (permalink / raw)
  To: linkinjeon@kernel.org, sj1557.seo@samsung.com
  Cc: linux-fsdevel@vger.kernel.org, Andy.Wu@sony.com,
	Wataru.Aoyama@sony.com

[-- Attachment #1: Type: text/plain, Size: 917 bytes --]

inode->i_rwsem should be locked when writing file. But the lock
is missing when writing zeros to the file in exfat_file_mmap().

Fixes: 11a347fb6cef ("exfat: change to get file size from DataLength")
Signed-off-by: Yuezhang Mo <Yuezhang.Mo@sony.com>
---
 fs/exfat/file.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/fs/exfat/file.c b/fs/exfat/file.c
index d25a96a148af..473c1641d50d 100644
--- a/fs/exfat/file.c
+++ b/fs/exfat/file.c
@@ -613,7 +613,11 @@ static int exfat_file_mmap(struct file *file, struct vm_area_struct *vma)
 			start + vma->vm_end - vma->vm_start);
 
 	if ((vma->vm_flags & VM_WRITE) && ei->valid_size < end) {
+		if (!inode_trylock(inode))
+			return -EAGAIN;
+
 		ret = exfat_file_zeroed_range(file, ei->valid_size, end);
+		inode_unlock(inode);
 		if (ret < 0) {
 			exfat_err(inode->i_sb,
 				  "mmap: fail to zero from %llu to %llu(%d)",
-- 
2.34.1


[-- Attachment #2: 0001-exfat-fix-file-not-locking-when-writing-zeros-in-exf.patch --]
[-- Type: application/octet-stream, Size: 1126 bytes --]

From e7f58ba0572c48278816e4448bbdc7c25a57f185 Mon Sep 17 00:00:00 2001
From: Yuezhang Mo <Yuezhang.Mo@sony.com>
Date: Tue, 23 Jan 2024 17:12:47 +0800
Subject: [PATCH] exfat: fix file not locking when writing zeros in
 exfat_file_mmap()

inode->i_rwsem should be locked when writing file. But the lock
is missing when writing zeros to the file in exfat_file_mmap().

Fixes: 11a347fb6cef ("exfat: change to get file size from DataLength")
Signed-off-by: Yuezhang Mo <Yuezhang.Mo@sony.com>
---
 fs/exfat/file.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/fs/exfat/file.c b/fs/exfat/file.c
index d25a96a148af..473c1641d50d 100644
--- a/fs/exfat/file.c
+++ b/fs/exfat/file.c
@@ -613,7 +613,11 @@ static int exfat_file_mmap(struct file *file, struct vm_area_struct *vma)
 			start + vma->vm_end - vma->vm_start);
 
 	if ((vma->vm_flags & VM_WRITE) && ei->valid_size < end) {
+		if (!inode_trylock(inode))
+			return -EAGAIN;
+
 		ret = exfat_file_zeroed_range(file, ei->valid_size, end);
+		inode_unlock(inode);
 		if (ret < 0) {
 			exfat_err(inode->i_sb,
 				  "mmap: fail to zero from %llu to %llu(%d)",
-- 
2.34.1


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

end of thread, other threads:[~2024-03-06 22:31 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-01-24  5:00 [PATCH] exfat: fix file not locking when writing zeros in exfat_file_mmap() Yuezhang.Mo
2024-01-24  5:21 ` Matthew Wilcox
2024-01-24 10:05   ` Yuezhang.Mo
2024-01-24 14:02     ` Matthew Wilcox
2024-01-26  5:43       ` Yuezhang.Mo
2024-01-24 21:35     ` Dave Chinner
2024-01-25 10:19       ` Namjae Jeon
2024-01-26  1:22         ` Dave Chinner
2024-01-26  2:54           ` Matthew Wilcox
2024-01-26 22:32             ` Dave Chinner
2024-01-26 22:41               ` Matthew Wilcox
2024-03-06 22:31                 ` Dave Chinner

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).