Netdev Archive on lore.kernel.org
help / color / mirror / Atom feed
* [PATCH] net: qrtr: fix memory leak in qrtr_local_enqueue
@ 2021-07-22 16:16 Pavel Skripkin
  2021-07-23 12:27 ` Manivannan Sadhasivam
  0 siblings, 1 reply; 6+ messages in thread
From: Pavel Skripkin @ 2021-07-22 16:16 UTC (permalink / raw)
  To: mani, davem, kuba, bjorn.andersson, courtney.cavin
  Cc: linux-arm-msm, netdev, linux-kernel, Pavel Skripkin,
	syzbot+35a511c72ea7356cdcf3

Syzbot reported memory leak in qrtr. The problem was in unputted
struct sock. qrtr_local_enqueue() function calls qrtr_port_lookup()
which takes sock reference if port was found. Then there is the following
check:

if (!ipc || &ipc->sk == skb->sk) {
	...
	return -ENODEV;
}

Since we should drop the reference before returning from this function and
ipc can be non-NULL inside this if, we should add qrtr_port_put() inside
this if.

Fixes: bdabad3e363d ("net: Add Qualcomm IPC router")
Reported-and-tested-by: syzbot+35a511c72ea7356cdcf3@syzkaller.appspotmail.com
Signed-off-by: Pavel Skripkin <paskripkin@gmail.com>
---
 net/qrtr/qrtr.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/net/qrtr/qrtr.c b/net/qrtr/qrtr.c
index e6f4a6202f82..d5ce428d0b25 100644
--- a/net/qrtr/qrtr.c
+++ b/net/qrtr/qrtr.c
@@ -839,6 +839,8 @@ static int qrtr_local_enqueue(struct qrtr_node *node, struct sk_buff *skb,
 
 	ipc = qrtr_port_lookup(to->sq_port);
 	if (!ipc || &ipc->sk == skb->sk) { /* do not send to self */
+		if (ipc)
+			qrtr_port_put(ipc);
 		kfree_skb(skb);
 		return -ENODEV;
 	}
-- 
2.32.0


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2021-07-23 16:50 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-22 16:16 [PATCH] net: qrtr: fix memory leak in qrtr_local_enqueue Pavel Skripkin
2021-07-23 12:27 ` Manivannan Sadhasivam
2021-07-23 15:08   ` Pavel Skripkin
2021-07-23 15:31   ` [PATCH v2] net: qrtr: fix memory leaks Pavel Skripkin
2021-07-23 15:43     ` Manivannan Sadhasivam
2021-07-23 16:50     ` 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).