diff mbox series

netfilter: seqadj: check seq offset before update

Message ID 20211224023713.9260-1-zhangkaiheb@126.com (mailing list archive)
State Awaiting Upstream
Delegated to: Netdev Maintainers
Headers show
Series netfilter: seqadj: check seq offset before update | expand

Checks

Context Check Description
netdev/tree_selection success Guessed tree name to be net-next
netdev/fixes_present success Fixes tag not required for -next series
netdev/subject_prefix warning Target tree name not specified in the subject
netdev/cover_letter success Single patches do not need cover letters
netdev/patch_count success Link
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 0 this patch: 0
netdev/cc_maintainers success CCed 8 of 8 maintainers
netdev/build_clang success Errors and warnings before: 0 this patch: 0
netdev/module_param success Was 0 now: 0
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 0 this patch: 0
netdev/checkpatch warning WARNING: line length of 86 exceeds 80 columns
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

kai zhang Dec. 24, 2021, 2:37 a.m. UTC
if seq/ack offset is zero, don't update

Signed-off-by: zhang kai <zhangkaiheb@126.com>
---
 net/netfilter/nf_conntrack_seqadj.c | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)

Comments

Pablo Neira Ayuso Jan. 6, 2022, 9:53 p.m. UTC | #1
On Fri, Dec 24, 2021 at 10:37:13AM +0800, zhang kai wrote:
> 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.

> Signed-off-by: zhang kai <zhangkaiheb@126.com>
> ---
>  net/netfilter/nf_conntrack_seqadj.c | 15 ++++++++++-----
>  1 file changed, 10 insertions(+), 5 deletions(-)
> 
> diff --git a/net/netfilter/nf_conntrack_seqadj.c b/net/netfilter/nf_conntrack_seqadj.c
> index 3066449f8bd8..d35e272a2e36 100644
> --- a/net/netfilter/nf_conntrack_seqadj.c
> +++ b/net/netfilter/nf_conntrack_seqadj.c
> @@ -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);
> -- 
> 2.17.1
>
diff mbox series

Patch

diff --git a/net/netfilter/nf_conntrack_seqadj.c b/net/netfilter/nf_conntrack_seqadj.c
index 3066449f8bd8..d35e272a2e36 100644
--- a/net/netfilter/nf_conntrack_seqadj.c
+++ b/net/netfilter/nf_conntrack_seqadj.c
@@ -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);