summaryrefslogtreecommitdiff
path: root/net/sunrpc/sysfs.c
diff options
context:
space:
mode:
authorNeilBrown <neilb@suse.de>2022-01-17 08:36:53 +0300
committerAnna Schumaker <Anna.Schumaker@Netapp.com>2022-02-08 17:14:26 +0300
commitb49ea673e119f59c71645e2f65b3ccad857c90ee (patch)
treef2c725e739f87b03ccbc0cababb25d71026b1f9a /net/sunrpc/sysfs.c
parent63db37e99ac17f575766c9317f927c8d4c6e8cdf (diff)
downloadlinux-b49ea673e119f59c71645e2f65b3ccad857c90ee.tar.xz
SUNRPC: lock against ->sock changing during sysfs read
->sock can be set to NULL asynchronously unless ->recv_mutex is held. So it is important to hold that mutex. Otherwise a sysfs read can trigger an oops. Commit 17f09d3f619a ("SUNRPC: Check if the xprt is connected before handling sysfs reads") appears to attempt to fix this problem, but it only narrows the race window. Fixes: 17f09d3f619a ("SUNRPC: Check if the xprt is connected before handling sysfs reads") Fixes: a8482488a7d6 ("SUNRPC query transport's source port") Signed-off-by: NeilBrown <neilb@suse.de> Signed-off-by: Anna Schumaker <Anna.Schumaker@Netapp.com>
Diffstat (limited to 'net/sunrpc/sysfs.c')
-rw-r--r--net/sunrpc/sysfs.c5
1 files changed, 4 insertions, 1 deletions
diff --git a/net/sunrpc/sysfs.c b/net/sunrpc/sysfs.c
index b64a0286b182..05c758da6a92 100644
--- a/net/sunrpc/sysfs.c
+++ b/net/sunrpc/sysfs.c
@@ -115,11 +115,14 @@ static ssize_t rpc_sysfs_xprt_srcaddr_show(struct kobject *kobj,
}
sock = container_of(xprt, struct sock_xprt, xprt);
- if (kernel_getsockname(sock->sock, (struct sockaddr *)&saddr) < 0)
+ mutex_lock(&sock->recv_mutex);
+ if (sock->sock == NULL ||
+ kernel_getsockname(sock->sock, (struct sockaddr *)&saddr) < 0)
goto out;
ret = sprintf(buf, "%pISc\n", &saddr);
out:
+ mutex_unlock(&sock->recv_mutex);
xprt_put(xprt);
return ret + 1;
}