All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] netfilter: seqadj: check seq offset before update
@ 2021-12-24  2:37 zhang kai
  2022-01-06 21:53 ` Pablo Neira Ayuso
  0 siblings, 1 reply; 2+ messages in thread
From: zhang kai @ 2021-12-24  2:37 UTC (permalink / raw)
  To: pablo, kadlec, fw, davem, kuba, netfilter-devel, coreteam,
	netdev, linux-kernel
  Cc: zhang kai

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(-)

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


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] netfilter: seqadj: check seq offset before update
  2021-12-24  2:37 [PATCH] netfilter: seqadj: check seq offset before update zhang kai
@ 2022-01-06 21:53 ` Pablo Neira Ayuso
  0 siblings, 0 replies; 2+ messages in thread
From: Pablo Neira Ayuso @ 2022-01-06 21:53 UTC (permalink / raw)
  To: zhang kai
  Cc: kadlec, fw, davem, kuba, netfilter-devel, coreteam, netdev, linux-kernel

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
> 

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-01-06 21:53 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-12-24  2:37 [PATCH] netfilter: seqadj: check seq offset before update zhang kai
2022-01-06 21:53 ` Pablo Neira Ayuso

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.