mptcp: avoid data corruption on reinsert
authorPaolo Abeni <pabeni@redhat.com>
Thu, 23 Jul 2020 11:02:30 +0000 (13:02 +0200)
committerDavid S. Miller <davem@davemloft.net>
Thu, 23 Jul 2020 18:47:24 +0000 (11:47 -0700)
When updating a partially acked data fragment, we
actually corrupt it. This is irrelevant till we send
data on a single subflow, as retransmitted data, if
any are discarded by the peer as duplicate, but it
will cause data corruption as soon as we will start
creating non backup subflows.

Reviewed-by: Mat Martineau <mathew.j.martineau@linux.intel.com>
Tested-by: Christoph Paasch <cpaasch@apple.com>
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
net/mptcp/protocol.c

index 59c0eef..254e6ef 100644 (file)
@@ -460,15 +460,20 @@ static void mptcp_clean_una(struct sock *sk)
 
        dfrag = mptcp_rtx_head(sk);
        if (dfrag && after64(snd_una, dfrag->data_seq)) {
-               u64 delta = dfrag->data_seq + dfrag->data_len - snd_una;
+               u64 delta = snd_una - dfrag->data_seq;
+
+               if (WARN_ON_ONCE(delta > dfrag->data_len))
+                       goto out;
 
                dfrag->data_seq += delta;
+               dfrag->offset += delta;
                dfrag->data_len -= delta;
 
                dfrag_uncharge(sk, delta);
                cleaned = true;
        }
 
+out:
        if (cleaned) {
                sk_mem_reclaim_partial(sk);