[PATCH AUTOSEL 5.4 07/14] phonet: refcount leak in pep_sock_accep

From: Sasha Levin
Date: Mon Dec 20 2021 - 21:01:36 EST


From: Hangyu Hua <hbh25y@xxxxxxxxx>

[ Upstream commit bcd0f93353326954817a4f9fa55ec57fb38acbb0 ]

sock_hold(sk) is invoked in pep_sock_accept(), but __sock_put(sk) is not
invoked in subsequent failure branches(pep_accept_conn() != 0).

Signed-off-by: Hangyu Hua <hbh25y@xxxxxxxxx>
Link: https://lore.kernel.org/r/20211209082839.33985-1-hbh25y@xxxxxxxxx
Signed-off-by: Jakub Kicinski <kuba@xxxxxxxxxx>
Signed-off-by: Sasha Levin <sashal@xxxxxxxxxx>
---
net/phonet/pep.c | 1 +
1 file changed, 1 insertion(+)

diff --git a/net/phonet/pep.c b/net/phonet/pep.c
index 4577e43cb7778..ea3b480ce20d9 100644
--- a/net/phonet/pep.c
+++ b/net/phonet/pep.c
@@ -868,6 +868,7 @@ static struct sock *pep_sock_accept(struct sock *sk, int flags, int *errp,

err = pep_accept_conn(newsk, skb);
if (err) {
+ __sock_put(sk);
sock_put(newsk);
newsk = NULL;
goto drop;
--
2.34.1