[PATCH] ext4: Fix handle refcount leak in ext4_write_begin()

Subsystems: ext4 file system, filesystems (vfs and infrastructure), the rest

STALE1799d

2 messages, 2 authors, 2021-10-07 · open the first message on its own page

[PATCH] ext4: Fix handle refcount leak in ext4_write_begin()

From: Chenyuan Mi <hidden>
Date: 2021-09-08 07:07:22

The reference counting issue happens when ret is zero,
the function forgets to decrease the refcount of handle
increased by ext4_journal_start().

Fix this issue by using ext4_journal_stop() to decrease
the refcount of handle.

Signed-off-by: Chenyuan Mi <redacted>
Signed-off-by: Xiyu Yang <redacted>
Signed-off-by: Xin Tan <redacted>
---
 fs/ext4/inode.c | 1 +
 1 file changed, 1 insertion(+)
diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
index d18852d6029c..90c57d8e3de1 100644
--- a/fs/ext4/inode.c
+++ b/fs/ext4/inode.c
@@ -1249,6 +1249,7 @@ static int ext4_write_begin(struct file *file, struct address_space *mapping,
 		put_page(page);
 		return ret;
 	}
+	ext4_journal_stop(handle);
 	*pagep = page;
 	return ret;
 }
-- 
2.17.1

Re: [PATCH] ext4: Fix handle refcount leak in ext4_write_begin()

From: Jan Kara <jack@suse.cz>
Date: 2021-10-07 14:06:45

On Wed 08-09-21 15:06:40, Chenyuan Mi wrote:
The reference counting issue happens when ret is zero,
the function forgets to decrease the refcount of handle
increased by ext4_journal_start().

Fix this issue by using ext4_journal_stop() to decrease
the refcount of handle.

Signed-off-by: Chenyuan Mi <redacted>
Signed-off-by: Xiyu Yang <redacted>
Signed-off-by: Xin Tan <redacted>
Yes, but that is deliberate. We want to keep the transaction running until
the write is done - i.e., until ->write_end() callback where we call
ext4_journal_stop(). As a side note, please test your patches. You clearly
didn't test this patch because if you did, you would notice that your patch
breaks writing to ext4.

                                                                Honza
quoted hunk
---
 fs/ext4/inode.c | 1 +
 1 file changed, 1 insertion(+)
diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
index d18852d6029c..90c57d8e3de1 100644
--- a/fs/ext4/inode.c
+++ b/fs/ext4/inode.c
@@ -1249,6 +1249,7 @@ static int ext4_write_begin(struct file *file, struct address_space *mapping,
 		put_page(page);
 		return ret;
 	}
+	ext4_journal_stop(handle);
 	*pagep = page;
 	return ret;
 }
-- 
2.17.1
-- 
Jan Kara [off-list ref]
SUSE Labs, CR
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help