Skip to contentSkip to conversation

netfilter: only call csum_tcpudp_magic for TCP/UDP packets

PATCH In review Li RongQing 2 participants 3 messages Nov 13, 2019 – Dec 3, 2019

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 netfilter: only call csum_tcpudp_magic for TCP/UDP packets

csum_tcpudp_magic should not be called to compute checksum for non-TCP/UDP packets, like ICMP with wrong checksum

Fixes 5d1549847c76 ("netfilter: Fix remainder of pseudo-header protocol 0")

---
diff with v1:
rewrite the code as suggested
add fixes tag

 net/netfilter/utils.c | 21 +++++++++++++++------
 1 file changed, 15 insertions(+), 6 deletions(-)
net/netfilter/utils.c +15 -6
index 51b454d8fa9c..0f78416566fa 100644
@@ -17,12 +17,21 @@ __sum16 nf_ip_checksum(struct sk_buff *skb, unsigned int hook,
 	case CHECKSUM_COMPLETE:
 		if (hook != NF_INET_PRE_ROUTING && hook != NF_INET_LOCAL_IN)
 			break;
-		if ((protocol != IPPROTO_TCP && protocol != IPPROTO_UDP &&
-		    !csum_fold(skb->csum)) ||
-		    !csum_tcpudp_magic(iph->saddr, iph->daddr,
-				       skb->len - dataoff, protocol,
-				       skb->csum)) {
-			skb->ip_summed = CHECKSUM_UNNECESSARY;
+		switch (protocol) {
+		case IPPROTO_TCP:
+		case IPPROTO_UDP:
+			if (!csum_tcpudp_magic(iph->saddr, iph->daddr,
+					    skb->len - dataoff,
+					    protocol, skb->csum)) {
+				skb->ip_summed = CHECKSUM_UNNECESSARY;
+				return 0;
+			}
+			break;
+		default:
+			if (!csum_fold(skb->csum)) {
+				skb->ip_summed = CHECKSUM_UNNECESSARY;
+				return 0;
+			}
 			break;
 		}
 		/* fall through */
Signature · 1 line
2.16.2
#1 lore raw

Hi,

Quoted 19 lines · Li RongQing

csum_tcpudp_magic should not be called to compute checksum for non-TCP/UDP packets, like ICMP with wrong checksum

Fixes 5d1549847c76 ("netfilter: Fix remainder of pseudo-header protocol 0")

---
diff with v1:
rewrite the code as suggested
add fixes tag

 net/netfilter/utils.c | 21 +++++++++++++++------
 1 file changed, 15 insertions(+), 6 deletions(-)
net/netfilter/utils.c +0 -0
index 51b454d8fa9c..0f78416566fa 100644

net/netfilter/utils.c __sum16 nf_ip_checksum(struct sk_buff *skb, unsigned int hook, · line 24

Quoted 8 lines
net/netfilter/utils.c +0 -5
@@ -17,12 +17,21 @@ __sum16 nf_ip_checksum(struct sk_buff *skb, unsigned int hook,
 	case CHECKSUM_COMPLETE:
 		if (hook != NF_INET_PRE_ROUTING && hook != NF_INET_LOCAL_IN)
 			break;
-		if ((protocol != IPPROTO_TCP && protocol != IPPROTO_UDP &&
-		    !csum_fold(skb->csum)) ||
-		    !csum_tcpudp_magic(iph->saddr, iph->daddr,
-				       skb->len - dataoff, protocol,
-				       skb->csum)) {

Could you describe what you observe there to tag this patch as a Fix?

Thanks.

#2 lore raw
Quoted 5 lines

net/netfilter/utils.c __sum16 nf_ip_checksum(struct sk_buff *skb, unsigned int hook, · line 24

Quoted 2 lines
net/netfilter/utils.c +0 -2
-				       skb->len - dataoff, protocol,
-				       skb->csum)) {

Could you describe what you observe there to tag this patch as a Fix?

nothing, this fix tag can be dropped

I find this unreasonable codes when I read, it should have little negative effect.

thanks

-Li