From: Hui Peng <benquike@gmail.com>
To: miklos@szeredi.hu
Cc: fuse-devel@lists.linux.dev, linux-kernel@vger.kernel.org
Subject: [PATCH] fuse: validate folio state before pipe_buf_try_steal() in fuse_try_move_folio()
Date: Sat, 19 Sep 2026 22:17:33 +0000 [thread overview]
Message-ID: <20260919221733.3707924-1-benquike@gmail.com> (raw)
In fuse_try_move_folio(), check that the pipe buffer's folio is not
hugetlb, swap-backed, or already mapped/anon before attempting
pipe_buf_try_steal() and inserting it into the FUSE inode's page cache,
preventing VM_BUG_ON_FOLIO() and page cache state corruption.
Fixes: 394244b24fdd ("fuse: support copying large folios")
Assisted-by: LLM
Signed-off-by: Hui Peng <benquike@gmail.com>
---
diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
index 4fec31fc0b84..121bb1f3cb05 100644
--- a/fs/fuse/dev.c
+++ b/fs/fuse/dev.c
@@ -1147,32 +1147,32 @@ static int fuse_try_move_folio(struct fuse_copy_state *cs, struct folio **foliop
if (cs->len != folio_size(oldfolio))
goto out_fallback;
- if (!pipe_buf_try_steal(cs->pipe, buf))
- goto out_fallback;
-
newfolio = page_folio(buf->page);
- folio_clear_uptodate(newfolio);
- folio_clear_mappedtodisk(newfolio);
-
if (folio_test_large(newfolio))
- goto out_fallback_unlock;
-
- if (fuse_check_folio(newfolio) != 0)
- goto out_fallback_unlock;
+ goto out_fallback;
/*
* This is a new and locked page, it shouldn't be mapped or
* have any special flags on it
*/
if (WARN_ON(folio_mapped(oldfolio)))
- goto out_fallback_unlock;
+ goto out_fallback;
if (WARN_ON(folio_has_private(oldfolio)))
- goto out_fallback_unlock;
+ goto out_fallback;
if (WARN_ON(folio_test_dirty(oldfolio) ||
folio_test_writeback(oldfolio)))
- goto out_fallback_unlock;
+ goto out_fallback;
if (WARN_ON(folio_test_mlocked(oldfolio)))
+ goto out_fallback;
+
+ if (!pipe_buf_try_steal(cs->pipe, buf))
+ goto out_fallback;
+
+ folio_clear_uptodate(newfolio);
+ folio_clear_mappedtodisk(newfolio);
+
+ if (fuse_check_folio(newfolio) != 0)
goto out_fallback_unlock;
err = lock_request(cs->req);
reply other threads:[~2026-09-19 22:17 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260919221733.3707924-1-benquike@gmail.com \
--to=benquike@gmail.com \
--cc=fuse-devel@lists.linux.dev \
--cc=linux-kernel@vger.kernel.org \
--cc=miklos@szeredi.hu \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®