Linux Netfilter development
 help / color / mirror / Atom feed
* [PATCH nf 1/2] netfilter: nft_socket: fix sk refcount leaks
@ 2024-09-05 10:54 Florian Westphal
  2024-09-05 10:54 ` [PATCH nf 2/2] netfilter: nft_socket: make cgroupsv2 matching work with namespaces Florian Westphal
  0 siblings, 1 reply; 5+ messages in thread
From: Florian Westphal @ 2024-09-05 10:54 UTC (permalink / raw)
  To: netfilter-devel; +Cc: Florian Westphal

We must put 'sk' reference before returning.

Fixes: 039b1f4f24ec ("netfilter: nft_socket: fix erroneous socket assignment")
Signed-off-by: Florian Westphal <fw@strlen.de>
---
 net/netfilter/nft_socket.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/net/netfilter/nft_socket.c b/net/netfilter/nft_socket.c
index f30163e2ca62..765ffd6e06bc 100644
--- a/net/netfilter/nft_socket.c
+++ b/net/netfilter/nft_socket.c
@@ -110,13 +110,13 @@ static void nft_socket_eval(const struct nft_expr *expr,
 			*dest = READ_ONCE(sk->sk_mark);
 		} else {
 			regs->verdict.code = NFT_BREAK;
-			return;
+			goto out_put_sk;
 		}
 		break;
 	case NFT_SOCKET_WILDCARD:
 		if (!sk_fullsock(sk)) {
 			regs->verdict.code = NFT_BREAK;
-			return;
+			goto out_put_sk;
 		}
 		nft_socket_wildcard(pkt, regs, sk, dest);
 		break;
@@ -124,7 +124,7 @@ static void nft_socket_eval(const struct nft_expr *expr,
 	case NFT_SOCKET_CGROUPV2:
 		if (!nft_sock_get_eval_cgroupv2(dest, sk, pkt, priv->level)) {
 			regs->verdict.code = NFT_BREAK;
-			return;
+			goto out_put_sk;
 		}
 		break;
 #endif
@@ -133,6 +133,7 @@ static void nft_socket_eval(const struct nft_expr *expr,
 		regs->verdict.code = NFT_BREAK;
 	}
 
+out_put_sk:
 	if (sk != skb->sk)
 		sock_gen_put(sk);
 }
-- 
2.44.2


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

end of thread, other threads:[~2024-09-08 17:07 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-09-05 10:54 [PATCH nf 1/2] netfilter: nft_socket: fix sk refcount leaks Florian Westphal
2024-09-05 10:54 ` [PATCH nf 2/2] netfilter: nft_socket: make cgroupsv2 matching work with namespaces Florian Westphal
2024-09-06 19:39   ` kernel test robot
2024-09-07 14:07     ` [PATCH nf v2 " Florian Westphal
2024-09-08 17:06   ` [PATCH nf " kernel test robot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox