From: Jeff Layton <jlayton@kernel.org>
To: Chuck Lever <cel@kernel.org>, NeilBrown <neil@brown.name>,
Olga Kornievskaia <okorniev@redhat.com>,
Dai Ngo <Dai.Ngo@oracle.com>, Tom Talpey <tom@talpey.com>
Cc: linux-nfs@vger.kernel.org, linux-kernel@vger.kernel.org,
Yifan Zhang <yfzhang23@stu.pku.edu.cn>,
Jeff Layton <jlayton@kernel.org>
Subject: [PATCH] NFSD: Don't dereference cp_clp in async COPY tracepoints
Date: Wed, 28 Oct 2026 10:10:38 -0400 [thread overview]
Message-ID: <20261028-nfsd-testing-v1-1-9116f59c4f77@kernel.org> (raw)
nfsd4_unhash_copy() and find_async_copy() clear cp_clp before
nfsd4_stop_copy() fires trace_nfsd_copy_async_cancel(), which reads
copy->cp_clp->cl_addr: NULL deref on shutdown or OFFLOAD_CANCEL. The
kthread's nfsd_copy_async{,_done} events race the same clear.
Pass the client explicitly: cp_stid.sc_client for async copies (never
cleared), cstate->clp for the sync paths.
Reported-by: Yifan Zhang <yfzhang23@stu.pku.edu.cn>
Closes: https://lore.kernel.org/linux-nfs/179317462025.87538.12362003258355443382@stu.pku.edu.cn/
Fixes: 62a8642ba00a ("NFSD: Fix nfsd4_shutdown_copy()")
Fixes: 62c0f6eaf050 ("nfsd: fix UAF in async copy cancel and shutdown")
Signed-off-by: Jeff Layton <jlayton@kernel.org>
---
fs/nfsd/nfs4proc.c | 10 +++++-----
fs/nfsd/trace.h | 20 ++++++++++++--------
2 files changed, 17 insertions(+), 13 deletions(-)
diff --git a/fs/nfsd/nfs4proc.c b/fs/nfsd/nfs4proc.c
index a50f9dcb3a31..b572210ee526 100644
--- a/fs/nfsd/nfs4proc.c
+++ b/fs/nfsd/nfs4proc.c
@@ -1653,7 +1653,7 @@ static void release_copy_files(struct nfsd4_copy *copy);
static void nfsd4_stop_copy(struct nfsd4_async_copy *copy)
{
- trace_nfsd_copy_async_cancel(©->cp_copy);
+ trace_nfsd_copy_async_cancel(copy->cp_stid.sc_client, ©->cp_copy);
/*
* Join the kthread before releasing its resources. The task_struct is
* pinned in nfsd4_copy(), so kthread_stop() is safe even after the
@@ -2245,7 +2245,7 @@ static int nfsd4_do_async_copy(void *data)
struct nfsd4_copy *copy = &async->cp_copy;
__be32 nfserr = nfs_ok;
- trace_nfsd_copy_async(copy);
+ trace_nfsd_copy_async(async->cp_stid.sc_client, copy);
if (nfsd4_ssc_is_inter(copy)) {
struct file *filp;
@@ -2280,7 +2280,7 @@ static int nfsd4_do_async_copy(void *data)
* joining.
*/
set_bit(NFSD4_COPY_F_COMPLETED, ©->cp_flags);
- trace_nfsd_copy_async_done(copy);
+ trace_nfsd_copy_async_done(async->cp_stid.sc_client, copy);
atomic_dec(©->cp_nn->pending_async_copies);
if (copy->cp_res.wr_bytes_written > 0 && copy->attr_update)
nfsd_update_cmtime_attr(copy->nf_dst->nf_file, 0);
@@ -2306,7 +2306,7 @@ nfsd4_copy(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
copy->cp_clp = cstate->clp;
if (nfsd4_ssc_is_inter(copy)) {
- trace_nfsd_copy_inter(copy);
+ trace_nfsd_copy_inter(cstate->clp, copy);
if (!inter_copy_offload_enable || nfsd4_copy_is_sync(copy)) {
status = nfserr_notsupp;
goto out;
@@ -2317,7 +2317,7 @@ nfsd4_copy(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
goto out;
}
} else {
- trace_nfsd_copy_intra(copy);
+ trace_nfsd_copy_intra(cstate->clp, copy);
status = nfsd4_setup_intra_ssc(rqstp, cstate, copy);
if (status)
goto out;
diff --git a/fs/nfsd/trace.h b/fs/nfsd/trace.h
index 951af645d1cb..e7b186307c21 100644
--- a/fs/nfsd/trace.h
+++ b/fs/nfsd/trace.h
@@ -2481,9 +2481,10 @@ TRACE_EVENT(nfsd_ctl_fh_key_set,
DECLARE_EVENT_CLASS(nfsd_copy_class,
TP_PROTO(
+ const struct nfs4_client *clp,
const struct nfsd4_copy *copy
),
- TP_ARGS(copy),
+ TP_ARGS(clp, copy),
TP_STRUCT__entry(
__field(bool, intra)
__field(bool, async)
@@ -2526,7 +2527,7 @@ DECLARE_EVENT_CLASS(nfsd_copy_class,
__entry->src_cp_pos = copy->cp_src_pos;
__entry->dst_cp_pos = copy->cp_dst_pos;
__entry->cp_count = copy->cp_count;
- __assign_sockaddr(addr, ©->cp_clp->cl_addr,
+ __assign_sockaddr(addr, &clp->cl_addr,
sizeof(struct sockaddr_in6));
),
TP_printk("client=%pISpc intra=%d async=%d "
@@ -2547,8 +2548,9 @@ DECLARE_EVENT_CLASS(nfsd_copy_class,
#define DEFINE_COPY_EVENT(name) \
DEFINE_EVENT(nfsd_copy_class, nfsd_copy_##name, \
- TP_PROTO(const struct nfsd4_copy *copy), \
- TP_ARGS(copy))
+ TP_PROTO(const struct nfs4_client *clp, \
+ const struct nfsd4_copy *copy), \
+ TP_ARGS(clp, copy))
DEFINE_COPY_EVENT(inter);
DEFINE_COPY_EVENT(intra);
@@ -2580,9 +2582,10 @@ TRACE_EVENT(nfsd_copy_done,
DECLARE_EVENT_CLASS(nfsd_copy_async_done_class,
TP_PROTO(
+ const struct nfs4_client *clp,
const struct nfsd4_copy *copy
),
- TP_ARGS(copy),
+ TP_ARGS(clp, copy),
TP_STRUCT__entry(
__field(int, status)
__field(bool, intra)
@@ -2627,7 +2630,7 @@ DECLARE_EVENT_CLASS(nfsd_copy_async_done_class,
__entry->src_cp_pos = copy->cp_src_pos;
__entry->dst_cp_pos = copy->cp_dst_pos;
__entry->cp_count = copy->cp_count;
- __assign_sockaddr(addr, ©->cp_clp->cl_addr,
+ __assign_sockaddr(addr, &clp->cl_addr,
sizeof(struct sockaddr_in6));
),
TP_printk("client=%pISpc status=%d intra=%d async=%d "
@@ -2650,8 +2653,9 @@ DECLARE_EVENT_CLASS(nfsd_copy_async_done_class,
#define DEFINE_COPY_ASYNC_DONE_EVENT(name) \
DEFINE_EVENT(nfsd_copy_async_done_class, \
nfsd_copy_async_##name, \
- TP_PROTO(const struct nfsd4_copy *copy), \
- TP_ARGS(copy))
+ TP_PROTO(const struct nfs4_client *clp, \
+ const struct nfsd4_copy *copy), \
+ TP_ARGS(clp, copy))
DEFINE_COPY_ASYNC_DONE_EVENT(done);
DEFINE_COPY_ASYNC_DONE_EVENT(cancel);
---
base-commit: 19bbac00ad1cfa28e9127488f161ffc2ac03fad4
change-id: 20261028-nfsd-testing-1ee56f934cd8
Best regards,
--
Jeff Layton <jlayton@kernel.org>
next reply other threads:[~2026-10-28 14:10 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-28 14:10 Jeff Layton [this message]
2026-10-28 18:51 ` Chuck Lever
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=20261028-nfsd-testing-v1-1-9116f59c4f77@kernel.org \
--to=jlayton@kernel.org \
--cc=Dai.Ngo@oracle.com \
--cc=cel@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-nfs@vger.kernel.org \
--cc=neil@brown.name \
--cc=okorniev@redhat.com \
--cc=tom@talpey.com \
--cc=yfzhang23@stu.pku.edu.cn \
/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®