fix syzkaller splats reported by Christoph
Subsystems (3)
Florian Westphal
v4 cover fix syzkaller splats reported by Christoph
This fixes the syzkaller splats with reproducers that Christoph forwarded to the mailing list, including the one wrt. slab oob in syncookie mode.
First patch moves free of the cached extension pointer to the destroy callback to make sure no other call path can allocate a new one. Actually net-next should be fine in this regard (no msk work queue yet), but as Paolo pointed out it looks bogus when 3rd patch calls it with mptcp lock already released.
2nd patch fixes a crash with set/getsockopt interface and resolves a lockdep splat due to calls to rtnl_lock while already holding the msk lock.
I resolved both in the same patch because the fixes need to touch the same spot.
3rd patch fixes another lockdep splat, this time during mptcp_close but again related to rtnl_lock.
Last patch avoid OOB access when syncookies are used.
This should be resolved differently, as mptcp v1 can use 4th ack to recover state, but that will be more intrusive so this fix downgrades to TCP instead.
See patches for more detailed explanation.
include/linux/tcp.h | 2 -- net/ipv4/syncookies.c | 4 ++++ net/ipv4/tcp_input.c | 3 +++ net/ipv6/syncookies.c | 3 +++ net/mptcp/protocol.c | 48 ++++++++++++++++++++++++++++-------------------- net/mptcp/subflow.c | 5 ++++- 6 files changed, 42 insertions(+), 23 deletions(-)
Florian Westphal
PATCH 1/4 mptcp: protocol: defer freeing of cached ext until last moment
access to msk->cached_ext is only legal if the msk is locked or all concurrent accesses are impossible.
Furthermore, once we start to tear down, we must make sure nothing else can step in and allocate a new cached ext.
So place this code in the destroy callback where it belongs.
---
patch is new in this round.
net/mptcp/protocol.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
net/mptcp/protocol.c +4 -2
@@ -654,8 +654,6 @@ static void __mptcp_close(struct sock *sk, long timeout)__mptcp_close_ssk (sk, ssk, subflow, timeout); } -if (msk->cached_ext) -__skb_ext_put (msk->cached_ext);release_sock (sk);sk_common_release (sk); }
@@ -776,6 +774,10 @@ static struct sock *mptcp_accept(struct sock *sk, int flags, int *err,static void mptcp_destroy (struct sock *sk) { +struct mptcp_sock *msk =mptcp_sk (sk); + +if (msk->cached_ext) +__skb_ext_put (msk->cached_ext); } static int mptcp_setsockopt(struct sock *sk, int level, int optname,
Signature · 1 line
2.24.1
Florian Westphal
PATCH v4 2/4 mptcp: protocol: fix panic on user pointer access
In reply to Florian WestphalIts not possible to call the kernel_(s|g)etsockopt functions here, the address points to user memory:
General protection fault in user access. Non-canonical address?
WARNING: CPU: 1 PID: 5352 at arch/x86/mm/extable.c:77 ex_handler_uaccess+0xba/0xe0 arch/x86/mm/extable.c:77 Kernel panic - not syncing: panic_on_warn set ... [..] Call Trace: fixup_exception+0x9d/0xcd arch/x86/mm/extable.c:178 general_protection+0x2d/0x40 arch/x86/entry/entry_64.S:1202 do_ip_getsockopt+0x1f6/0x1860 net/ipv4/ip_sockglue.c:1323 ip_getsockopt+0x87/0x1c0 net/ipv4/ip_sockglue.c:1561 tcp_getsockopt net/ipv4/tcp.c:3691 [inline] tcp_getsockopt+0x8c/0xd0 net/ipv4/tcp.c:3685 kernel_getsockopt+0x121/0x1f0 net/socket.c:3736 mptcp_getsockopt+0x69/0x90 net/mptcp/protocol.c:830 __sys_getsockopt+0x13a/0x220 net/socket.c:2175
v2: also fix a circular locking dependency reported by Christoph:
release the mptcp-level lock before calling set/getsockopt on the underlying tcp subflow socket, else this yields:
v4: no need to check for SOL_SOCKET again (Paolo)
WARNING: possible circular locking dependency detected
5.5.0-rc6 #2 Not tainted
------------------------------------------------------
syz-executor.0/16334 is trying to acquire lock:
ffffffff84f7a080 (rtnl_mutex){+.+.}, at: do_ip_setsockopt.isra.0+0x277/0x3820 net/ipv4/ip_sockglue.c:644 but task is already holding lock:
ffff888116503b90 (sk_lock-AF_INET){+.+.}, at: lock_sock include/net/sock.h:1516 [inline] ffff888116503b90 (sk_lock-AF_INET){+.+.}, at: mptcp_setsockopt+0x28/0x90 net/mptcp/protocol.c:1284
which lock already depends on the new lock. the existing dependency chain (in reverse order) is:
-> #1 (sk_lock-AF_INET){+.+.}:
lock_sock_nested+0xca/0x120 net/core/sock.c:2944
lock_sock include/net/sock.h:1516 [inline]
do_ip_setsockopt.isra.0+0x281/0x3820 net/ipv4/ip_sockglue.c:645
ip_setsockopt+0x44/0xf0 net/ipv4/ip_sockglue.c:1248
udp_setsockopt+0x5d/0xa0 net/ipv4/udp.c:2639
__sys_setsockopt+0x152/0x240 net/socket.c:2130
__do_sys_setsockopt net/socket.c:2146 [inline]
__se_sys_setsockopt net/socket.c:2143 [inline]
__x64_sys_setsockopt+0xba/0x150 net/socket.c:2143
do_syscall_64+0xbd/0x5b0 arch/x86/entry/common.c:294
entry_SYSCALL_64_after_hwframe+0x49/0xbe-> #0 (rtnl_mutex){+.+.}:
check_prev_add kernel/locking/lockdep.c:2475 [inline]
check_prevs_add kernel/locking/lockdep.c:2580 [inline]
validate_chain kernel/locking/lockdep.c:2970 [inline]
__lock_acquire+0x1fb2/0x4680 kernel/locking/lockdep.c:3954
lock_acquire+0x127/0x330 kernel/locking/lockdep.c:4484
__mutex_lock_common kernel/locking/mutex.c:956 [inline]
__mutex_lock+0x158/0x1340 kernel/locking/mutex.c:1103
do_ip_setsockopt.isra.0+0x277/0x3820 net/ipv4/ip_sockglue.c:644
ip_setsockopt+0x44/0xf0 net/ipv4/ip_sockglue.c:1248
tcp_setsockopt net/ipv4/tcp.c:3159 [inline]
tcp_setsockopt+0x8c/0xd0 net/ipv4/tcp.c:3153
kernel_setsockopt+0x121/0x1f0 net/socket.c:3767
mptcp_setsockopt+0x69/0x90 net/mptcp/protocol.c:1288
__sys_setsockopt+0x152/0x240 net/socket.c:2130
__do_sys_setsockopt net/socket.c:2146 [inline]
__se_sys_setsockopt net/socket.c:2143 [inline]
__x64_sys_setsockopt+0xba/0x150 net/socket.c:2143
do_syscall_64+0xbd/0x5b0 arch/x86/entry/common.c:294
entry_SYSCALL_64_after_hwframe+0x49/0xbeother info that might help us debug this:
Possible unsafe locking scenario:
CPU0 CPU1
---- ----
lock(sk_lock-AF_INET);
lock(rtnl_mutex);
lock(sk_lock-AF_INET); lock(rtnl_mutex);
v4: no need to handle SOL_SOCKET, sys_s/getsockopt handles this already.
--- net/mptcp/protocol.c | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-)
net/mptcp/protocol.c +18 -16
@@ -780,17 +780,19 @@ static void mptcp_destroy(struct sock *sk)__skb_ext_put (msk->cached_ext); } +static int subflow_setsockopt (struct socket *sock,int level,int optname, +char __user *optval,unsigned int optlen) +{ +return sock->ops->setsockopt (sock, level, optname, optval, optlen); +} +static int mptcp_setsockopt (struct sock *sk,int level,int optname, -char __user *uoptval,unsigned int optlen) +char __user *optval,unsigned int optlen) {struct mptcp_sock *msk =mptcp_sk (sk); -char __kernel *optval;int ret = -EOPNOTSUPP ;struct socket *ssock; -/* will be treated as __user in tcp_setsockopt */ - optval = (char __kernel __force *)uoptval; -pr_debug ("msk=%p" , msk);/* @@ the meaning of setsockopt() when the socket is connected and
@@ -798,28 +800,28 @@ static int mptcp_setsockopt(struct sock *sk, int level, int optname,*/ lock_sock (sk); ssock =__mptcp_socket_create (msk,MPTCP_SAME_STATE ); +release_sock (sk);if (!IS_ERR (ssock)) {pr_debug ("subflow=%p" , ssock->sk); - ret =kernel_setsockopt (ssock, level, optname, optval, optlen); + ret =subflow_setsockopt (ssock, level, optname, optval, optlen); } -release_sock (sk);return ret; } +static int subflow_getsockopt (struct socket *sock,int level,int optname, +char __user *optval,int __user *optlen) +{ +return sock->ops->getsockopt (sock, level, optname, optval, optlen); +} +static int mptcp_getsockopt (struct sock *sk,int level,int optname, -char __user *uoptval,int __user *uoption) +char __user *optval,int __user *option) {struct mptcp_sock *msk =mptcp_sk (sk); -char __kernel *optval;int ret = -EOPNOTSUPP ; -int __kernel *option;struct socket *ssock; -/* will be treated as __user in tcp_getsockopt */ - optval = (char __kernel __force *)uoptval; - option = (int __kernel __force *)uoption; -pr_debug ("msk=%p" , msk);/* @@ the meaning of getsockopt() when the socket is connected and
@@ -827,11 +829,11 @@ static int mptcp_getsockopt(struct sock *sk, int level, int optname,*/ lock_sock (sk); ssock =__mptcp_socket_create (msk,MPTCP_SAME_STATE ); +release_sock (sk);if (!IS_ERR (ssock)) {pr_debug ("subflow=%p" , ssock->sk); - ret =kernel_getsockopt (ssock, level, optname, optval, option); + ret =subflow_getsockopt (ssock, level, optname, optval, option); } -release_sock (sk);return ret; }
Signature · 1 line
2.24.1
Paolo Abeni
[MPTCP] Re: [PATCH net-next v4 2/4] mptcp: protocol: fix panic on user pointer access
Hi,
Quoted 119 lines · Florian Westphal
Its not possible to call the kernel_(s|g)etsockopt functions here, the address points to user memory:
General protection fault in user access. Non-canonical address?
WARNING: CPU: 1 PID: 5352 at arch/x86/mm/extable.c:77 ex_handler_uaccess+0xba/0xe0 arch/x86/mm/extable.c:77 Kernel panic - not syncing: panic_on_warn set ... [..] Call Trace: fixup_exception+0x9d/0xcd arch/x86/mm/extable.c:178 general_protection+0x2d/0x40 arch/x86/entry/entry_64.S:1202 do_ip_getsockopt+0x1f6/0x1860 net/ipv4/ip_sockglue.c:1323 ip_getsockopt+0x87/0x1c0 net/ipv4/ip_sockglue.c:1561 tcp_getsockopt net/ipv4/tcp.c:3691 [inline] tcp_getsockopt+0x8c/0xd0 net/ipv4/tcp.c:3685 kernel_getsockopt+0x121/0x1f0 net/socket.c:3736 mptcp_getsockopt+0x69/0x90 net/mptcp/protocol.c:830 __sys_getsockopt+0x13a/0x220 net/socket.c:2175v2: also fix a circular locking dependency reported by Christoph:
release the mptcp-level lock before calling set/getsockopt on the underlying tcp subflow socket, else this yields:
v4: no need to check forSOL_SOCKETagain (Paolo)WARNING: possible circular locking dependency detected
5.5.0-rc6 #2 Not tainted
------------------------------------------------------
syz-executor.0/16334 is trying to acquire lock:
ffffffff84f7a080(rtnl_mutex){+.+.}, at: do_ip_setsockopt.isra.0+0x277/0x3820net/ipv4/ip_sockglue.c:644but task is already holding lock:
ffff888116503b90(sk_lock-AF_INET){+.+.}, at:lock_sockinclude/net/sock.h:1516[inline]ffff888116503b90(sk_lock-AF_INET){+.+.}, at:mptcp_setsockopt+0x28/0x90net/mptcp/protocol.c:1284which lock already depends on the new lock. the existing dependency chain (in reverse order) is:
-> #1 (sk_lock-AF_INET){+.+.}:
lock_sock_nested+0xca/0x120 net/core/sock.c:2944 lock_sock include/net/sock.h:1516 [inline] do_ip_setsockopt.isra.0+0x281/0x3820 net/ipv4/ip_sockglue.c:645 ip_setsockopt+0x44/0xf0 net/ipv4/ip_sockglue.c:1248 udp_setsockopt+0x5d/0xa0 net/ipv4/udp.c:2639 __sys_setsockopt+0x152/0x240 net/socket.c:2130 __do_sys_setsockopt net/socket.c:2146 [inline] __se_sys_setsockopt net/socket.c:2143 [inline] __x64_sys_setsockopt+0xba/0x150 net/socket.c:2143 do_syscall_64+0xbd/0x5b0 arch/x86/entry/common.c:294 entry_SYSCALL_64_after_hwframe+0x49/0xbe-> #0 (rtnl_mutex){+.+.}:
check_prev_add kernel/locking/lockdep.c:2475 [inline] check_prevs_add kernel/locking/lockdep.c:2580 [inline] validate_chain kernel/locking/lockdep.c:2970 [inline] __lock_acquire+0x1fb2/0x4680 kernel/locking/lockdep.c:3954 lock_acquire+0x127/0x330 kernel/locking/lockdep.c:4484 __mutex_lock_common kernel/locking/mutex.c:956 [inline] __mutex_lock+0x158/0x1340 kernel/locking/mutex.c:1103 do_ip_setsockopt.isra.0+0x277/0x3820 net/ipv4/ip_sockglue.c:644 ip_setsockopt+0x44/0xf0 net/ipv4/ip_sockglue.c:1248 tcp_setsockopt net/ipv4/tcp.c:3159 [inline] tcp_setsockopt+0x8c/0xd0 net/ipv4/tcp.c:3153 kernel_setsockopt+0x121/0x1f0 net/socket.c:3767 mptcp_setsockopt+0x69/0x90 net/mptcp/protocol.c:1288 __sys_setsockopt+0x152/0x240 net/socket.c:2130 __do_sys_setsockopt net/socket.c:2146 [inline] __se_sys_setsockopt net/socket.c:2143 [inline] __x64_sys_setsockopt+0xba/0x150 net/socket.c:2143 do_syscall_64+0xbd/0x5b0 arch/x86/entry/common.c:294 entry_SYSCALL_64_after_hwframe+0x49/0xbeother info that might help us debug this:
Possible unsafe locking scenario:CPU0 CPU1 ---- ---- lock(sk_lock-AF_INET); lock(rtnl_mutex); lock(sk_lock-AF_INET);
lock(rtnl_mutex);v4: no need to handle
SOL_SOCKET, sys_s/getsockopt handles this already.Fixes 717e79c867ca5 ("mptcp: Add setsockopt()/getsockopt() socket operations")Reported-by Christoph Paasch <cpaasch(a)apple.com>Signed-off-by Florian Westphal <fw(a)strlen.de>--- net/mptcp/protocol.c | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-)net/mptcp/protocol.c +7
-5@@ -780,17 +780,19 @@ static void mptcp_destroy(struct sock *sk)__skb_ext_put (msk->cached_ext); } +static int subflow_setsockopt (struct socket *sock,int level,int optname, +char __user *optval,unsigned int optlen) +{ +return sock->ops->setsockopt (sock, level, optname, optval, optlen); +} +static int mptcp_setsockopt (struct sock *sk,int level,int optname, -char __user *uoptval,unsigned int optlen) +char __user *optval,unsigned int optlen) {struct mptcp_sock *msk =mptcp_sk (sk); -char __kernel *optval;int ret = -EOPNOTSUPP ;struct socket *ssock; -/* will be treated as __user in tcp_setsockopt */ - optval = (char __kernel __force *)uoptval; -pr_debug ("msk=%p" , msk);/* @@ the meaning of setsockopt() when the socket is connected and
net/mptcp/protocol.c static int mptcp_setsockopt(struct sock *sk, int level, int optname, · line 805
Quoted 10 lines
net/mptcp/protocol.c +2
-2@@ -798,28 +800,28 @@ static int mptcp_setsockopt(struct sock *sk, int level, int optname,*/ lock_sock (sk); ssock =__mptcp_socket_create (msk,MPTCP_SAME_STATE ); +release_sock (sk);if (!IS_ERR (ssock)) {pr_debug ("subflow=%p" , ssock->sk); - ret =kernel_setsockopt (ssock, level, optname, optval, optlen); + ret =subflow_setsockopt (ssock, level, optname, optval, optlen); } -release_sock (sk);
Can the patched code possibly race with mptcp_close(), so that after releasing the socket lock the subflow is destroyed (by mptcp_close()) and we hit UaF in subflow_setsockopt()?
I fear we need that lookup/get/<op>/put schema here ?!?
Am I missing something here ?!?
Thanks,
Paolo
Florian Westphal
PATCH v2 3/4 mptcp: mptcp_close: avoid a lockdep splat when mcast group was joined
In reply to Florian Westphalsyzbot triggered following lockdep splat:
ffffffff82d2cd40 (rtnl_mutex){+.+.}, at: ip_mc_drop_socket+0x52/0x180 but task is already holding lock:ffff8881187a2310 (sk_lock-AF_INET){+.+.}, at: mptcp_close+0x18/0x30
which lock already depends on the new lock.
the existing dependency chain (in reverse order) is:
-> #1 (sk_lock-AF_INET){+.+.}:
lock_acquire+0xee/0x230
lock_sock_nested+0x89/0xc0
do_ip_setsockopt.isra.0+0x335/0x22f0
ip_setsockopt+0x35/0x60
tcp_setsockopt+0x5d/0x90
__sys_setsockopt+0xf3/0x190
__x64_sys_setsockopt+0x61/0x70
do_syscall_64+0x72/0x300
entry_SYSCALL_64_after_hwframe+0x49/0xbe
-> #0 (rtnl_mutex){+.+.}:
check_prevs_add+0x2b7/0x1210
__lock_acquire+0x10b6/0x1400
lock_acquire+0xee/0x230
__mutex_lock+0x120/0xc70
ip_mc_drop_socket+0x52/0x180
inet_release+0x36/0xe0
__sock_release+0xfd/0x130
__mptcp_close+0xa8/0x1f0
inet_release+0x7f/0xe0
__sock_release+0x69/0x130
sock_close+0x18/0x20
__fput+0x179/0x400
task_work_run+0xd5/0x110
do_exit+0x685/0x1510
do_group_exit+0x7e/0x170
__x64_sys_exit_group+0x28/0x30
do_syscall_64+0x72/0x300
entry_SYSCALL_64_after_hwframe+0x49/0xbeThe trigger is:
socket(AF_INET, SOCK_STREAM, 0x106 /* IPPROTO_MPTCP */) = 4
setsockopt(4, SOL_IP, MCAST_JOIN_GROUP, {gr_interface=7, gr_group={sa_family=AF_INET, sin_port=htons(20003), sin_addr=inet_addr("224.0.0.2")}}, 136) = 0 exit(0)
Which results in a call to rtnl_lock while we are holding
the parent mptcp socket lock viamptcp_close -> lock_sock(msk) -> inet_release -> ip_mc_drop_socket -> rtnl_lock().
From lockdep point of view we thus have both 'rtnl_lock; lock_sock' and 'lock_sock; rtnl_lock'.
Fix this by stealing the msk conn_list and doing the subflow close without holding the msk lock.
---
v2: rebase to account for new patch 1.
net/mptcp/protocol.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
net/mptcp/protocol.c +6 -2
@@ -644,17 +644,21 @@ static void __mptcp_close(struct sock *sk, long timeout) {struct mptcp_subflow_context *subflow, *tmp;struct mptcp_sock *msk =mptcp_sk (sk); +LIST_HEAD (conn_list);mptcp_token_destroy (msk->token);inet_sk_state_store (sk,TCP_CLOSE ); -list_for_each_entry_safe (subflow, tmp, &msk->conn_list, node) { +list_splice_init (&msk->conn_list, &conn_list); + +release_sock (sk); + +list_for_each_entry_safe (subflow, tmp, &conn_list, node) {struct sock *ssk =mptcp_subflow_tcp_sock (subflow);__mptcp_close_ssk (sk, ssk, subflow, timeout); } -release_sock (sk);sk_common_release (sk); }
Signature · 1 line
2.24.1
Florian Westphal
PATCH 4/4 mptcp: handle tcp fallback when using syn cookies
In reply to Florian WestphalWe can't deal with syncookie mode yet, the syncookie rx path will create tcp rsk instead of mptcp rsk, i.e. we get OOB access because we treat tcp rsk as mptcp rsk:
TCP: request_sock_subflow: Possible SYN flooding on port 20002. Sending cookies. Check SNMP counters.
BUG: KASAN: slab-out-of-bounds in subflow_syn_recv_sock+0x451/0x4d0 net/mptcp/subflow.c:191 Read of size 1 at addr ffff8881167bc148 by task syz-executor099/2120 subflow_syn_recv_sock+0x451/0x4d0 net/mptcp/subflow.c:191 tcp_get_cookie_sock+0xcf/0x520 net/ipv4/syncookies.c:209 cookie_v6_check+0x15a5/0x1e90 net/ipv6/syncookies.c:252 tcp_v6_cookie_check net/ipv6/tcp_ipv6.c:1123 [inline] [..]
Bug can be reproduced via "sysctl net.ipv4.tcp_syncookies=2".
Note that MPTCP should work with syncookies (4th ack would carry needed state), but it appears better to sort that out in -next so do tcp fallback for now.
I decided to remove the ifdef on tcp_rsk "is_mptcp" member because if (IS_ENABLED()) is easier to read than "#ifdef IS_ENABLED()/#endif" pair.
---
patch is new in this set.
include/linux/tcp.h | 2 -- net/ipv4/syncookies.c | 4 ++++ net/ipv4/tcp_input.c | 3 +++ net/ipv6/syncookies.c | 3 +++ net/mptcp/subflow.c | 5 ++++- 5 files changed, 14 insertions(+), 3 deletions(-)
include/linux/tcp.h +0 -2
@@ -148,9 +148,7 @@ struct tcp_request_sock {const struct tcp_request_sock_ops *af_specific;u64 snt_synack;/* first SYNACK sent time */ bool tfo_listener; -#if IS_ENABLED (CONFIG_MPTCP )bool is_mptcp; -#endif u32 txhash;u32 rcv_isn;u32 snt_isn;
net/ipv4/syncookies.c +4 -0
@@ -349,6 +349,10 @@ struct sock *cookie_v4_check(struct sock *sk, struct sk_buff *skb) req->ts_recent = tcp_opt.saw_tstamp ? tcp_opt.rcv_tsval :0 ; treq->snt_synack =0 ; treq->tfo_listener = false; + +if (IS_ENABLED (CONFIG_MPTCP )) + treq->is_mptcp =0 ; +if (IS_ENABLED (CONFIG_SMC )) ireq->smc_ok =0 ;
net/ipv4/tcp_input.c +3 -0
@@ -6637,6 +6637,9 @@ int tcp_conn_request(struct request_sock_ops *rsk_ops, af_ops->init_req (req, sk, skb); +if (IS_ENABLED (CONFIG_MPTCP ) && want_cookie) +tcp_rsk (req)->is_mptcp =0 ; +if (security_inet_conn_request (sk, skb, req)) goto drop_and_free;
net/ipv6/syncookies.c +3 -0
@@ -178,6 +178,9 @@ struct sock *cookie_v6_check(struct sock *sk, struct sk_buff *skb) treq =tcp_rsk (req); treq->tfo_listener = false; +if (IS_ENABLED (CONFIG_MPTCP )) + treq->is_mptcp =0 ; +if (security_inet_conn_request (sk, skb, req)) goto out_free;
net/mptcp/subflow.c +4 -1
@@ -186,6 +186,9 @@ static struct sock *subflow_syn_recv_sock(const struct sock *sk,pr_debug ("listener=%p, req=%p, conn=%p" , listener, req, listener->conn); +if (tcp_rsk (req)->is_mptcp ==0 ) + goto create_child; +/* if the sk is MP_CAPABLE, we try to fetch the client key */ subflow_req =mptcp_subflow_rsk (req);if (subflow_req->mp_capable) {
@@ -767,7 +770,7 @@ static void subflow_ulp_clone(const struct request_sock *req,struct mptcp_subflow_context *old_ctx =mptcp_subflow_ctx (newsk);struct mptcp_subflow_context *new_ctx; -if (!subflow_req->mp_capable) { +if (!tcp_rsk (req)->is_mptcp || !subflow_req->mp_capable) {subflow_ulp_fallback (newsk, old_ctx);return ; }
Signature · 1 line
2.24.1
Matthieu Baerts
[MPTCP] Re: [PATCH net-next v1 4/4] mptcp: handle tcp fallback when using syn cookies
Hi Florian,
Quoted 13 lines · Florian Westphal
We can't deal with syncookie mode yet, the syncookie rx path will create tcp rsk instead of mptcp rsk, i.e. we get OOB access because we treat tcp rsk as mptcp rsk:
TCP:
request_sock_subflow: Possible SYN flooding on port 20002. Sending cookies. Check SNMP counters.BUG: KASAN: slab-out-of-bounds in subflow_syn_recv_sock+0x451/0x4d0 net/mptcp/subflow.c:191 Read of size 1 at addr ffff8881167bc148 by task syz-executor099/2120 subflow_syn_recv_sock+0x451/0x4d0 net/mptcp/subflow.c:191 tcp_get_cookie_sock+0xcf/0x520 net/ipv4/syncookies.c:209 cookie_v6_check+0x15a5/0x1e90 net/ipv6/syncookies.c:252 tcp_v6_cookie_check net/ipv6/tcp_ipv6.c:1123 [inline] [..]
Quoted 1 line
Bug can be reproduced via "sysctl net.ipv4.tcp_syncookies=2".
Thank you for looking at that!
Quoted 3 lines
Note that MPTCP should work with syncookies (4th ack would carry needed state), but it appears better to sort that out in -next so do tcp fallback for now.
Indeed, it makes sense.
Quoted 2 lines
I decided to remove the ifdef on
tcp_rsk"is_mptcp" member because if (IS_ENABLED()) is easier to read than "#ifdef IS_ENABLED()/#endif" pair.
I agree with you that it is easier to read but will it be OK for upstream? Should we use a bitfield and include 'tfo_listener' in it?
Cheers,
Matt
Signature · 5 lines
Matthieu Baerts | R&D Engineer matthieu.baerts(a)tessares.net Tessares SA | Hybrid Access Solutions www.tessares.net 1 Avenue Jean Monnet, 1348 Louvain-la-Neuve, Belgium
Florian Westphal
[MPTCP] Re: [PATCH net-next v1 4/4] mptcp: handle tcp fallback when using syn cookies
Quoted 6 lines · Matthieu Baerts
Quoted 2 lines · Florian Westphal
I decided to remove the ifdef on
tcp_rsk"is_mptcp" member because if (IS_ENABLED()) is easier to read than "#ifdef IS_ENABLED()/#endif" pair.I agree with you that it is easier to read but will it be OK for upstream? Should we use a bitfield and include '
tfo_listener' in it?
It doesn't increase struct size, so I think its OK. bitfield would be better but not for -net, we can do this in 2 weeks when net-next opens again.
Christoph Paasch
[MPTCP] Re: [PATCH net-next v1 4/4] mptcp: handle tcp fallback when using syn cookies
In reply to Florian WestphalI just tested this one as well. Works fine now!
Christoph
Quoted 117 lines · Florian Westphal
We can't deal with syncookie mode yet, the syncookie rx path will create tcp rsk instead of mptcp rsk, i.e. we get OOB access because we treat tcp rsk as mptcp rsk:
TCP:
request_sock_subflow: Possible SYN flooding on port 20002. Sending cookies. Check SNMP counters.BUG: KASAN: slab-out-of-bounds in subflow_syn_recv_sock+0x451/0x4d0 net/mptcp/subflow.c:191 Read of size 1 at addr ffff8881167bc148 by task syz-executor099/2120 subflow_syn_recv_sock+0x451/0x4d0 net/mptcp/subflow.c:191 tcp_get_cookie_sock+0xcf/0x520 net/ipv4/syncookies.c:209 cookie_v6_check+0x15a5/0x1e90 net/ipv6/syncookies.c:252 tcp_v6_cookie_check net/ipv6/tcp_ipv6.c:1123 [inline] [..]Bug can be reproduced via "sysctl net.ipv4.tcp_syncookies=2".
Note that MPTCP should work with syncookies (4th ack would carry needed state), but it appears better to sort that out in -next so do tcp fallback for now.
I decided to remove the ifdef on
tcp_rsk"is_mptcp" member because if (IS_ENABLED()) is easier to read than "#ifdef IS_ENABLED()/#endif" pair.Reported-by Christoph Paasch <cpaasch(a)apple.com>Signed-off-by Florian Westphal <fw(a)strlen.de>---
patch is new in this set.include/linux/tcp.h | 2 -- net/ipv4/syncookies.c | 4 ++++ net/ipv4/tcp_input.c | 3 +++ net/ipv6/syncookies.c | 3 +++ net/mptcp/subflow.c | 5 ++++- 5 files changed, 14 insertions(+), 3 deletions(-)include/linux/tcp.h +0
-2@@ -148,9 +148,7 @@ struct tcp_request_sock {const struct tcp_request_sock_ops *af_specific;u64 snt_synack;/* first SYNACK sent time */ bool tfo_listener; -#if IS_ENABLED (CONFIG_MPTCP )bool is_mptcp; -#endif u32 txhash;u32 rcv_isn;u32 snt_isn;net/ipv4/syncookies.c +4
-0@@ -349,6 +349,10 @@ struct sock *cookie_v4_check(struct sock *sk, struct sk_buff *skb) req->ts_recent = tcp_opt.saw_tstamp ? tcp_opt.rcv_tsval :0 ; treq->snt_synack =0 ; treq->tfo_listener = false; + +if (IS_ENABLED (CONFIG_MPTCP )) + treq->is_mptcp =0 ; +if (IS_ENABLED (CONFIG_SMC )) ireq->smc_ok =0 ;net/ipv4/tcp_input.c +3
-0@@ -6637,6 +6637,9 @@ int tcp_conn_request(struct request_sock_ops *rsk_ops, af_ops->init_req (req, sk, skb); +if (IS_ENABLED (CONFIG_MPTCP ) && want_cookie) +tcp_rsk (req)->is_mptcp =0 ; +if (security_inet_conn_request (sk, skb, req)) goto drop_and_free;net/ipv6/syncookies.c +3
-0@@ -178,6 +178,9 @@ struct sock *cookie_v6_check(struct sock *sk, struct sk_buff *skb) treq =tcp_rsk (req); treq->tfo_listener = false; +if (IS_ENABLED (CONFIG_MPTCP )) + treq->is_mptcp =0 ; +if (security_inet_conn_request (sk, skb, req)) goto out_free;net/mptcp/subflow.c +4
-1@@ -186,6 +186,9 @@ static struct sock *subflow_syn_recv_sock(const struct sock *sk,pr_debug ("listener=%p, req=%p, conn=%p" , listener, req, listener->conn); +if (tcp_rsk (req)->is_mptcp ==0 ) + goto create_child; +/* if the sk is MP_CAPABLE, we try to fetch the client key */ subflow_req =mptcp_subflow_rsk (req);if (subflow_req->mp_capable) {@@ -767,7 +770,7 @@ static void subflow_ulp_clone(const struct request_sock *req,struct mptcp_subflow_context *old_ctx =mptcp_subflow_ctx (newsk);struct mptcp_subflow_context *new_ctx; -if (!subflow_req->mp_capable) { +if (!tcp_rsk (req)->is_mptcp || !subflow_req->mp_capable) {subflow_ulp_fallback (newsk, old_ctx);return ; }Signature · 1 line
2.24.1
Paolo Abeni
Quoted 25 lines · Florian Westphal
This fixes the syzkaller splats with reproducers that Christoph forwarded to the mailing list, including the one wrt. slab oob in syncookie mode.
First patch moves free of the cached extension pointer to the destroy callback to make sure no other call path can allocate a new one. Actually net-next should be fine in this regard (no msk work queue yet), but as Paolo pointed out it looks bogus when 3rd patch calls it with mptcp lock already released.
2nd patch fixes a crash with set/getsockopt interface and resolves a lockdep splat due to calls to
rtnl_lockwhile already holding the msk lock.I resolved both in the same patch because the fixes need to touch the same spot.
3rd patch fixes another lockdep splat, this time during
mptcp_closebut again related tortnl_lock.Last patch avoid OOB access when syncookies are used.
This should be resolved differently, as mptcp v1 can use 4th ack to recover state, but that will be more intrusive so this fix downgrades to TCP instead.See patches for more detailed explanation.
Quoted 7 lines
include/linux/tcp.h | 2 -- net/ipv4/syncookies.c | 4 ++++ net/ipv4/tcp_input.c | 3 +++ net/ipv6/syncookies.c | 3 +++ net/mptcp/protocol.c | 48 ++++++++++++++++++++++++++++-------------------- net/mptcp/subflow.c | 5 ++++- 6 files changed, 42 insertions(+), 23 deletions(-)
Except for the already reported note on patch 2/4, I think the others patches are good.
Thanks Florian for fixing our mess ;)
/P