Commit 8b26ff7a authored by Florian Westphal's avatar Florian Westphal Committed by Pablo Neira Ayuso

netfilter: nft_socket: fix sk refcount leaks

We must put 'sk' reference before returning.

Fixes: 039b1f4f ("netfilter: nft_socket: fix erroneous socket assignment")
Signed-off-by: default avatarFlorian Westphal <fw@strlen.de>
Signed-off-by: default avatarPablo Neira Ayuso <pablo@netfilter.org>
parent d759ee24
...@@ -110,13 +110,13 @@ static void nft_socket_eval(const struct nft_expr *expr, ...@@ -110,13 +110,13 @@ static void nft_socket_eval(const struct nft_expr *expr,
*dest = READ_ONCE(sk->sk_mark); *dest = READ_ONCE(sk->sk_mark);
} else { } else {
regs->verdict.code = NFT_BREAK; regs->verdict.code = NFT_BREAK;
return; goto out_put_sk;
} }
break; break;
case NFT_SOCKET_WILDCARD: case NFT_SOCKET_WILDCARD:
if (!sk_fullsock(sk)) { if (!sk_fullsock(sk)) {
regs->verdict.code = NFT_BREAK; regs->verdict.code = NFT_BREAK;
return; goto out_put_sk;
} }
nft_socket_wildcard(pkt, regs, sk, dest); nft_socket_wildcard(pkt, regs, sk, dest);
break; break;
...@@ -124,7 +124,7 @@ static void nft_socket_eval(const struct nft_expr *expr, ...@@ -124,7 +124,7 @@ static void nft_socket_eval(const struct nft_expr *expr,
case NFT_SOCKET_CGROUPV2: case NFT_SOCKET_CGROUPV2:
if (!nft_sock_get_eval_cgroupv2(dest, sk, pkt, priv->level)) { if (!nft_sock_get_eval_cgroupv2(dest, sk, pkt, priv->level)) {
regs->verdict.code = NFT_BREAK; regs->verdict.code = NFT_BREAK;
return; goto out_put_sk;
} }
break; break;
#endif #endif
...@@ -133,6 +133,7 @@ static void nft_socket_eval(const struct nft_expr *expr, ...@@ -133,6 +133,7 @@ static void nft_socket_eval(const struct nft_expr *expr,
regs->verdict.code = NFT_BREAK; regs->verdict.code = NFT_BREAK;
} }
out_put_sk:
if (sk != skb->sk) if (sk != skb->sk)
sock_gen_put(sk); sock_gen_put(sk);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment