Skip to content

Commit

Permalink
net/sunrpc: fix potential memory leaks in rpc_sysfs_xprt_state_change()
Browse files Browse the repository at this point in the history
commit bfc48f1 upstream.

The issue happens on some error handling paths. When the function
fails to grab the object `xprt`, it simply returns 0, forgetting to
decrease the reference count of another object `xps`, which is
increased by rpc_sysfs_xprt_kobj_get_xprt_switch(), causing refcount
leaks. Also, the function forgets to check whether `xps` is valid
before using it, which may result in NULL-dereferencing issues.

Fix it by adding proper error handling code when either `xprt` or
`xps` is NULL.

Fixes: 5b7eb78 ("SUNRPC: take a xprt offline using sysfs")
Signed-off-by: Xin Xiong <xiongx18@fudan.edu.cn>
Signed-off-by: Xin Tan <tanxin.ctf@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
  • Loading branch information
Conchy-Conchy authored and gregkh committed Aug 25, 2022
1 parent 181c691 commit 76fbeb1
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions net/sunrpc/sysfs.c
Expand Up @@ -291,8 +291,10 @@ static ssize_t rpc_sysfs_xprt_state_change(struct kobject *kobj,
int offline = 0, online = 0, remove = 0;
struct rpc_xprt_switch *xps = rpc_sysfs_xprt_kobj_get_xprt_switch(kobj);

if (!xprt)
return 0;
if (!xprt || !xps) {
count = 0;
goto out_put;
}

if (!strncmp(buf, "offline", 7))
offline = 1;
Expand Down

0 comments on commit 76fbeb1

Please sign in to comment.