Skip to content

Commit

Permalink
mptcp: fix sk_forward_memory corruption on retransmission
Browse files Browse the repository at this point in the history
[ Upstream commit b5941f0 ]

MPTCP sk_forward_memory handling is a bit special, as such field
is protected by the msk socket spin_lock, instead of the plain
socket lock.

Currently we have a code path updating such field without handling
the relevant lock:

__mptcp_retrans() -> __mptcp_clean_una_wakeup()

Several helpers in __mptcp_clean_una_wakeup() will update
sk_forward_alloc, possibly causing such field corruption, as reported
by Matthieu.

Address the issue providing and using a new variant of blamed function
which explicitly acquires the msk spin lock.

Fixes: 64b9cea ("mptcp: fix spurious retransmissions")
Closes: multipath-tcp/mptcp_net-next#172
Reported-by: Matthieu Baerts <matthieu.baerts@tessares.net>
Tested-by: Matthieu Baerts <matthieu.baerts@tessares.net>
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
Signed-off-by: Mat Martineau <mathew.j.martineau@linux.intel.com>
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
  • Loading branch information
Paolo Abeni authored and gregkh committed Jun 10, 2021
1 parent 41d6cc0 commit b9c78b1
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion net/mptcp/protocol.c
Expand Up @@ -937,6 +937,10 @@ static void __mptcp_update_wmem(struct sock *sk)
{
struct mptcp_sock *msk = mptcp_sk(sk);

#ifdef CONFIG_LOCKDEP
WARN_ON_ONCE(!lockdep_is_held(&sk->sk_lock.slock));
#endif

if (!msk->wmem_reserved)
return;

Expand Down Expand Up @@ -1075,10 +1079,20 @@ static void __mptcp_clean_una(struct sock *sk)

static void __mptcp_clean_una_wakeup(struct sock *sk)
{
#ifdef CONFIG_LOCKDEP
WARN_ON_ONCE(!lockdep_is_held(&sk->sk_lock.slock));
#endif
__mptcp_clean_una(sk);
mptcp_write_space(sk);
}

static void mptcp_clean_una_wakeup(struct sock *sk)
{
mptcp_data_lock(sk);
__mptcp_clean_una_wakeup(sk);
mptcp_data_unlock(sk);
}

static void mptcp_enter_memory_pressure(struct sock *sk)
{
struct mptcp_subflow_context *subflow;
Expand Down Expand Up @@ -2288,7 +2302,7 @@ static void __mptcp_retrans(struct sock *sk)
struct sock *ssk;
int ret;

__mptcp_clean_una_wakeup(sk);
mptcp_clean_una_wakeup(sk);
dfrag = mptcp_rtx_head(sk);
if (!dfrag) {
if (mptcp_data_fin_enabled(msk)) {
Expand Down

0 comments on commit b9c78b1

Please sign in to comment.