Skip to contentSkip to conversation

netfilter: nft_socket: fix erroneous socket assignment

PATCH Superseded Fernando Fernandez Mancera 2 participants 3 messages Aug 31, 2019

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 netfilter: nft_socket: fix erroneous socket assignment

This socket assignment was unnecessary and also added a missing sock_gen_put().

Fixes 554ced0a6e29 ("netfilter: nf_tables: add support for native socket matching")
---
 net/netfilter/nft_socket.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
net/netfilter/nft_socket.c +3 -3
index d7f3776dfd71..637ce3e8c575 100644
@@ -47,9 +47,6 @@ static void nft_socket_eval(const struct nft_expr *expr,
 		return;
 	}
 
-	/* So that subsequent socket matching not to require other lookups. */
-	skb->sk = sk;
-
 	switch(priv->key) {
 	case NFT_SOCKET_TRANSPARENT:
 		nft_reg_store8(dest, inet_sk_transparent(sk));
@@ -66,6 +63,9 @@ static void nft_socket_eval(const struct nft_expr *expr,
 		WARN_ON(1);
 		regs->verdict.code = NFT_BREAK;
 	}
+
+	if (sk != skb->sk)
+		sock_gen_put(sk);
 }
 
 static const struct nla_policy nft_socket_policy[NFTA_SOCKET_MAX + 1] = {
Signature · 1 line
2.20.1
#1 lore raw

This patch fixes https://bugzilla.redhat.com/show_bug.cgi?id=1651813. I didn't include this link into the commit message because I don't know if it is appropiate. Thanks! :-)

Quoted 33 lines · Fernando Fernandez Mancera

This socket assignment was unnecessary and also added a missing sock_gen_put().

Fixes 554ced0a6e29 ("netfilter: nf_tables: add support for native socket matching")
---
 net/netfilter/nft_socket.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
net/netfilter/nft_socket.c +3 -3
index d7f3776dfd71..637ce3e8c575 100644
@@ -47,9 +47,6 @@ static void nft_socket_eval(const struct nft_expr *expr,
 		return;
 	}
 
-	/* So that subsequent socket matching not to require other lookups. */
-	skb->sk = sk;
-
 	switch(priv->key) {
 	case NFT_SOCKET_TRANSPARENT:
 		nft_reg_store8(dest, inet_sk_transparent(sk));
@@ -66,6 +63,9 @@ static void nft_socket_eval(const struct nft_expr *expr,
 		WARN_ON(1);
 		regs->verdict.code = NFT_BREAK;
 	}
+
+	if (sk != skb->sk)
+		sock_gen_put(sk);
 }
 
 static const struct nla_policy nft_socket_policy[NFTA_SOCKET_MAX + 1] = {
maintainer
#2 lore raw
In reply to Fernando Fernandez Mancera
Quoted 1 line · Fernando Fernandez Mancera

This socket assignment was unnecessary and also added a missing sock_gen_put().

The socket assignment is wrong, see skb_orphan():
When skb->destructor callback is not set, but skb->sk is set, this hits BUG().

You could add a 'Link: ' to the bugzilla ticket if you like. Patch looks good, thanks for fixing this Fernando!