All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jeff Layton <jlayton@kernel.org>
To: Trond Myklebust <trondmy@kernel.org>, Anna Schumaker <anna@kernel.org>
Cc: linux-nfs@vger.kernel.org
Subject: NFS client leaks -ERESTARTSYS into userland
Date: Mon, 16 Nov 2026 14:14:55 -0800	[thread overview]
Message-ID: <99d4032b341ae5a08b10f059289f21d3dd08079d.camel@kernel.org> (raw)

[-- Attachment #1: Type: text/plain, Size: 455 bytes --]

We had a report internally of ERESTARTSYS leaking into userland after
killing a process stuck waiting for a missing NFS server.

I've got a draft patch, but agentic review keeps finding issues with it
and I don't have the cycles at the moment to chase this down. I had
claude put together a reproducer (attached), which seems to work. I've
attached the draft patch too, but it's still a bit rough.

Cheers,
-- 
Jeff Layton <jlayton@kernel.org>

[-- Attachment #2: nfs-umount-f-512.sh --]
[-- Type: application/x-shellscript, Size: 4938 bytes --]

[-- Attachment #3: 0001-SUNRPC-report-EIO-not-ERESTARTSYS-for-administrative.patch --]
[-- Type: text/x-patch, Size: 3922 bytes --]

From 1641d4b702d4451f244a8767cb144b06eebadc84 Mon Sep 17 00:00:00 2001
From: Jeff Layton <jlayton@kernel.org>
Date: Fri, 13 Nov 2026 14:00:15 -0500
Subject: [PATCH] SUNRPC: report -EIO, not -ERESTARTSYS, for administratively
 killed tasks

rpc_killall_tasks() terminates every task on an rpc_clnt through
rpc_signal_task(), which sets -ERESTARTSYS.  That code means "a signal
arrived, restart the syscall", and the syscall layer restarts the call
only when a signal is actually pending.  Its one caller,
nfs_umount_begin(), is not a signal: it runs on a forced unmount
(umount -f).  There is no signal to restart on, so -ERESTARTSYS is
returned to userspace as error 512.

Seen in production: a forced unmount of an NFS filesystem made
mkdir(2) fail with "Unknown error 512" in an unrelated process.  Note
that nfs_umount_begin() aborts calls per superblock, so one container's
forced unmount hits every process using that filesystem on the host.

nfs_umount_begin()'s own comment already says what should happen:

	/* -EIO all pending I/O */

Make the code match.  Split the status out of rpc_signal_task() and
add rpc_abort_task(), which reports -EIO, and use it in
rpc_killall_tasks().  Tasks interrupted by a real signal are
unchanged.

Signed-off-by: Jeff Layton <jlayton@kernel.org>
---
 include/linux/sunrpc/sched.h |  1 +
 net/sunrpc/clnt.c            |  2 +-
 net/sunrpc/sched.c           | 23 +++++++++++++++++++++--
 3 files changed, 23 insertions(+), 3 deletions(-)

diff --git a/include/linux/sunrpc/sched.h b/include/linux/sunrpc/sched.h
index 0dbdf3722537..79a08171c4b8 100644
--- a/include/linux/sunrpc/sched.h
+++ b/include/linux/sunrpc/sched.h
@@ -222,6 +222,7 @@ void		rpc_put_task_async(struct rpc_task *);
 bool		rpc_task_set_rpc_status(struct rpc_task *task, int rpc_status);
 void		rpc_task_try_cancel(struct rpc_task *task, int error);
 void		rpc_signal_task(struct rpc_task *);
+void		rpc_abort_task(struct rpc_task *);
 void		rpc_exit_task(struct rpc_task *);
 void		rpc_exit(struct rpc_task *, int);
 void		rpc_release_calldata(const struct rpc_call_ops *, void *);
diff --git a/net/sunrpc/clnt.c b/net/sunrpc/clnt.c
index 6cedc824cf82..9055f0299836 100644
--- a/net/sunrpc/clnt.c
+++ b/net/sunrpc/clnt.c
@@ -896,7 +896,7 @@ void rpc_killall_tasks(struct rpc_clnt *clnt)
 	trace_rpc_clnt_killall(clnt);
 	spin_lock(&clnt->cl_lock);
 	list_for_each_entry(rovr, &clnt->cl_tasks, tk_task)
-		rpc_signal_task(rovr);
+		rpc_abort_task(rovr);
 	spin_unlock(&clnt->cl_lock);
 }
 EXPORT_SYMBOL_GPL(rpc_killall_tasks);
diff --git a/net/sunrpc/sched.c b/net/sunrpc/sched.c
index 016f16ca5779..663d8e157f9a 100644
--- a/net/sunrpc/sched.c
+++ b/net/sunrpc/sched.c
@@ -854,14 +854,14 @@ void rpc_exit_task(struct rpc_task *task)
 	}
 }
 
-void rpc_signal_task(struct rpc_task *task)
+static void rpc_signal_task_status(struct rpc_task *task, int status)
 {
 	struct rpc_wait_queue *queue;
 
 	if (!RPC_IS_ACTIVATED(task))
 		return;
 
-	if (!rpc_task_set_rpc_status(task, -ERESTARTSYS))
+	if (!rpc_task_set_rpc_status(task, status))
 		return;
 	trace_rpc_task_signalled(task, task->tk_action);
 	queue = READ_ONCE(task->tk_waitqueue);
@@ -869,6 +869,25 @@ void rpc_signal_task(struct rpc_task *task)
 		rpc_wake_up_queued_task(queue, task);
 }
 
+void rpc_signal_task(struct rpc_task *task)
+{
+	rpc_signal_task_status(task, -ERESTARTSYS);
+}
+
+/**
+ * rpc_abort_task - terminate a task on behalf of an administrative action
+ * @task: the task to terminate
+ *
+ * Unlike rpc_signal_task(), which reports -ERESTARTSYS for a task
+ * interrupted by a signal, this reports -EIO: there is no signal for
+ * the syscall layer to restart on, so -ERESTARTSYS would be returned
+ * to userspace as error 512.
+ */
+void rpc_abort_task(struct rpc_task *task)
+{
+	rpc_signal_task_status(task, -EIO);
+}
+
 void rpc_task_try_cancel(struct rpc_task *task, int error)
 {
 	struct rpc_wait_queue *queue;
-- 
2.56.1


             reply	other threads:[~2026-11-16 22:14 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-16 22:14 Jeff Layton [this message]
2026-11-16 22:41 ` NFS client leaks -ERESTARTSYS into userland Tigran Mkrtchyan

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=99d4032b341ae5a08b10f059289f21d3dd08079d.camel@kernel.org \
    --to=jlayton@kernel.org \
    --cc=anna@kernel.org \
    --cc=linux-nfs@vger.kernel.org \
    --cc=trondmy@kernel.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.