* [PATCH] net/sunrpc: fix potential memory leaks in rpc_sysfs_xprt_state_change()
@ 2022-08-10 15:29 Xin Xiong
2022-08-12 10:30 ` patchwork-bot+netdevbpf
0 siblings, 1 reply; 2+ messages in thread
From: Xin Xiong @ 2022-08-10 15:29 UTC (permalink / raw)
To: Trond Myklebust, Anna Schumaker, Chuck Lever, Jeff Layton,
“David S . Miller ,
Eric Dumazet, Jakub Kicinski, Paolo Abeni, Olga Kornievskaia,
linux-nfs, netdev, linux-kernel
Cc: yuanxzhang, Xin Xiong, Xin Tan
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>
---
net/sunrpc/sysfs.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/net/sunrpc/sysfs.c b/net/sunrpc/sysfs.c
index a3a2f8aeb80e..d1a15c6d3fd9 100644
--- a/net/sunrpc/sysfs.c
+++ b/net/sunrpc/sysfs.c
@@ -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;
--
2.25.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] net/sunrpc: fix potential memory leaks in rpc_sysfs_xprt_state_change()
2022-08-10 15:29 [PATCH] net/sunrpc: fix potential memory leaks in rpc_sysfs_xprt_state_change() Xin Xiong
@ 2022-08-12 10:30 ` patchwork-bot+netdevbpf
0 siblings, 0 replies; 2+ messages in thread
From: patchwork-bot+netdevbpf @ 2022-08-12 10:30 UTC (permalink / raw)
To: Xin Xiong
Cc: trond.myklebust, anna, chuck.lever, jlayton, davem, edumazet,
kuba, pabeni, kolga, linux-nfs, netdev, linux-kernel, yuanxzhang,
tanxin.ctf
Hello:
This patch was applied to netdev/net.git (master)
by David S. Miller <davem@davemloft.net>:
On Wed, 10 Aug 2022 23:29:13 +0800 you wrote:
> 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.
>
> [...]
Here is the summary with links:
- net/sunrpc: fix potential memory leaks in rpc_sysfs_xprt_state_change()
https://git.kernel.org/netdev/net/c/bfc48f1b0505
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2022-08-12 10:31 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-08-10 15:29 [PATCH] net/sunrpc: fix potential memory leaks in rpc_sysfs_xprt_state_change() Xin Xiong
2022-08-12 10:30 ` patchwork-bot+netdevbpf
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).