Skip to content

Commit 78f2560

Browse files
bsberndMiklos Szeredi
authored andcommitted
fuse: Set *nbytesp=0 in fuse_get_user_pages on allocation failure
In fuse_get_user_pages(), set *nbytesp to 0 when struct page **pages allocation fails. This prevents the caller (fuse_direct_io) from making incorrect assumptions that could lead to NULL pointer dereferences when processing the request reply. Previously, *nbytesp was left unmodified on allocation failure, which could cause issues if the caller assumed pages had been added to ap->descs[] when they hadn't. Reported-by: [email protected] Closes: https://syzkaller.appspot.com/bug?extid=87b8e6ed25dbc41759f7 Fixes: 3b97c36 ("fuse: convert direct io to use folios") Signed-off-by: Bernd Schubert <[email protected]> Reviewed-by: Joanne Koong <[email protected]> Tested-by: Dmitry Antipov <[email protected]> Tested-by: David Howells <[email protected]> Signed-off-by: Miklos Szeredi <[email protected]>
1 parent 7a4f541 commit 78f2560

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

fs/fuse/file.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1541,8 +1541,10 @@ static int fuse_get_user_pages(struct fuse_args_pages *ap, struct iov_iter *ii,
15411541
*/
15421542
struct page **pages = kzalloc(max_pages * sizeof(struct page *),
15431543
GFP_KERNEL);
1544-
if (!pages)
1545-
return -ENOMEM;
1544+
if (!pages) {
1545+
ret = -ENOMEM;
1546+
goto out;
1547+
}
15461548

15471549
while (nbytes < *nbytesp && nr_pages < max_pages) {
15481550
unsigned nfolios, i;
@@ -1588,6 +1590,7 @@ static int fuse_get_user_pages(struct fuse_args_pages *ap, struct iov_iter *ii,
15881590
else
15891591
ap->args.out_pages = true;
15901592

1593+
out:
15911594
*nbytesp = nbytes;
15921595

15931596
return ret < 0 ? ret : 0;

0 commit comments

Comments
 (0)