[PATCH] ipvs: Fix exception handling in two functions

Markus Elfring <[email protected]>
Newsgroups org.kernel.vger.lvs-devel,fr.inria.cocci
Message-ID <[email protected]>
Date: Fri, 7 Apr 2023 09:33:43 +0200

The label “tx_error” was used to jump to another pointer check
despite of the detail in these function implementations
that it was determined already that the corresponding variable
contained an error pointer because of a failed call of
the function “ip_vs_prepare_tunneled_skb”.

* Thus use an additional label.

* Delete two redundant checks.


This issue was detected by using the Coccinelle software.

Fixes: ea1d5d7755a3e556de78cc757d1895d5c7180548 ("ipvs: properly declare tunnel encapsulation")
Signed-off-by: Markus Elfring <[email protected]>
---
 net/netfilter/ipvs/ip_vs_xmit.c | 20 ++++++++------------
 1 file changed, 8 insertions(+), 12 deletions(-)

diff --git a/net/netfilter/ipvs/ip_vs_xmit.c b/net/netfilter/ipvs/ip_vs_xmit.c
index 99c349c0d968..68343ee380e1 100644
--- a/net/netfilter/ipvs/ip_vs_xmit.c
+++ b/net/netfilter/ipvs/ip_vs_xmit.c
@@ -1199,7 +1199,7 @@ ip_vs_tunnel_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
 					 &next_protocol, NULL, &dsfield,
 					 &ttl, dfp);
 	if (IS_ERR(skb))
-		goto tx_error;
+		goto leave_function;

 	gso_type = __tun_gso_type_mask(AF_INET, cp->af);
 	if (tun_type == IP_VS_CONN_F_TUNNEL_TYPE_GUE) {
@@ -1266,16 +1266,14 @@ ip_vs_tunnel_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
 		ip_local_out(net, skb->sk, skb);
 	else if (ret == NF_DROP)
 		kfree_skb(skb);
-
+leave_function:
 	LeaveFunction(10);

 	return NF_STOLEN;

   tx_error:
-	if (!IS_ERR(skb))
-		kfree_skb(skb);
-	LeaveFunction(10);
-	return NF_STOLEN;
+	kfree_skb(skb);
+	goto leave_function;
 }

 #ifdef CONFIG_IP_VS_IPV6
@@ -1347,7 +1345,7 @@ ip_vs_tunnel_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
 					 &next_protocol, &payload_len,
 					 &dsfield, &ttl, NULL);
 	if (IS_ERR(skb))
-		goto tx_error;
+		goto leave_function;

 	gso_type = __tun_gso_type_mask(AF_INET6, cp->af);
 	if (tun_type == IP_VS_CONN_F_TUNNEL_TYPE_GUE) {
@@ -1413,16 +1411,14 @@ ip_vs_tunnel_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
 		ip6_local_out(net, skb->sk, skb);
 	else if (ret == NF_DROP)
 		kfree_skb(skb);
-
+leave_function:
 	LeaveFunction(10);

 	return NF_STOLEN;

 tx_error:
-	if (!IS_ERR(skb))
-		kfree_skb(skb);
-	LeaveFunction(10);
-	return NF_STOLEN;
+	kfree_skb(skb);
+	goto leave_function;
 }
 #endif

--
2.40.0
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.