Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

mptcp: ADD_ADDRs with echo bit are smaller

The MPTCP ADD_ADDR suboption with echo-flag=1 has no HMAC, the size is
smaller than the one initially sent without echo-flag=1. We then need to
use the correct size everywhere when we need this echo bit.

Before this patch, the wrong size was reserved but the correct amount of
bytes were written (and read): the remaining bytes contained garbage.

Fixes: 6a6c05a8b016 ("mptcp: send out ADD_ADDR with echo flag")
Closes: https://github.com/multipath-tcp/mptcp_net-next/issues/95
Reported-and-tested-by: Davide Caratti <dcaratti@redhat.com>
Acked-by: Geliang Tang <geliangtang@gmail.com>
Signed-off-by: Matthieu Baerts <matthieu.baerts@tessares.net>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

Matthieu Baerts and committed by
David S. Miller
456afe01 3a56268e

+8 -6
+1 -1
net/mptcp/options.c
··· 587 587 !(mptcp_pm_add_addr_signal(msk, remaining, &saddr, &echo))) 588 588 return false; 589 589 590 - len = mptcp_add_addr_len(saddr.family); 590 + len = mptcp_add_addr_len(saddr.family, echo); 591 591 if (remaining < len) 592 592 return false; 593 593
+3 -2
net/mptcp/pm.c
··· 183 183 if (!mptcp_pm_should_add_signal(msk)) 184 184 goto out_unlock; 185 185 186 - if (remaining < mptcp_add_addr_len(msk->pm.local.family)) 186 + *echo = READ_ONCE(msk->pm.add_addr_echo); 187 + 188 + if (remaining < mptcp_add_addr_len(msk->pm.local.family, *echo)) 187 189 goto out_unlock; 188 190 189 191 *saddr = msk->pm.local; 190 - *echo = READ_ONCE(msk->pm.add_addr_echo); 191 192 WRITE_ONCE(msk->pm.add_addr_signal, false); 192 193 ret = true; 193 194
+4 -3
net/mptcp/protocol.h
··· 464 464 return READ_ONCE(msk->pm.rm_addr_signal); 465 465 } 466 466 467 - static inline unsigned int mptcp_add_addr_len(int family) 467 + static inline unsigned int mptcp_add_addr_len(int family, bool echo) 468 468 { 469 469 if (family == AF_INET) 470 - return TCPOLEN_MPTCP_ADD_ADDR; 471 - return TCPOLEN_MPTCP_ADD_ADDR6; 470 + return echo ? TCPOLEN_MPTCP_ADD_ADDR_BASE 471 + : TCPOLEN_MPTCP_ADD_ADDR; 472 + return echo ? TCPOLEN_MPTCP_ADD_ADDR6_BASE : TCPOLEN_MPTCP_ADD_ADDR6; 472 473 } 473 474 474 475 bool mptcp_pm_add_addr_signal(struct mptcp_sock *msk, unsigned int remaining,