netfilter-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 0/2] netfilter: nfqueue: incorrect sctp checksum
@ 2024-05-13  0:09 Antonio Ojea
  2024-05-13  0:09 ` [PATCH v2 1/2] netfilter: nft_queue: compute SCTP checksum Antonio Ojea
  2024-05-13  0:09 ` [PATCH v2 2/2] selftests: net: netfilter: nft_queue.sh: sctp checksum Antonio Ojea
  0 siblings, 2 replies; 5+ messages in thread
From: Antonio Ojea @ 2024-05-13  0:09 UTC (permalink / raw)
  To: netfilter-devel; +Cc: pablo, fw, Antonio Ojea

Fixes the bug described in
https://bugzilla.netfilter.org/show_bug.cgi?id=1742
causing netfilter to drop SCTP packets when using
nfqueue and GSO due to incorrect checksum.

Patch 1 adds a new helper to process the sctp checksum
correctly.

Patch 2 adds a selftest regression test.

Antonio Ojea (2):
  netfilter: nft_queue: compute SCTP checksum
  selftests: net: netfilter: nft_queue.sh: sctp checksum

 net/netfilter/nfnetlink_queue.c               | 10 ++++-
 .../selftests/net/netfilter/nft_queue.sh      | 38 +++++++++++++++++++
 2 files changed, 47 insertions(+), 1 deletion(-)

-- 
2.45.0.118.g7fe29c98d7-goog


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

* [PATCH v2 1/2] netfilter: nft_queue: compute SCTP checksum
  2024-05-13  0:09 [PATCH v2 0/2] netfilter: nfqueue: incorrect sctp checksum Antonio Ojea
@ 2024-05-13  0:09 ` Antonio Ojea
  2024-05-13 21:14   ` Florian Westphal
  2024-05-13  0:09 ` [PATCH v2 2/2] selftests: net: netfilter: nft_queue.sh: sctp checksum Antonio Ojea
  1 sibling, 1 reply; 5+ messages in thread
From: Antonio Ojea @ 2024-05-13  0:09 UTC (permalink / raw)
  To: netfilter-devel; +Cc: pablo, fw, Antonio Ojea

when packet is enqueued with nfqueue and GSO is enabled, checksum
calculation has to take into account the protocol, as SCTP uses a
32 bits CRC checksum.

Signed-off-by: Antonio Ojea <aojea@google.com>
---
V1 -> V2: add a helper function to process the checksum

 net/netfilter/nfnetlink_queue.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/net/netfilter/nfnetlink_queue.c b/net/netfilter/nfnetlink_queue.c
index 00f4bd21c59b..accf4942d9ff 100644
--- a/net/netfilter/nfnetlink_queue.c
+++ b/net/netfilter/nfnetlink_queue.c
@@ -538,6 +538,14 @@ static int nfqnl_put_bridge(struct nf_queue_entry *entry, struct sk_buff *skb)
 	return -1;
 }
 
+static int nf_queue_checksum_help(struct sk_buff *entskb)
+{
+  if (skb_csum_is_sctp(entskb))
+    return skb_crc32c_csum_help(entskb);
+
+  return skb_checksum_help(entskb);
+}
+
 static struct sk_buff *
 nfqnl_build_packet_message(struct net *net, struct nfqnl_instance *queue,
 			   struct nf_queue_entry *entry,
@@ -600,7 +608,7 @@ nfqnl_build_packet_message(struct net *net, struct nfqnl_instance *queue,
 	case NFQNL_COPY_PACKET:
 		if (!(queue->flags & NFQA_CFG_F_GSO) &&
 		    entskb->ip_summed == CHECKSUM_PARTIAL &&
-		    skb_checksum_help(entskb))
+		    nf_queue_checksum_help(entskb))
 			return NULL;
 
 		data_len = READ_ONCE(queue->copy_range);
-- 
2.45.0.118.g7fe29c98d7-goog


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

* [PATCH v2 2/2] selftests: net: netfilter: nft_queue.sh: sctp checksum
  2024-05-13  0:09 [PATCH v2 0/2] netfilter: nfqueue: incorrect sctp checksum Antonio Ojea
  2024-05-13  0:09 ` [PATCH v2 1/2] netfilter: nft_queue: compute SCTP checksum Antonio Ojea
@ 2024-05-13  0:09 ` Antonio Ojea
  2024-05-13 21:18   ` Florian Westphal
  1 sibling, 1 reply; 5+ messages in thread
From: Antonio Ojea @ 2024-05-13  0:09 UTC (permalink / raw)
  To: netfilter-devel; +Cc: pablo, fw, Antonio Ojea

Test that nfqueue, when using GSO, process SCTP packets
correctly.

Regression test for https://bugzilla.netfilter.org/show_bug.cgi?id=1742

Signed-off-by: Antonio Ojea <aojea@google.com>
---
 .../selftests/net/netfilter/nft_queue.sh      | 38 +++++++++++++++++++
 1 file changed, 38 insertions(+)

diff --git a/tools/testing/selftests/net/netfilter/nft_queue.sh b/tools/testing/selftests/net/netfilter/nft_queue.sh
index 8538f08c64c2..5e075c7e0350 100755
--- a/tools/testing/selftests/net/netfilter/nft_queue.sh
+++ b/tools/testing/selftests/net/netfilter/nft_queue.sh
@@ -25,6 +25,9 @@ cleanup()
 }
 
 checktool "nft --version" "test without nft tool"
