Commit ba2c89e0 authored by Paolo Abeni's avatar Paolo Abeni Committed by David S. Miller

mptcp: fix checksum byte order

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: c5b39e26 ("mptcp: send out checksum for DSS")
Fixes: 390b95a5 ("mptcp: receive checksum for DSS")
Signed-off-by: default avatarPaolo Abeni <pabeni@redhat.com>
Signed-off-by: default avatarMat Martineau <mathew.j.martineau@linux.intel.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 680b8926
...@@ -107,7 +107,7 @@ static void mptcp_parse_option(const struct sk_buff *skb, ...@@ -107,7 +107,7 @@ static void mptcp_parse_option(const struct sk_buff *skb,
ptr += 2; ptr += 2;
} }
if (opsize == TCPOLEN_MPTCP_MPC_ACK_DATA_CSUM) { 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; mp_opt->suboptions |= OPTION_MPTCP_CSUMREQD;
ptr += 2; ptr += 2;
} }
...@@ -221,7 +221,7 @@ static void mptcp_parse_option(const struct sk_buff *skb, ...@@ -221,7 +221,7 @@ static void mptcp_parse_option(const struct sk_buff *skb,
if (opsize == expected_opsize + TCPOLEN_MPTCP_DSS_CHECKSUM) { if (opsize == expected_opsize + TCPOLEN_MPTCP_DSS_CHECKSUM) {
mp_opt->suboptions |= OPTION_MPTCP_CSUMREQD; 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; ptr += 2;
} }
...@@ -1240,7 +1240,7 @@ static void mptcp_set_rwin(const struct tcp_sock *tp) ...@@ -1240,7 +1240,7 @@ static void mptcp_set_rwin(const struct tcp_sock *tp)
WRITE_ONCE(msk->rcv_wnd_sent, ack_seq); 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; struct csum_pseudo_header header;
__wsum csum; __wsum csum;
...@@ -1256,15 +1256,25 @@ u16 __mptcp_make_csum(u64 data_seq, u32 subflow_seq, u16 data_len, __wsum sum) ...@@ -1256,15 +1256,25 @@ u16 __mptcp_make_csum(u64 data_seq, u32 subflow_seq, u16 data_len, __wsum sum)
header.csum = 0; header.csum = 0;
csum = csum_partial(&header, sizeof(header), sum); 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, return __mptcp_make_csum(mpext->data_seq, mpext->subflow_seq, mpext->data_len,
~csum_unfold(mpext->csum)); ~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, void mptcp_write_options(__be32 *ptr, const struct tcp_sock *tp,
struct mptcp_out_options *opts) struct mptcp_out_options *opts)
{ {
...@@ -1340,8 +1350,9 @@ void mptcp_write_options(__be32 *ptr, const struct tcp_sock *tp, ...@@ -1340,8 +1350,9 @@ void mptcp_write_options(__be32 *ptr, const struct tcp_sock *tp,
put_unaligned_be32(mpext->subflow_seq, ptr); put_unaligned_be32(mpext->subflow_seq, ptr);
ptr += 1; ptr += 1;
if (opts->csum_reqd) { if (opts->csum_reqd) {
put_unaligned_be32(mpext->data_len << 16 | put_len_csum(mpext->data_len,
mptcp_make_csum(mpext), ptr); mptcp_make_csum(mpext),
ptr);
} else { } else {
put_unaligned_be32(mpext->data_len << 16 | put_unaligned_be32(mpext->data_len << 16 |
TCPOPT_NOP << 8 | TCPOPT_NOP, ptr); TCPOPT_NOP << 8 | TCPOPT_NOP, ptr);
...@@ -1392,11 +1403,12 @@ void mptcp_write_options(__be32 *ptr, const struct tcp_sock *tp, ...@@ -1392,11 +1403,12 @@ void mptcp_write_options(__be32 *ptr, const struct tcp_sock *tp,
goto mp_capable_done; goto mp_capable_done;
if (opts->csum_reqd) { if (opts->csum_reqd) {
put_unaligned_be32(opts->data_len << 16 | put_len_csum(opts->data_len,
__mptcp_make_csum(opts->data_seq, __mptcp_make_csum(opts->data_seq,
opts->subflow_seq, opts->subflow_seq,
opts->data_len, opts->data_len,
~csum_unfold(opts->csum)), ptr); ~csum_unfold(opts->csum)),
ptr);
} else { } else {
put_unaligned_be32(opts->data_len << 16 | put_unaligned_be32(opts->data_len << 16 |
TCPOPT_NOP << 8 | TCPOPT_NOP, ptr); TCPOPT_NOP << 8 | TCPOPT_NOP, ptr);
......
...@@ -723,7 +723,7 @@ void mptcp_token_destroy(struct mptcp_sock *msk); ...@@ -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_key_sha(u64 key, u32 *token, u64 *idsn);
void mptcp_crypto_hmac_sha(u64 key1, u64 key2, u8 *msg, int len, void *hmac); 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 __init mptcp_pm_init(void);
void mptcp_pm_data_init(struct mptcp_sock *msk); void mptcp_pm_data_init(struct mptcp_sock *msk);
......
...@@ -888,7 +888,7 @@ static enum mapping_status validate_data_csum(struct sock *ssk, struct sk_buff * ...@@ -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); struct mptcp_subflow_context *subflow = mptcp_subflow_ctx(ssk);
u32 offset, seq, delta; u32 offset, seq, delta;
u16 csum; __sum16 csum;
int len; int len;
if (!csum_reqd) if (!csum_reqd)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment