mptcp: fix checksum byte order
authorPaolo Abeni <pabeni@redhat.com>
Tue, 17 May 2022 18:02:11 +0000 (11:02 -0700)
committerDavid S. Miller <davem@davemloft.net>
Wed, 18 May 2022 12:05:42 +0000 (13:05 +0100)
The MPTCP code typecasts the checksum value to u16 and
then converts it to big endian while storing the value into
the MPTCP option.

As a result, the wire encoding for little endian host is
wrong, and that causes interoperabilty interoperability
issues with other implementation or host with different endianness.

Address the issue writing in the packet the unmodified __sum16 value.

MPTCP checksum is disabled by default, interoperating with systems
with bad mptcp-level csum encoding should cause fallback to TCP.

Closes: https://github.com/multipath-tcp/mptcp_net-next/issues/275
Fixes: c5b39e26d003 ("mptcp: send out checksum for DSS")
Fixes: 390b95a5fb84 ("mptcp: receive checksum for DSS")
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
Signed-off-by: Mat Martineau <mathew.j.martineau@linux.intel.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
net/mptcp/options.c
net/mptcp/protocol.h
net/mptcp/subflow.c

index 325383646f5c0061f049603aa4a965ac40651f7d..b548cec86c9d87f0c063255461d93c891a09f476 100644 (file)
@@ -107,7 +107,7 @@ static void mptcp_parse_option(const struct sk_buff *skb,
                        ptr += 2;
                }
                if (opsize == TCPOLEN_MPTCP_MPC_ACK_DATA_CSUM) {
-                       mp_opt->csum = (__force __sum16)get_unaligned_be16(ptr);
+                       mp_opt->csum = get_unaligned((__force __sum16 *)ptr);
                        mp_opt->suboptions |= OPTION_MPTCP_CSUMREQD;
                        ptr += 2;
                }
@@ -221,7 +221,7 @@ static void mptcp_parse_option(const struct sk_buff *skb,
 
                        if (opsize == expected_opsize + TCPOLEN_MPTCP_DSS_CHECKSUM) {
                                mp_opt->suboptions |= OPTION_MPTCP_CSUMREQD;
-                               mp_opt->csum = (__force __sum16)get_unaligned_be16(ptr);
+                               mp_opt->csum = get_unaligned((__force __sum16 *)ptr);
                                ptr += 2;
                        }
 
@@ -1240,7 +1240,7 @@ static void mptcp_set_rwin(const struct tcp_sock *tp)
                WRITE_ONCE(msk->rcv_wnd_sent, ack_seq);
 }
 
-u16 __mptcp_make_csum(u64 data_seq, u32 subflow_seq, u16 data_len, __wsum sum)
+__sum16 __mptcp_make_csum(u64 data_seq, u32 subflow_seq, u16 data_len, __wsum sum)
 {
        struct csum_pseudo_header header;
        __wsum csum;
@@ -1256,15 +1256,25 @@ u16 __mptcp_make_csum(u64 data_seq, u32 subflow_seq, u16 data_len, __wsum sum)
        header.csum = 0;
 
        csum = csum_partial(&header, sizeof(header), sum);
-       return (__force u16)csum_fold(csum);
+       return csum_fold(csum);
 }
 
-static u16 mptcp_make_csum(const struct mptcp_ext *mpext)
+static __sum16 mptcp_make_csum(const struct mptcp_ext *mpext)
 {
        return __mptcp_make_csum(mpext->data_seq, mpext->subflow_seq, mpext->data_len,
                                 ~csum_unfold(mpext->csum));
 }
 
+static void put_len_csum(u16 len, __sum16 csum, void *data)
+{
+       __sum16 *sumptr = data + 2;
+       __be16 *ptr = data;
+
+       put_unaligned_be16(len, ptr);
+
+       put_unaligned(csum, sumptr);
+}
+
 void mptcp_write_options(__be32 *ptr, const struct tcp_sock *tp,
                         struct mptcp_out_options *opts)
 {
@@ -1340,8 +1350,9 @@ void mptcp_write_options(__be32 *ptr, const struct tcp_sock *tp,
                        put_unaligned_be32(mpext->subflow_seq, ptr);
                        ptr += 1;
                        if (opts->csum_reqd) {
-                               put_unaligned_be32(mpext->data_len << 16 |
-                                                  mptcp_make_csum(mpext), ptr);
+                               put_len_csum(mpext->data_len,
+                                            mptcp_make_csum(mpext),
+                                            ptr);
                        } else {
                                put_unaligned_be32(mpext->data_len << 16 |
                                                   TCPOPT_NOP << 8 | TCPOPT_NOP, ptr);
@@ -1392,11 +1403,12 @@ void mptcp_write_options(__be32 *ptr, const struct tcp_sock *tp,
                        goto mp_capable_done;
 
                if (opts->csum_reqd) {
-                       put_unaligned_be32(opts->data_len << 16 |
-                                          __mptcp_make_csum(opts->data_seq,
-                                                            opts->subflow_seq,
-                                                            opts->data_len,
-                                                            ~csum_unfold(opts->csum)), ptr);
+                       put_len_csum(opts->data_len,
+                                    __mptcp_make_csum(opts->data_seq,
+                                                      opts->subflow_seq,
+                                                      opts->data_len,
+                                                      ~csum_unfold(opts->csum)),
+                                    ptr);
                } else {
                        put_unaligned_be32(opts->data_len << 16 |
                                           TCPOPT_NOP << 8 | TCPOPT_NOP, ptr);
index f4ce28bb0fdcceaa38e01525775435be4d27de1b..fb40dd676a26ead49419b9aecbb4e3667a9b65b0 100644 (file)
@@ -723,7 +723,7 @@ void mptcp_token_destroy(struct mptcp_sock *msk);
 void mptcp_crypto_key_sha(u64 key, u32 *token, u64 *idsn);
 
 void mptcp_crypto_hmac_sha(u64 key1, u64 key2, u8 *msg, int len, void *hmac);
-u16 __mptcp_make_csum(u64 data_seq, u32 subflow_seq, u16 data_len, __wsum sum);
+__sum16 __mptcp_make_csum(u64 data_seq, u32 subflow_seq, u16 data_len, __wsum sum);
 
 void __init mptcp_pm_init(void);
 void mptcp_pm_data_init(struct mptcp_sock *msk);
index 8c37087f0d8460600c21e9c249ffb8f74bf17a14..e90fe7eec43ac747c2eaa7ae06285a084f870bef 100644 (file)
@@ -888,7 +888,7 @@ static enum mapping_status validate_data_csum(struct sock *ssk, struct sk_buff *
 {
        struct mptcp_subflow_context *subflow = mptcp_subflow_ctx(ssk);
        u32 offset, seq, delta;
-       u16 csum;
+       __sum16 csum;
        int len;
 
        if (!csum_reqd)