+checktool "socat -h" "run test without socat"
+
+modprobe -q sctp
 
 trap cleanup EXIT
 
@@ -375,6 +378,40 @@ EOF
 	wait 2>/dev/null
 }
 
+test_sctp_forward()
+{
+        ip netns exec "$nsrouter" nft -f /dev/stdin <<EOF
+table inet sctpq {
+        chain forward {
+        type filter hook forward priority 0; policy accept;
+                sctp dport 12345 queue num 10
+        }
+}
+EOF
+        ip netns exec "$nsrouter" ./nf_queue -q 10 -G -t "$timeout" &
+        local nfqpid=$!
+
+        timeout 5 ip netns exec "$ns2" socat -u SCTP-LISTEN:12345 STDOUT > "$TMPFILE1" &
+        local rpid=$!
+
+        # ss does not show the sctp socket?
+        busywait "$BUSYWAIT_TIMEOUT" sh -c "ps axf | grep -q SCTP-LISTEN" "$ns2"
+
+        ip netns exec "$ns1" socat -u STDIN SCTP:10.0.2.99:12345 <"$TMPINPUT" >/dev/null
+
+        if ! ip netns exec "$nsrouter" nft delete table inet sctpq; then
+                echo "FAIL:  Could not delete sctpq table"
+                exit 1
+        fi
+
+        if ! diff -u "$TMPINPUT" "$TMPFILE1" ; then
+                echo "FAIL: lost packets?!" 1>&2
+                return
+        fi
+
+        wait "$rpid" && echo "PASS: sctp and nfqueue in forward chain with GSO"
+}
+
 ip netns exec "$nsrouter" sysctl net.ipv6.conf.all.forwarding=1 > /dev/null
 ip netns exec "$nsrouter" sysctl net.ipv4.conf.veth0.forwarding=1 > /dev/null
 ip netns exec "$nsrouter" sysctl net.ipv4.conf.veth1.forwarding=1 > /dev/null
@@ -413,5 +450,6 @@ test_tcp_localhost
 test_tcp_localhost_connectclose
 test_tcp_localhost_requeue
 test_icmp_vrf
+test_sctp_forward
 
 exit $ret
-- 
2.45.0.118.g7fe29c98d7-goog


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

* Re: [PATCH v2 1/2] netfilter: nft_queue: compute SCTP checksum
  2024-05-13  0:09 ` [PATCH v2 1/2] netfilter: nft_queue: compute SCTP checksum Antonio Ojea
@ 2024-05-13 21:14   ` Florian Westphal
  0 siblings, 0 replies; 5+ messages in thread
From: Florian Westphal @ 2024-05-13 21:14 UTC (permalink / raw)
  To: Antonio Ojea; +Cc: netfilter-devel, pablo, fw

Antonio Ojea <aojea@google.com> wrote:
> when packet is enqueued with nfqueue and GSO is enabled, checksum
> calculation has to take into account the protocol, as SCTP uses a
> 32 bits CRC checksum.
> 
> Signed-off-by: Antonio Ojea <aojea@google.com>
> ---
> V1 -> V2: add a helper function to process the checksum
> 
>  net/netfilter/nfnetlink_queue.c | 10 +++++++++-
>  1 file changed, 9 insertions(+), 1 deletion(-)
> 
> diff --git a/net/netfilter/nfnetlink_queue.c b/net/netfilter/nfnetlink_queue.c
> index 00f4bd21c59b..accf4942d9ff 100644
> --- a/net/netfilter/nfnetlink_queue.c
> +++ b/net/netfilter/nfnetlink_queue.c
> @@ -538,6 +538,14 @@ static int nfqnl_put_bridge(struct nf_queue_entry *entry, struct sk_buff *skb)
>  	return -1;
>  }
>  
> +static int nf_queue_checksum_help(struct sk_buff *entskb)
> +{
> +  if (skb_csum_is_sctp(entskb))
> +    return skb_crc32c_csum_help(entskb);

This should be tabs, please run your patch through checkpatch.pl.

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

* Re: [PATCH v2 2/2] selftests: net: netfilter: nft_queue.sh: sctp checksum
  2024-05-13  0:09 ` [PATCH v2 2/2] selftests: net: netfilter: nft_queue.sh: sctp checksum Antonio Ojea
@ 2024-05-13 21:18   ` Florian Westphal
  0 siblings, 0 replies; 5+ messages in thread
From: Florian Westphal @ 2024-05-13 21:18 UTC (permalink / raw)
  To: Antonio Ojea; +Cc: netfilter-devel, pablo, fw

Antonio Ojea <aojea@google.com> wrote:
> +        # ss does not show the sctp socket?

Hmn, it should, maybe INET_SCTP_DIAG=m is missing in kernel?

> +        busywait "$BUSYWAIT_TIMEOUT" sh -c "ps axf | grep -q SCTP-LISTEN" "$ns2"

... but if that works ok then no need to change.
Thanks for adding a test case.

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

end of thread, other threads:[~2024-05-13 21:18 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-05-13  0:09 [PATCH v2 0/2] netfilter: nfqueue: incorrect sctp checksum Antonio Ojea
2024-05-13  0:09 ` [PATCH v2 1/2] netfilter: nft_queue: compute SCTP checksum Antonio Ojea
2024-05-13 21:14   ` Florian Westphal
2024-05-13  0:09 ` [PATCH v2 2/2] selftests: net: netfilter: nft_queue.sh: sctp checksum Antonio Ojea
2024-05-13 21:18   ` Florian Westphal

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).