]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
mptcp: sockopt: fix getting IPV6_V6ONLY
authorMatthieu Baerts (NGI0) <matttbe@kernel.org>
Fri, 14 Mar 2025 20:11:32 +0000 (21:11 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 2 May 2025 05:41:04 +0000 (07:41 +0200)
commit 8c39633759885b6ff85f6d96cf445560e74df5e8 upstream.

When adding a socket option support in MPTCP, both the get and set parts
are supposed to be implemented.

IPV6_V6ONLY support for the setsockopt part has been added a while ago,
but it looks like the get part got forgotten. It should have been
present as a way to verify a setting has been set as expected, and not
to act differently from TCP or any other socket types.

Not supporting this getsockopt(IPV6_V6ONLY) blocks some apps which want
to check the default value, before doing extra actions. On Linux, the
default value is 0, but this can be changed with the net.ipv6.bindv6only
sysctl knob. On Windows, it is set to 1 by default. So supporting the
get part, like for all other socket options, is important.

Everything was in place to expose it, just the last step was missing.
Only new code is added to cover this specific getsockopt(), that seems
safe.

Fixes: c9b95a135987 ("mptcp: support IPV6_V6ONLY setsockopt")
Cc: stable@vger.kernel.org
Closes: https://github.com/multipath-tcp/mptcp_net-next/issues/550
Reviewed-by: Mat Martineau <martineau@kernel.org>
Signed-off-by: Matthieu Baerts (NGI0) <matttbe@kernel.org>
Reviewed-by: Simon Horman <horms@kernel.org>
Link: https://patch.msgid.link/20250314-net-mptcp-fix-data-stream-corr-sockopt-v1-2-122dbb249db3@kernel.org
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
[ Conflicts in sockopt.c in the context, because commit 0abdde82b163
  ("mptcp: move sockopt function into a new file") is not in this
  release. The modifications can still be done in protocol.c without
  difficulties. A particularity is that the mptcp_put_int_option()
  helper is required, and imported from newer versions without taking
  the extra features introduced with them in commit 2c9e77659a0c
  ("mptcp: add TCP_INQ cmsg support") and commit 3b1e21eb60e8 ("mptcp:
  getsockopt: add support for IP_TOS"). ]
Signed-off-by: Matthieu Baerts (NGI0) <matttbe@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
net/mptcp/protocol.c

index 51b552fa392a5f2f01fe8ad44660fbc61dab3d06..f33c3150e6909190fa69841bbe6a46a75813e759 100644 (file)
@@ -2395,6 +2395,49 @@ static int mptcp_setsockopt(struct sock *sk, int level, int optname,
        return -EOPNOTSUPP;
 }
 
+static int mptcp_put_int_option(struct mptcp_sock *msk, char __user *optval,
+                               int __user *optlen, int val)
+{
+       int len;
+
+       if (get_user(len, optlen))
+               return -EFAULT;
+       if (len < 0)
+               return -EINVAL;
+
+       if (len < sizeof(int) && len > 0 && val >= 0 && val <= 255) {
+               unsigned char ucval = (unsigned char)val;
+
+               len = 1;
+               if (put_user(len, optlen))
+                       return -EFAULT;
+               if (copy_to_user(optval, &ucval, 1))
+                       return -EFAULT;
+       } else {
+               len = min_t(unsigned int, len, sizeof(int));
+               if (put_user(len, optlen))
+                       return -EFAULT;
+               if (copy_to_user(optval, &val, len))
+                       return -EFAULT;
+       }
+
+       return 0;
+}
+
+static int mptcp_getsockopt_v6(struct mptcp_sock *msk, int optname,
+                              char __user *optval, int __user *optlen)
+{
+       struct sock *sk = (void *)msk;
+
+       switch (optname) {
+       case IPV6_V6ONLY:
+               return mptcp_put_int_option(msk, optval, optlen,
+                                           sk->sk_ipv6only);
+       }
+
+       return -EOPNOTSUPP;
+}
+
 static int mptcp_getsockopt(struct sock *sk, int level, int optname,
                            char __user *optval, int __user *option)
 {
@@ -2415,6 +2458,8 @@ static int mptcp_getsockopt(struct sock *sk, int level, int optname,
        if (ssk)
                return tcp_getsockopt(ssk, level, optname, optval, option);
 
+       if (level == SOL_IPV6)
+               return mptcp_getsockopt_v6(msk, optname, optval, option);
        return -EOPNOTSUPP;
 }