Skip to content

Commit 17f09d3

Browse files
amschuma-ntapTrond Myklebust
authored andcommitted
SUNRPC: Check if the xprt is connected before handling sysfs reads
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]>
1 parent 4330fe3 commit 17f09d3

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

net/sunrpc/sysfs.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,10 @@ static ssize_t rpc_sysfs_xprt_srcaddr_show(struct kobject *kobj,
109109
struct sock_xprt *sock;
110110
ssize_t ret = -1;
111111

112-
if (!xprt)
113-
return 0;
112+
if (!xprt || !xprt_connected(xprt)) {
113+
xprt_put(xprt);
114+
return -ENOTCONN;
115+
}
114116

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

132-
if (!xprt)
133-
return 0;
134+
if (!xprt || !xprt_connected(xprt)) {
135+
xprt_put(xprt);
136+
return -ENOTCONN;
137+
}
134138

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

0 commit comments

Comments
 (0)