All of lore.kernel.org
 help / color / mirror / Atom feed
* [MPTCP] [PATCH v3 5/6] mptcp: protocol: re-check dsn before reading from subflow
@ 2020-02-20 14:34 Florian Westphal
  0 siblings, 0 replies; 2+ messages in thread
From: Florian Westphal @ 2020-02-20 14:34 UTC (permalink / raw)
  To: mptcp 

[-- Attachment #1: Type: text/plain, Size: 1779 bytes --]

mptcp_subflow_data_available() is commonly called via
ssk->sk_data_ready(), in this case the mptcp socket lock
cannot be acquired.

Therefore, while we can safely discard subflow data that
was already received up to msk->ack_seq, we cannot be sure
that 'subflow->data_avail' will still be valid at the time
userspace wants to read the data -- a previous read on a
different subflow might have carried this data already.

In that (unlikely) event, msk->ack_seq will have been updated
and will be ahead of the subflow dsn.

We can check for this condition and skip/resync to the expected
sequence number.

Signed-off-by: Florian Westphal <fw(a)strlen.de>
---
 net/mptcp/protocol.c | 20 ++++++++++++++++++--
 1 file changed, 18 insertions(+), 2 deletions(-)

diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c
index 75ae03931963..02aba8b31f1f 100644
--- a/net/mptcp/protocol.c
+++ b/net/mptcp/protocol.c
@@ -205,8 +205,24 @@ static struct sock *mptcp_subflow_recv_lookup(const struct mptcp_sock *msk)
 	sock_owned_by_me(sk);
 
 	mptcp_for_each_subflow(msk, subflow) {
-		if (subflow->data_avail)
-			return mptcp_subflow_tcp_sock(subflow);
+		if (subflow->data_avail) {
+			struct sock *ssk = mptcp_subflow_tcp_sock(subflow);
+			u64 dsn = mptcp_subflow_get_mapped_dsn(subflow);
+
+			/* revalidate data sequence number.
+			 *
+			 * mptcp_subflow_data_available() is usually called
+			 * without msk lock.  Its unlikely (but possible)
+			 * that msk->ack_seq has been advanced since the last
+			 * call found in-sequence data.
+			 */
+			if (likely(dsn == msk->ack_seq))
+				return ssk;
+
+			subflow->data_avail = 0;
+			if (mptcp_subflow_data_available(ssk))
+				return ssk;
+		}
 	}
 
 	return NULL;
-- 
2.24.1

^ permalink raw reply related	[flat|nested] 2+ messages in thread
* [MPTCP] [PATCH v3 5/6] mptcp: protocol: re-check dsn before reading from subflow
@ 2020-02-18 12:21 Florian Westphal
  0 siblings, 0 replies; 2+ messages in thread
From: Florian Westphal @ 2020-02-18 12:21 UTC (permalink / raw)
  To: mptcp 

[-- Attachment #1: Type: text/plain, Size: 1779 bytes --]

mptcp_subflow_data_available() is commonly called via
ssk->sk_data_ready(), in this case the mptcp socket lock
cannot be acquired.

Therefore, while we can safely discard subflow data that
was already received up to msk->ack_seq, we cannot be sure
that 'subflow->data_avail' will still be valid at the time
userspace wants to read the data -- a previous read on a
different subflow might have carried this data already.

In that (unlikely) event, msk->ack_seq will have been updated
and will be ahead of the subflow dsn.

We can check for this condition and skip/resync to the expected
sequence number.

Signed-off-by: Florian Westphal <fw(a)strlen.de>
---
 net/mptcp/protocol.c | 20 ++++++++++++++++++--
 1 file changed, 18 insertions(+), 2 deletions(-)

diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c
index 75ae03931963..02aba8b31f1f 100644
--- a/net/mptcp/protocol.c
+++ b/net/mptcp/protocol.c
@@ -205,8 +205,24 @@ static struct sock *mptcp_subflow_recv_lookup(const struct mptcp_sock *msk)
 	sock_owned_by_me(sk);
 
 	mptcp_for_each_subflow(msk, subflow) {
-		if (subflow->data_avail)
-			return mptcp_subflow_tcp_sock(subflow);
+		if (subflow->data_avail) {
+			struct sock *ssk = mptcp_subflow_tcp_sock(subflow);
+			u64 dsn = mptcp_subflow_get_mapped_dsn(subflow);
+
+			/* revalidate data sequence number.
+			 *
+			 * mptcp_subflow_data_available() is usually called
+			 * without msk lock.  Its unlikely (but possible)
+			 * that msk->ack_seq has been advanced since the last
+			 * call found in-sequence data.
+			 */
+			if (likely(dsn == msk->ack_seq))
+				return ssk;
+
+			subflow->data_avail = 0;
+			if (mptcp_subflow_data_available(ssk))
+				return ssk;
+		}
 	}
 
 	return NULL;
-- 
2.24.1

^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-02-20 14:34 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-02-20 14:34 [MPTCP] [PATCH v3 5/6] mptcp: protocol: re-check dsn before reading from subflow Florian Westphal
  -- strict thread matches above, loose matches on Subject: below --
2020-02-18 12:21 Florian Westphal

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.