[Devel,1/3] sunrpc: fix race between "kill_tasks" set and actual task killing

Submitted by Stanislav Kinsburskiy on July 10, 2017, 4:41 p.m.

Details

Message ID 20170710164141.15570.77330.stgit@localhost.localdomain
State New
Series "SUNRPC: fix races in tasks killing"
Headers show

Commit Message

Stanislav Kinsburskiy July 10, 2017, 4:41 p.m.
There could be a situation, when RPC task is not yet sleeping, but already
passed the check for "kill_tasks" in __rpc_execute().
There is a race in such a case, because task will fall into sleep anyway.
This patch makes this probability a little bit less.

Signed-off-by: Stanislav Kinsburskiy <skinsbursky@virtuozzo.com>
---
 net/sunrpc/clnt.c |    6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

Patch hide | download patch | download mbox

diff --git a/net/sunrpc/clnt.c b/net/sunrpc/clnt.c
index 8543de4..94b0187 100644
--- a/net/sunrpc/clnt.c
+++ b/net/sunrpc/clnt.c
@@ -2556,6 +2556,7 @@  static ssize_t write_kill_tasks(struct file *file, const char __user *buf,
 {
 	struct net *net = PDE_DATA(file->f_path.dentry->d_inode);
 	struct sunrpc_net *sn = net_generic(net, sunrpc_net_id);
+	bool prev_kill_tasks = sn->kill_tasks;
 	char tbuf[20];
 	unsigned long kill_tasks;
 	int res;
@@ -2570,11 +2571,12 @@  static ssize_t write_kill_tasks(struct file *file, const char __user *buf,
 	if (res)
 		return res;
 
+	sn->kill_tasks = !!kill_tasks;
+
 	/* Kill pending tasks */
-	if (kill_tasks && !sn->kill_tasks)
+	if (sn->kill_tasks && !prev_kill_tasks)
 		rpc_kill_tasks(net);
 
-	sn->kill_tasks = !!kill_tasks;
 	return count;
 }