Skip to content

Commit dbee298

Browse files
joannekoongbrauner
authored andcommitted
fuse: fix fuse_fill_write_pages() upper bound calculation
This fixes a bug in commit 63c69ad ("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. Signed-off-by: Joanne Koong <[email protected]> Link: https://lore.kernel.org/[email protected] Fixes: 63c69ad ("fuse: refactor fuse_fill_write_pages()") Tested-by: Brian Foster <[email protected]> Reported-by: Brian Foster <[email protected]> Closes: https://lore.kernel.org/linux-fsdevel/aEq4haEQScwHIWK6@bfoster/ Signed-off-by: Christian Brauner <[email protected]>
1 parent cbe4134 commit dbee298

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

fs/fuse/file.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1147,7 +1147,7 @@ static ssize_t fuse_send_write_pages(struct fuse_io_args *ia,
11471147
static ssize_t fuse_fill_write_pages(struct fuse_io_args *ia,
11481148
struct address_space *mapping,
11491149
struct iov_iter *ii, loff_t pos,
1150-
unsigned int max_pages)
1150+
unsigned int max_folios)
11511151
{
11521152
struct fuse_args_pages *ap = &ia->ap;
11531153
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,
11571157
int err = 0;
11581158

11591159
num = min(iov_iter_count(ii), fc->max_write);
1160-
num = min(num, max_pages << PAGE_SHIFT);
11611160

11621161
ap->args.in_pages = true;
11631162
ap->descs[0].offset = offset;
11641163

1165-
while (num) {
1164+
while (num && ap->num_folios < max_folios) {
11661165
size_t tmp;
11671166
struct folio *folio;
11681167
pgoff_t index = pos >> PAGE_SHIFT;

0 commit comments

Comments
 (0)