Linux network filesystem support library
 help / color / mirror / Atom feed
* [PATCH] netfs: Fix UAF in netfs_unbuffered_write() on failed preparation
@ 2026-05-30  1:14 hongao
  2026-06-23 10:28 ` Christian Brauner
                   ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: hongao @ 2026-05-30  1:14 UTC (permalink / raw)
  To: David Howells
  Cc: Paulo Alcantara, netfs, linux-fsdevel, linux-kernel, hongao,
	syzbot+3c74b1f0c372e98efc32

If write subrequest preparation fails, netfs_unbuffered_write() calls
netfs_write_subrequest_terminated() and then reads subreq->error to set
wreq->error.

However, netfs_write_subrequest_terminated() consumes a reference to the
subrequest through netfs_put_subrequest(), so the subrequest may be freed
before netfs_unbuffered_write() reads subreq->error again.  This can
trigger a slab-use-after-free.

Save the error locally before terminating the subrequest, and use the
saved value afterwards.

Fixes: a0b4c7a49137 ("netfs: Fix unbuffered/DIO writes to dispatch subrequests in strict sequence")
Reported-by: syzbot+3c74b1f0c372e98efc32@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=3c74b1f0c372e98efc32

Signed-off-by: hongao <hongao@uniontech.com>
---
 fs/netfs/direct_write.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/fs/netfs/direct_write.c b/fs/netfs/direct_write.c
index 25f8ceb15fad..2d5361702076 100644
--- a/fs/netfs/direct_write.c
+++ b/fs/netfs/direct_write.c
@@ -115,8 +115,9 @@ static int netfs_unbuffered_write(struct netfs_io_request *wreq)
 
 		/* Check if (re-)preparation failed. */
 		if (unlikely(test_bit(NETFS_SREQ_FAILED, &subreq->flags))) {
-			netfs_write_subrequest_terminated(subreq, subreq->error);
-			wreq->error = subreq->error;
+			ret = subreq->error;
+			wreq->error = ret;
+			netfs_write_subrequest_terminated(subreq, ret);
 			break;
 		}
 
-- 
2.51.0


^ permalink raw reply related	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2026-06-24 11:03 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-05-30  1:14 [PATCH] netfs: Fix UAF in netfs_unbuffered_write() on failed preparation hongao
2026-06-23 10:28 ` Christian Brauner
2026-06-23 11:52 ` ChenXiaoSong
2026-06-23 16:10   ` David Howells
2026-06-24  1:26     ` ChenXiaoSong
2026-06-24  7:36       ` David Howells
2026-06-24 10:59       ` David Howells
2026-06-24 11:02       ` David Howells
2026-06-23 14:53 ` David Howells

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox