[PATCH] ipv4: fix lock leaks

From: ycaibb
Date: Thu Jan 20 2022 - 22:12:03 EST


From: Ryan Cai <ycaibb@xxxxxxxxx>

In methods listening_get_first and listening_get_first in tcp_ipv4.c, there are lock leaks when seq_sk_match returns true.

Signed-off-by: Ryan Cai <ycaibb@xxxxxxxxx>
---
net/ipv4/tcp_ipv4.c | 2 ++
1 file changed, 2 insertions(+)

diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
index 13d868c43284..714107766035 100644
--- a/net/ipv4/tcp_ipv4.c
+++ b/net/ipv4/tcp_ipv4.c
@@ -2329,6 +2329,7 @@ static void *listening_get_first(struct seq_file *seq)
inet_lhash2_for_each_icsk(icsk, &ilb2->head) {
sk = (struct sock *)icsk;
if (seq_sk_match(seq, sk))
+ spin_unlock(&ilb2->lock);
return sk;
}
spin_unlock(&ilb2->lock);
@@ -2407,6 +2408,7 @@ static void *established_get_first(struct seq_file *seq)
spin_lock_bh(lock);
sk_nulls_for_each(sk, node, &tcp_hashinfo.ehash[st->bucket].chain) {
if (seq_sk_match(seq, sk))
+ spin_unlock_bh(lock);
return sk;
}
spin_unlock_bh(lock);
--
2.33.0