net/sunrpc: fix reference count leaks in rpc_sysfs_xprt_state_change
authorXiyu Yang <xiyuyang19@fudan.edu.cn>
Thu, 9 Sep 2021 04:32:38 +0000 (12:32 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 16 Feb 2022 11:56:10 +0000 (12:56 +0100)
commit4b22aa42bd4d2d630ef1854c139275c3532937cb
tree5cd0a8c6120b460903b1da62496405bc6f177c9e
parent5ca123c91a64a85230272136b756c78d632d21c5
net/sunrpc: fix reference count leaks in rpc_sysfs_xprt_state_change

[ Upstream commit 776d794f28c95051bc70405a7b1fa40115658a18 ]

The refcount leak issues take place in an error handling path. When the
3rd argument buf doesn't match with "offline", "online" or "remove", the
function simply returns -EINVAL and forgets to decrease the reference
count of a rpc_xprt object and a rpc_xprt_switch object increased by
rpc_sysfs_xprt_kobj_get_xprt() and
rpc_sysfs_xprt_kobj_get_xprt_switch(), causing reference count leaks of
both unused objects.

Fix this issue by jumping to the error handling path labelled with
out_put when buf matches none of "offline", "online" or "remove".

Signed-off-by: Xiyu Yang <xiyuyang19@fudan.edu.cn>
Signed-off-by: Xin Xiong <xiongx18@fudan.edu.cn>
Signed-off-by: Xin Tan <tanxin.ctf@gmail.com>
Signed-off-by: Anna Schumaker <Anna.Schumaker@Netapp.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
net/sunrpc/sysfs.c