]> git.baikalelectronics.ru Git - kernel.git/commit
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)
committerDavid S. Miller <davem@davemloft.net>
Fri, 12 Aug 2022 10:21:28 +0000 (11:21 +0100)
commit35d9c59d826ae1ff7a4fee62e8c2fb683b5ef849
tree02acba0b72a6045625b6111c25b47642039af5e1
parent758db2054af5df6d21f7e947843f8867458e12ad
net/sunrpc: fix potential memory leaks in rpc_sysfs_xprt_state_change()

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: 3e769b79ea0d ("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>
net/sunrpc/sysfs.c