mptcp: fix deadlock in mptcp{,6}_release
Subsystems (2)
Paolo Abeni
cover mptcp: fix deadlock in mptcp{,6}_release
This address the issue the easy way: removing the bugged feature (mcast support :).
AFAICS the mcast related sockopt manipulate a global state, so there could be existing working application doing setsockopt(mcast opt) on TCP sockets. This is why I did not disable mcast at the inet level for stream sockets.
Still I'm wondering if we should take the opposite approach: explicitly forbitting all setsockopt except the one we implement in net/mptcp/protocol.c
Additionally this possibly overlap with wider task - a more comprehensive sockopt support. Ence the RFC tag.
Side note: syzbot confirm this fixes issues/170
Paolo Abeni (2):
mptcp: forbit mcast-related sockopt on MPTCP sockets
mptcp: revert "mptcp: provide subflow aware release function"$ ....$
net/mptcp/protocol.c | 100 ++++++++++++++++++++----------------------- 1 file changed, 47 insertions(+), 53 deletions(-)
Signature · 1 line
2.26.2
Paolo Abeni
RFC PATCH 1/2 mptcp: forbit mcast-related sockopt on MPTCP sockets
Unrolling mcast state at msk dismantel time is bug prone, as syzkaller reported:
======================================================
WARNING: possible circular locking dependency detected
5.11.0-syzkaller #0 Not tainted
------------------------------------------------------
syz-executor905/8822 is trying to acquire lock:ffffffff8d678fe8 (rtnl_mutex){+.+.}-{3:3}, at: ipv6_sock_mc_close+0xd7/0x110 net/ipv6/mcast.c:323
but task is already holding lock:ffff888024390120 (sk_lock-AF_INET6){+.+.}-{0:0}, at: lock_sock include/net/sock.h:1600 [inline] ffff888024390120 (sk_lock-AF_INET6){+.+.}-{0:0}, at: mptcp6_release+0x57/0x130 net/mptcp/protocol.c:3507
which lock already depends on the new lock.
Instead we can simply forbit any mcast-related setsockopt
--- net/mptcp/protocol.c | 45 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+)
net/mptcp/protocol.c +45 -0
@@ -2877,6 +2877,48 @@ static int mptcp_setsockopt_v6(struct mptcp_sock *msk, int optname,return ret; } +static bool mptcp_unsupported (int level,int optname) +{ +if (level ==SOL_IP ) { +switch (optname) { +case IP_ADD_MEMBERSHIP : +case IP_ADD_SOURCE_MEMBERSHIP : +case IP_DROP_MEMBERSHIP : +case IP_DROP_SOURCE_MEMBERSHIP : +case IP_BLOCK_SOURCE : +case IP_UNBLOCK_SOURCE : +case MCAST_JOIN_GROUP : +case MCAST_LEAVE_GROUP : +case MCAST_JOIN_SOURCE_GROUP : +case MCAST_LEAVE_SOURCE_GROUP : +case MCAST_BLOCK_SOURCE : +case MCAST_UNBLOCK_SOURCE : +case MCAST_MSFILTER : +return true; + } +return false; + } +if (level ==SOL_IPV6 ) { +switch (optname) { +case IPV6_ADDRFORM : +case IPV6_ADD_MEMBERSHIP : +case IPV6_DROP_MEMBERSHIP : +case IPV6_JOIN_ANYCAST : +case IPV6_LEAVE_ANYCAST : +case MCAST_JOIN_GROUP : +case MCAST_LEAVE_GROUP : +case MCAST_JOIN_SOURCE_GROUP : +case MCAST_LEAVE_SOURCE_GROUP : +case MCAST_BLOCK_SOURCE : +case MCAST_UNBLOCK_SOURCE : +case MCAST_MSFILTER : +return true; + } +return false; + } +return false; +} +static int mptcp_setsockopt (struct sock *sk,int level,int optname,sockptr_t optval,unsigned int optlen) {
@@ -2885,6 +2927,9 @@ static int mptcp_setsockopt(struct sock *sk, int level, int optname,pr_debug ("msk=%p" , msk); +if (mptcp_unsupported (level, optname)) +return -ENOPROTOOPT ; +if (level ==SOL_SOCKET )return mptcp_setsockopt_sol_socket (msk, optname, optval, optlen);
Signature · 1 line
2.26.2
Paolo Abeni
RFC PATCH 2/2 mptcp: revert "mptcp: provide subflow aware release function"$ ....$
In reply to Paolo AbeniThis commit reverts ad98dd37051e ("mptcp: provide subflow aware release function"). The latter introduced a deadlock spotted by syzkaller and is not needed anymore after the previous commit.
--- net/mptcp/protocol.c | 55 ++------------------------------------------ 1 file changed, 2 insertions(+), 53 deletions(-)
net/mptcp/protocol.c +2 -53
@@ -11,7 +11,6 @@#include <linux/netdevice.h> #include <linux/sched/signal.h> #include <linux/atomic.h> -#include <linux/igmp.h> #include <net/sock.h> #include <net/inet_common.h> #include <net/inet_hashtables.h>
@@ -20,7 +19,6 @@#include <net/tcp_states.h> #if IS_ENABLED (CONFIG_MPTCP_IPV6 )#include <net/transp_v6.h> -#include <net/addrconf.h> #endif #include <net/mptcp.h> #include <net/xfrm.h>
@@ -3460,34 +3458,10 @@ static __poll_t mptcp_poll(struct file *file, struct socket *sock,return mask; } -static int mptcp_release (struct socket *sock) -{ -struct mptcp_subflow_context *subflow; -struct sock *sk = sock->sk; -struct mptcp_sock *msk; - -if (!sk) -return 0 ; - -lock_sock (sk); - - msk =mptcp_sk (sk); - -mptcp_for_each_subflow (msk, subflow) { -struct sock *ssk =mptcp_subflow_tcp_sock (subflow); - -ip_mc_drop_socket (ssk); - } - -release_sock (sk); - -return inet_release (sock); -} -static const struct proto_ops mptcp_stream_ops = { .family =PF_INET , .owner =THIS_MODULE , - .release = mptcp_release, + .release = inet_release, .bind = mptcp_bind, .connect = mptcp_stream_connect, .socketpair = sock_no_socketpair,
@@ -3585,35 +3559,10 @@ void __init mptcp_proto_init(void) }#if IS_ENABLED (CONFIG_MPTCP_IPV6 ) -static int mptcp6_release (struct socket *sock) -{ -struct mptcp_subflow_context *subflow; -struct mptcp_sock *msk; -struct sock *sk = sock->sk; - -if (!sk) -return 0 ; - -lock_sock (sk); - - msk =mptcp_sk (sk); - -mptcp_for_each_subflow (msk, subflow) { -struct sock *ssk =mptcp_subflow_tcp_sock (subflow); - -ip_mc_drop_socket (ssk); -ipv6_sock_mc_close (ssk); -ipv6_sock_ac_close (ssk); - } - -release_sock (sk); -return inet6_release (sock); -} -static const struct proto_ops mptcp_v6_stream_ops = { .family =PF_INET6 , .owner =THIS_MODULE , - .release = mptcp6_release, + .release = inet6_release, .bind = mptcp_bind, .connect = mptcp_stream_connect, .socketpair = sock_no_socketpair,
Signature · 1 line
2.26.2
Mat Martineau
Quoted 12 lines · Paolo Abeni
This address the issue the easy way: removing the bugged feature (mcast support :).
AFAICS the mcast related sockopt manipulate a global state, so there could be existing working application doing setsockopt(mcast opt) on TCP sockets. This is why I did not disable mcast at the inet level for stream sockets.
Still I'm wondering if we should take the opposite approach: explicitly forbitting all setsockopt except the one we implement in
net/mptcp/protocol.c
I think there was mailing list discussion about having an allowed list of SOL_TCP options, but I think applying that idea to the inet level slipped by. It does seem better to only allow the options we implement.
(by the way: it's forbid/forbidding)
Mat
Quoted 18 lines
Additionally this possibly overlap with wider task - a more comprehensive sockopt support. Ence the RFC tag.
Side note: syzbot confirm this fixes issues/170
Paolo Abeni (2):
mptcp: forbit mcast-related sockopt on MPTCP sockets
mptcp: revert "mptcp: provide subflow aware release function"$ ....$
net/mptcp/protocol.c| 100 ++++++++++++++++++++-----------------------1 file changed, 47 insertions(+), 53 deletions(-)Signature · 4 lines
2.26.2 _______________________________________________ mptcp mailing list -- mptcp(a)lists.01.org To unsubscribe send an email to mptcp-leave(a)lists.01.org
--
Mat Martineau
Intel
Matthieu Baerts
Hi Paolo, Mat,
Quoted 10 lines · Mat Martineau
Quoted 8 lines · Paolo Abeni
This address the issue the easy way: removing the bugged feature (mcast support :).
AFAICS the mcast related sockopt manipulate a global state, so there could be existing working application doing setsockopt(mcast opt) on TCP sockets. This is why I did not disable mcast at the inet level for stream sockets.
Quoted 8 lines
Quoted 4 lines
Still I'm wondering if we should take the opposite approach: explicitly forbitting all setsockopt except the one we implement in
net/mptcp/protocol.cI think there was mailing list discussion about having an allowed list of
SOL_TCPoptions, but I think applying that idea to the inet level slipped by. It does seem better to only allow the options we implement.
Yes and probably easier to maintain a list of what has been implemented and/or validated (who mentioned packetdrill???) than having to block one because it can cause warnings or crashes.
BTW thank you for looking at that!
Cheers,
Matt
Signature · 2 lines
Tessares | Belgium | Hybrid Access Solutions www.tessares.net