net/sunrpc: fix potential memory leaks in rpc_sysfs_xprt_state_change()
authorXin Xiong <xiongx18@fudan.edu.cn>
Wed, 10 Aug 2022 15:29:13 +0000 (23:29 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 25 Aug 2022 09:40:23 +0000 (11:40 +0200)
commitc0434f0e058648649250b8ed6078b66d773de723
treef9ebe86cf81cc1e008138a45307599ee550a309f
parentdd32ea395658e36453468d2ad8e52fe6bcfdc53d
net/sunrpc: fix potential memory leaks in rpc_sysfs_xprt_state_change()

commit bfc48f1b0505ffcb03a6d749139b7577d6b81ae0 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: 5b7eb78486cd ("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>
net/sunrpc/sysfs.c