[PATCH] nfs: do not trace an xdr_stream that has no RPC request

From: Piyus Kedia

Date: Fri Nov 27 2026 - 05:57:38 EST


The nfs_xdr_event class reads
xdr->rqst->rq_task->tk_client->cl_program->name, so it needs a stream that
belongs to an RPC request. The readdir decoder has no such stream:
nfs_readdir_folio_filler() builds one over the page cache with
xdr_init_decode_pages(), which leaves xdr->rqst NULL.

decode_nfs_fh3() traces nfs_xdr_bad_filehandle when a server sends a
filehandle longer than NFS3_FHSIZE or of length zero. Reached from
nfs3_decode_dirent() that stream has no request, and the trace handler
dereferences the NULL pointer:

BUG: KASAN: null-ptr-deref in trace_event_get_offsets_nfs_xdr_event+0x32/0x1c0
Read of size 8 at addr 0000000000000098 by task syz-executor
trace_nfs_xdr_bad_filehandle+0x16c/0x1b0 fs/nfs/nfstrace.h:1979
decode_nfs_fh3+0xb5/0xd0 fs/nfs/nfs3xdr.c:442
nfs3_decode_dirent+0x3be/0x4a0 fs/nfs/nfs3xdr.c:2017
nfs_readdir_entry_decode+0x14a/0xab0 fs/nfs/dir.c:814
nfs_readdir_xdr_to_array+0x8af/0x1040 fs/nfs/dir.c:966
nfs_readdir+0x1003/0x23f0 fs/nfs/dir.c:1277
iterate_dir+0x29d/0x520

The tracepoint has to be enabled for this to happen.

Give the class a condition so it only fires for a stream that has a
request. The event reports the task and client ids, so it has nothing to
say without one.

We found this with a syzkaller-based fuzzing harness driven by an AI tool.

Fixes: eb3d58c68e39 ("NFSv4: Catch and trace server filehandle encoding errors")
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Kapil Vaswani <kapil@xxxxxxxxxxxxxxx>
Signed-off-by: Piyus Kedia <piyus@xxxxxxxxxxx>
---
Reproduced on 7.4.0-rc1 (63fe746a609a) with KASAN, same config and image
before and after, only fs/nfs rebuilt between the two. The reproducer runs
rpcbind, MOUNT and NFS servers inside the machine, enables the nfs
tracepoints and reads a directory whose READDIRPLUS entry carries a
zero-length filehandle:

before KASAN null-ptr-deref at 0x98, then "Kernel panic - Fatal exception"
after the same program reads the directory, no report, twice

fs/nfs/nfstrace.h | 10 ++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/fs/nfs/nfstrace.h b/fs/nfs/nfstrace.h
index a32c76df72db..a3056264344f 100644
--- a/fs/nfs/nfstrace.h
+++ b/fs/nfs/nfstrace.h
@@ -1971,13 +1971,19 @@ DECLARE_EVENT_CLASS(nfs_xdr_event,
show_nfs_status(__entry->error)
)
);
+/*
+ * Only trace a stream that belongs to an RPC request. The readdir decoder
+ * builds a stream over the page cache with xdr_init_decode_pages(), which
+ * leaves xdr->rqst NULL, and this class dereferences it.
+ */
#define DEFINE_NFS_XDR_EVENT(name) \
- DEFINE_EVENT(nfs_xdr_event, name, \
+ DEFINE_EVENT_CONDITION(nfs_xdr_event, name, \
TP_PROTO( \
const struct xdr_stream *xdr, \
int error \
), \
- TP_ARGS(xdr, error))
+ TP_ARGS(xdr, error), \
+ TP_CONDITION(xdr->rqst))
DEFINE_NFS_XDR_EVENT(nfs_xdr_status);
DEFINE_NFS_XDR_EVENT(nfs_xdr_bad_filehandle);

--
2.34.1