[BUG] nfs: NULL dereference in the nfs_xdr_event tracepoint from readdir
From: Piyus Kedia
Date: Fri Nov 27 2026 - 05:56:58 EST
Hi,
The nfs_xdr_event trace class dereferences xdr->rqst, and the readdir
decode path reaches it with that pointer NULL, so enabling the tracepoint
and reading a directory from a server that returns a bad filehandle
oopses.
The class builds its entry from the RPC task:
fs/nfs/nfstrace.h
__string(program, xdr->rqst->rq_task->tk_client->cl_program->name)
The readdir decoder has no RPC request. nfs_readdir_folio_filler() sets
up its stream over the page cache:
fs/nfs/dir.c:840
xdr_init_decode_pages(&stream, &buf, xdr_pages, buflen);
and xdr_init_decode_pages() ends with xdr_init_decode(xdr, buf, NULL,
NULL), so xdr->rqst stays NULL for the whole decode.
decode_nfs_fh3() traces on its error path:
fs/nfs/nfs3xdr.c:442
trace_nfs_xdr_bad_filehandle(xdr, NFSERR_BADHANDLE);
reached from nfs3_decode_dirent() at fs/nfs/nfs3xdr.c:2017 when a server
sends a filehandle longer than NFS3_FHSIZE or of length zero. The trace
handler then reads through the NULL request:
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/10770
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 fs/readdir.c:114
0x98 is offsetof(struct rpc_rqst, rq_task).
Two things bound how bad this is: the tracepoint has to be enabled, and
the filehandle has to come from the server, so it is a bad or hostile
server rather than an unprivileged local user.
It is not a logged splat: the read faults in a tracepoint handler, so the
machine takes a fatal exception and dies.
CR2: 0000000000000098
Kernel panic - not syncing: Fatal exception
Seen on 7.3.1 and REPRODUCED ON 7.4.0-rc1 (63fe746a609a) with KASAN, same
.config and image before and after, only fs/nfs rebuilt between the two:
without the patch (#13) KASAN null-ptr-deref, then the panic above
with the patch (#14) the same program opens and reads the directory,
no report, twice
The code has been this way since eb3d58c68e39, so v5.13 and later.
A patch follows. It gives the class a TP_CONDITION so the event only
fires for a stream that has a request, which covers both nfs_xdr_status
and nfs_xdr_bad_filehandle in one place. The event reports the task and
client ids, so without a request it has nothing to report anyway.
The reproducer runs both ends inside one machine - rpcbind, MOUNT and NFS
servers on 111/2049/2050, the NFS tracepoints enabled through tracefs, and
then a readdir - so it needs no network and no real server. It is
fuzzer-generated and we are happy to send it on request.
Thanks,
Piyus