aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthieu Baerts (NGI0) <matttbe@kernel.org>2024-04-20 09:25:04 +0000
committerMatthieu Baerts (NGI0) <matttbe@kernel.org>2024-04-20 09:25:04 +0000
commit8bc7f3adcaafb7ee61dd5affe60d1f5bf2bef215 (patch)
treed09932c51e87ba5c2375e3be2492f00e534076f2
parentf8eb9ff3e6dffdd8f3931904f612365ace6c00f3 (diff)
downloadmptcp_net-next-8bc7f3adcaafb7ee61dd5affe60d1f5bf2bef215.tar.gz
mptcp: sockopt: info: stop early if no buffer
Up to recently, it has been recommended to use getsockopt(MPTCP_INFO) on an 'accept'ed socket, for a server app to check if the client requested to use MPTCP. In this case, the userspace app is only interested by the returned value of the getsocktop() call, and can then give 0 for the option length, and NULL for the buffer address. An easy optimisation is then to stop early, and avoid filling a local buffer -- which now requires two different locks -- if it is not needed. Note that userspace apps should use getsockopt(SO_PROTOCOL) in such case instead: it looks less like a workaround, and it works with any kernel versions, while the MPTCP_INFO method requires kernels >= v5.16. Signed-off-by: Matthieu Baerts (NGI0) <matttbe@kernel.org>
-rw-r--r--net/mptcp/sockopt.c6
1 files changed, 6 insertions, 0 deletions
diff --git a/net/mptcp/sockopt.c b/net/mptcp/sockopt.c
index 1fea43f5b6f3de..b0d1dc4df0c1a7 100644
--- a/net/mptcp/sockopt.c
+++ b/net/mptcp/sockopt.c
@@ -960,6 +960,12 @@ static int mptcp_getsockopt_info(struct mptcp_sock *msk, char __user *optval, in
if (get_user(len, optlen))
return -EFAULT;
+ /* Opti when used to check if a fallback to TCP happened on an 'accept'
+ * socket. Userspace apps should use getsockopt(SO_PROTOCOL) instead.
+ */
+ if (len == 0)
+ return 0;
+
len = min_t(unsigned int, len, sizeof(struct mptcp_info));
mptcp_diag_fill_info(msk, &m_info);