Skip to content

Commit

Permalink
SUNRPC: Check if the xprt is connected before handling sysfs reads
Browse files Browse the repository at this point in the history
xprts don't immediately reconnect when changing the "dstaddr" property,
instead this gets handled the next time an operation uses the transport.
This could lead to NULL pointer dereferences when trying to read sysfs
files between the disconnect and reconnect operations. Fix this by
returning an error if the xprt is not connected.

Signed-off-by: Anna Schumaker <[email protected]>
Signed-off-by: Trond Myklebust <[email protected]>
  • Loading branch information
amschuma-ntap authored and Trond Myklebust committed Nov 4, 2021
1 parent 4330fe3 commit 17f09d3
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions net/sunrpc/sysfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,10 @@ static ssize_t rpc_sysfs_xprt_srcaddr_show(struct kobject *kobj,
struct sock_xprt *sock;
ssize_t ret = -1;

if (!xprt)
return 0;
if (!xprt || !xprt_connected(xprt)) {
xprt_put(xprt);
return -ENOTCONN;
}

sock = container_of(xprt, struct sock_xprt, xprt);
if (kernel_getsockname(sock->sock, (struct sockaddr *)&saddr) < 0)
Expand All @@ -129,8 +131,10 @@ static ssize_t rpc_sysfs_xprt_info_show(struct kobject *kobj,
struct rpc_xprt *xprt = rpc_sysfs_xprt_kobj_get_xprt(kobj);
ssize_t ret;

if (!xprt)
return 0;
if (!xprt || !xprt_connected(xprt)) {
xprt_put(xprt);
return -ENOTCONN;
}

ret = sprintf(buf, "last_used=%lu\ncur_cong=%lu\ncong_win=%lu\n"
"max_num_slots=%u\nmin_num_slots=%u\nnum_reqs=%u\n"
Expand Down

0 comments on commit 17f09d3

Please sign in to comment.