Skip to content

Commit 2f13982

Browse files
author
Miklos Szeredi
committed
fuse: don't overflow LLONG_MAX with end offset
Handle the special case of fuse_readpages() wanting to read the last page of a hugest file possible and overflowing the end offset in the process. This is basically to unbreak xfstests:generic/525 and prevent filesystems from doing bad things with an overflowing offset. Reported-by: Xiao Yang <[email protected]> Signed-off-by: Miklos Szeredi <[email protected]>
1 parent f658ade commit 2f13982

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

fs/fuse/file.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -803,6 +803,10 @@ static int fuse_do_readpage(struct file *file, struct page *page)
803803

804804
attr_ver = fuse_get_attr_version(fc);
805805

806+
/* Don't overflow end offset */
807+
if (pos + (desc.length - 1) == LLONG_MAX)
808+
desc.length--;
809+
806810
fuse_read_args_fill(&ia, file, pos, desc.length, FUSE_READ);
807811
res = fuse_simple_request(fc, &ia.ap.args);
808812
if (res < 0)
@@ -888,6 +892,14 @@ static void fuse_send_readpages(struct fuse_io_args *ia, struct file *file)
888892
ap->args.out_pages = true;
889893
ap->args.page_zeroing = true;
890894
ap->args.page_replace = true;
895+
896+
/* Don't overflow end offset */
897+
if (pos + (count - 1) == LLONG_MAX) {
898+
count--;
899+
ap->descs[ap->num_pages - 1].length--;
900+
}
901+
WARN_ON((loff_t) (pos + count) < 0);
902+
891903
fuse_read_args_fill(ia, file, pos, count, FUSE_READ);
892904
ia->read.attr_ver = fuse_get_attr_version(fc);
893905
if (fc->async_read) {

0 commit comments

Comments
 (0)