From: Li Ximo <lixicaicai@gmail.com>
To: David Howells <dhowells@redhat.com>,
Marc Dionne <marc.dionne@auristor.com>
Cc: linux-afs@lists.infradead.org, linux-kernel@vger.kernel.org,
Wang Haoran <haoranwangsec@gmail.com>,
Li Ximo <lixicaicai@gmail.com>
Subject: [PATCH] afs: Fix NULL stream dereference in afs_retry_request()
Date: Wed, 28 Oct 2026 12:03:47 +0800 [thread overview]
Message-ID: <20261028040347.843936-1-lixicaicai@gmail.com> (raw)
From: Wang Haoran <haoranwangsec@gmail.com>
afs_retry_request() is registered unconditionally as the netfs
.retry_request op and serves both the write and the read retry paths.
The netfs read-side retry path, netfs_retry_read_subrequests()
(fs/netfs/read_retry.c), invokes the op with stream == NULL. However,
afs_retry_request() computes
list_first_entry(&stream->subrequests, ...) *before* it checks
wreq->origin, so a read retry dereferences NULL plus
offsetof(struct netfs_io_stream, subrequests), producing a near-NULL
wild pointer dereference and a kernel crash. The read path is reachable
from userspace through an ordinary AFS file read: a failed fscache read
(source NETFS_READ_FROM_CACHE) or a short/partial server read marks the
read subrequest with NETFS_SREQ_NEED_RETRY (fs/netfs/read_collect.c),
which drives netfs_retry_reads() into netfs_retry_read_subrequests() and
hence into afs_retry_request(rreq, NULL). The existing switch on
wreq->origin already rejects all read origins, but only after the stream
has been dereferenced - too late to help. This issue was found during a
code audit.
Fix this by moving the origin check to the top of the function, before
any use of stream: read requests return early exactly as they do today,
and list_first_entry() is only reached for write requests, whose callers
(netfs_retry_write_stream(), which explicitly skips empty subrequest
lists, and the unbuffered/DIO write path, which holds a live subrequest)
guarantee a valid stream with a non-empty subrequest list. Behaviour on
the write path is unchanged.
Reported-by: Wang Haoran <haoranwangsec@gmail.com>
Reported-by: Li Ximo <lixicaicai@gmail.com>
Signed-off-by: Wang Haoran <haoranwangsec@gmail.com>
---
fs/afs/write.c | 11 ++++++++---
1 file changed, 8 insertions(+), 3 deletions(-)
diff --git a/fs/afs/write.c b/fs/afs/write.c
index 7f34b9397..4b4922858 100644
--- a/fs/afs/write.c
+++ b/fs/afs/write.c
@@ -191,10 +191,12 @@ void afs_begin_writeback(struct netfs_io_request *wreq)
*/
void afs_retry_request(struct netfs_io_request *wreq, struct netfs_io_stream *stream)
{
- struct netfs_io_subrequest *subreq =
- list_first_entry(&stream->subrequests,
- struct netfs_io_subrequest, rreq_link);
+ struct netfs_io_subrequest *subreq;
+ /*
+ * The read-side retry path calls this with a NULL stream, so check
+ * the origin before dereferencing stream.
+ */
switch (wreq->origin) {
case NETFS_READAHEAD:
case NETFS_READPAGE:
@@ -208,6 +210,9 @@ void afs_retry_request(struct netfs_io_request *wreq, struct netfs_io_stream *st
break;
}
+ subreq = list_first_entry(&stream->subrequests,
+ struct netfs_io_subrequest, rreq_link);
+
switch (subreq->error) {
case -EACCES:
case -EPERM:
--
2.30.2
reply other threads:[~2026-10-28 4:03 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=20261028040347.843936-1-lixicaicai@gmail.com \
--to=lixicaicai@gmail.com \
--cc=dhowells@redhat.com \
--cc=haoranwangsec@gmail.com \
--cc=linux-afs@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=marc.dionne@auristor.com \
/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®