Skip to contentSkip to conversation

fuse: fix fuse_fill_write_pages() upper bound calculation

PATCH Applied Joanne Koong 3 participants 6 messages Jun 14, 2025 – Jun 24, 2025

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 fuse: fix fuse_fill_write_pages() upper bound calculation

This fixes a bug in commit 63c69ad3d18a ("fuse: refactor fuse_fill_write_pages()") where max_pages << PAGE_SHIFT is mistakenly used as the calculation for the max_pages upper limit but there's the possibility that copy_folio_from_iter_atomic() may copy over bytes from the iov_iter that are less than the full length of the folio, which would lead to exceeding max_pages.

This commit fixes it by adding a 'ap->num_folios < max_folios' check.

Fixes 63c69ad3d18a ("fuse: refactor fuse_fill_write_pages()")
---
 fs/fuse/file.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
fs/fuse/file.c +2 -3
index 3d0b33be3824..a05a589dc701 100644
@@ -1147,7 +1147,7 @@ static ssize_t fuse_send_write_pages(struct fuse_io_args *ia,
 static ssize_t fuse_fill_write_pages(struct fuse_io_args *ia,
 				     struct address_space *mapping,
 				     struct iov_iter *ii, loff_t pos,
-				     unsigned int max_pages)
+				     unsigned int max_folios)
 {
 	struct fuse_args_pages *ap = &ia->ap;
 	struct fuse_conn *fc = get_fuse_conn(mapping->host);
@@ -1157,12 +1157,11 @@ static ssize_t fuse_fill_write_pages(struct fuse_io_args *ia,
 	int err = 0;
 
 	num = min(iov_iter_count(ii), fc->max_write);
-	num = min(num, max_pages << PAGE_SHIFT);
 
 	ap->args.in_pages = true;
 	ap->descs[0].offset = offset;
 
-	while (num) {
+	while (num && ap->num_folios < max_folios) {
 		size_t tmp;
 		struct folio *folio;
 		pgoff_t index = pos >> PAGE_SHIFT;
Signature · 1 line
2.47.1
Tested-by on v1 1/1
#1 lore raw
Quoted 7 lines · Joanne Koong

This fixes a bug in commit 63c69ad3d18a ("fuse: refactor fuse_fill_write_pages()") where max_pages << PAGE_SHIFT is mistakenly used as the calculation for the max_pages upper limit but there's the possibility that copy_folio_from_iter_atomic() may copy over bytes from the iov_iter that are less than the full length of the folio, which would lead to exceeding max_pages.

Quoted 7 lines

This commit fixes it by adding a 'ap->num_folios < max_folios' check.

Fixes 63c69ad3d18a ("fuse: refactor fuse_fill_write_pages()")

---

This resolves the problem for me as well. Thanks again..

Quoted 33 lines
 fs/fuse/file.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
fs/fuse/file.c +2 -3
index 3d0b33be3824..a05a589dc701 100644
@@ -1147,7 +1147,7 @@ static ssize_t fuse_send_write_pages(struct fuse_io_args *ia,
 static ssize_t fuse_fill_write_pages(struct fuse_io_args *ia,
 				     struct address_space *mapping,
 				     struct iov_iter *ii, loff_t pos,
-				     unsigned int max_pages)
+				     unsigned int max_folios)
 {
 	struct fuse_args_pages *ap = &ia->ap;
 	struct fuse_conn *fc = get_fuse_conn(mapping->host);
@@ -1157,12 +1157,11 @@ static ssize_t fuse_fill_write_pages(struct fuse_io_args *ia,
 	int err = 0;
 
 	num = min(iov_iter_count(ii), fc->max_write);
-	num = min(num, max_pages << PAGE_SHIFT);
 
 	ap->args.in_pages = true;
 	ap->descs[0].offset = offset;
 
-	while (num) {
+	while (num && ap->num_folios < max_folios) {
 		size_t tmp;
 		struct folio *folio;
 		pgoff_t index = pos >> PAGE_SHIFT;
Signature · 1 line
2.47.1
#2 lore raw
Quoted 46 lines · Brian Foster
Quoted 7 lines · Joanne Koong

This fixes a bug in commit 63c69ad3d18a ("fuse: refactor fuse_fill_write_pages()") where max_pages << PAGE_SHIFT is mistakenly used as the calculation for the max_pages upper limit but there's the possibility that copy_folio_from_iter_atomic() may copy over bytes from the iov_iter that are less than the full length of the folio, which would lead to exceeding max_pages.

Quoted 7 lines

This commit fixes it by adding a 'ap->num_folios < max_folios' check.

Fixes 63c69ad3d18a ("fuse: refactor fuse_fill_write_pages()")

---

This resolves the problem for me as well. Thanks again..

Quoted 25 lines
 fs/fuse/file.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
fs/fuse/file.c +1 -2
index 3d0b33be3824..a05a589dc701 100644
@@ -1147,7 +1147,7 @@ static ssize_t fuse_send_write_pages(struct fuse_io_args *ia,
 static ssize_t fuse_fill_write_pages(struct fuse_io_args *ia,
                                   struct address_space *mapping,
                                   struct iov_iter *ii, loff_t pos,
-                                  unsigned int max_pages)
+                                  unsigned int max_folios)
 {
      struct fuse_args_pages *ap = &ia->ap;
      struct fuse_conn *fc = get_fuse_conn(mapping->host);
@@ -1157,12 +1157,11 @@ static ssize_t fuse_fill_write_pages(struct fuse_io_args *ia,
      int err = 0;
 
      num = min(iov_iter_count(ii), fc->max_write);
-     num = min(num, max_pages << PAGE_SHIFT);
 
      ap->args.in_pages = true;
      ap->descs[0].offset = offset;
 
Quoted 9 lines
Quoted 8 lines
fs/fuse/file.c +1 -2
-     while (num) {
+     while (num && ap->num_folios < max_folios) {
              size_t tmp;
              struct folio *folio;
              pgoff_t index = pos >> PAGE_SHIFT;
--

2.47.1

Miklos or Christian, could this fix be added to the next release candidate?

Thanks,
Joanne

#3 lore raw
Quoted 1 line

Miklos or Christian, could this fix be added to the next release candidate?

Snatched.

#4 lore raw
Quoted 4 lines · Christian Brauner
Quoted 2 lines

Miklos or Christian, could this fix be added to the next release candidate?

Snatched.

Thanks, Christian.

maintainer Applied
#5 lore raw
In reply to Joanne Koong
Quoted 8 lines · Joanne Koong

This fixes a bug in commit 63c69ad3d18a ("fuse: refactor fuse_fill_write_pages()") where max_pages << PAGE_SHIFT is mistakenly used as the calculation for the max_pages upper limit but there's the possibility that copy_folio_from_iter_atomic() may copy over bytes from the iov_iter that are less than the full length of the folio, which would lead to exceeding max_pages.

[...]

Applied to the vfs.fixes branch of the vfs/vfs.git tree. Patches in the vfs.fixes branch should appear in linux-next soon.

Please report any outstanding bugs that were missed during review in a new review to the original patch series allowing us to drop it.

It's encouraged to provide Acked-bys and Reviewed-bys even though the patch has now been applied. If possible patch trailers will be updated.

Note that commit hashes shown below are subject to change due to rebase, trailer updates or similar. If in doubt, please check the listed branch.

tree:   https://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs.git
branch: vfs.fixes

[1/1] fuse: fix fuse_fill_write_pages() upper bound calculation

      https://git.kernel.org/vfs/vfs/c/dbee298cb7bb