Skip to contentSkip to conversation

netfilter: seqadj: check seq offset before update

PATCH In review zhang kai 2 participants 2 messages Dec 24, 2021 – Jan 6, 2022

Subsystems (3)
lore
Share & tools
lore

zhang kai

author
#0 lore raw

PATCH 1/1 netfilter: seqadj: check seq offset before update

if seq/ack offset is zero, don't update

---
 net/netfilter/nf_conntrack_seqadj.c | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)
net/netfilter/nf_conntrack_seqadj.c +10 -5
index 3066449f8bd8..d35e272a2e36 100644
@@ -186,11 +186,13 @@ int nf_ct_seq_adjust(struct sk_buff *skb,
 	else
 		seqoff = this_way->offset_before;
 
-	newseq = htonl(ntohl(tcph->seq) + seqoff);
-	inet_proto_csum_replace4(&tcph->check, skb, tcph->seq, newseq, false);
-	pr_debug("Adjusting sequence number from %u->%u\n",
-		 ntohl(tcph->seq), ntohl(newseq));
-	tcph->seq = newseq;
+	if (seqoff) {
+		newseq = htonl(ntohl(tcph->seq) + seqoff);
+		inet_proto_csum_replace4(&tcph->check, skb, tcph->seq, newseq, false);
+		pr_debug("Adjusting sequence number from %u->%u\n",
+			 ntohl(tcph->seq), ntohl(newseq));
+		tcph->seq = newseq;
+	}
 
 	if (!tcph->ack)
 		goto out;
@@ -201,6 +203,9 @@ int nf_ct_seq_adjust(struct sk_buff *skb,
 	else
 		ackoff = other_way->offset_before;
 
+	if (!ackoff)
+		goto out;
+
 	newack = htonl(ntohl(tcph->ack_seq) - ackoff);
 	inet_proto_csum_replace4(&tcph->check, skb, tcph->ack_seq, newack,
 				 false);
Signature · 1 line
2.17.1
#1 lore raw
Quoted 1 line · zhang kai

if seq/ack offset is zero, don't update

Please, provide more details: explain the scenario that triggers and seq/ack offset adjustment of zero, describe the scenario that triggers the bug, etc.

Quoted 41 lines
---
 net/netfilter/nf_conntrack_seqadj.c | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)
net/netfilter/nf_conntrack_seqadj.c +10 -5
index 3066449f8bd8..d35e272a2e36 100644
@@ -186,11 +186,13 @@ int nf_ct_seq_adjust(struct sk_buff *skb,
 	else
 		seqoff = this_way->offset_before;
 
-	newseq = htonl(ntohl(tcph->seq) + seqoff);
-	inet_proto_csum_replace4(&tcph->check, skb, tcph->seq, newseq, false);
-	pr_debug("Adjusting sequence number from %u->%u\n",
-		 ntohl(tcph->seq), ntohl(newseq));
-	tcph->seq = newseq;
+	if (seqoff) {
+		newseq = htonl(ntohl(tcph->seq) + seqoff);
+		inet_proto_csum_replace4(&tcph->check, skb, tcph->seq, newseq, false);
+		pr_debug("Adjusting sequence number from %u->%u\n",
+			 ntohl(tcph->seq), ntohl(newseq));
+		tcph->seq = newseq;
+	}
 
 	if (!tcph->ack)
 		goto out;
@@ -201,6 +203,9 @@ int nf_ct_seq_adjust(struct sk_buff *skb,
 	else
 		ackoff = other_way->offset_before;
 
+	if (!ackoff)
+		goto out;
+
 	newack = htonl(ntohl(tcph->ack_seq) - ackoff);
 	inet_proto_csum_replace4(&tcph->check, skb, tcph->ack_seq, newack,
 				 false);
Signature · 1 line
2.17.1