lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-id: <20200204180553.GG33105@MacBook-Pro-64.local>
Date:   Tue, 04 Feb 2020 10:05:53 -0800
From:   Christoph Paasch <cpaasch@...le.com>
To:     Florian Westphal <fw@...len.de>
Cc:     netdev@...r.kernel.org, Paolo Abeni <pabeni@...hat.com>
Subject: Re: [PATCH net] mptcp: fix use-after-free on tcp fallback

On 04/02/20 - 18:12:30, Florian Westphal wrote:
> When an mptcp socket connects to a tcp peer or when a middlebox interferes
> with tcp options, mptcp needs to fall back to plain tcp.
> Problem is that mptcp is trying to be too clever in this case:
> 
> It attempts to close the mptcp meta sk and transparently replace it with
> the (only) subflow tcp sk.
> 
> Unfortunately, this is racy -- the socket is already exposed to userspace.
> Any parallel calls to send/recv/setsockopt etc. can cause use-after-free:
> 
> BUG: KASAN: use-after-free in atomic_try_cmpxchg include/asm-generic/atomic-instrumented.h:693 [inline]
> CPU: 1 PID: 2083 Comm: syz-executor.1 Not tainted 5.5.0 #2
>  atomic_try_cmpxchg include/asm-generic/atomic-instrumented.h:693 [inline]
>  queued_spin_lock include/asm-generic/qspinlock.h:78 [inline]
>  do_raw_spin_lock include/linux/spinlock.h:181 [inline]
>  __raw_spin_lock_bh include/linux/spinlock_api_smp.h:136 [inline]
>  _raw_spin_lock_bh+0x71/0xd0 kernel/locking/spinlock.c:175
>  spin_lock_bh include/linux/spinlock.h:343 [inline]
>  __lock_sock+0x105/0x190 net/core/sock.c:2414
>  lock_sock_nested+0x10f/0x140 net/core/sock.c:2938
>  lock_sock include/net/sock.h:1516 [inline]
>  mptcp_setsockopt+0x2f/0x1f0 net/mptcp/protocol.c:800
>  __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+0xb7/0x3d0 arch/x86/entry/common.c:294
>  entry_SYSCALL_64_after_hwframe+0x44/0xa9
> 
> While the use-after-free can be resolved, there is another problem:
> sock->ops and sock->sk assignments are not atomic, i.e. we may get calls
> into mptcp functions with sock->sk already pointing at the subflow socket,
> or calls into tcp functions with a mptcp meta sk.
> 
> Remove the fallback code and call the relevant functions for the (only)
> subflow in case the mptcp socket is connected to tcp peer.
> 
> Reported-by: Christoph Paasch <cpaasch@...le.com>
> Diagnosed-by: Paolo Abeni <pabeni@...hat.com>
> Signed-off-by: Florian Westphal <fw@...len.de>
> ---
>  net/mptcp/protocol.c | 76 ++++----------------------------------------
>  1 file changed, 6 insertions(+), 70 deletions(-)

Tested-by: Christoph Paasch <cpaasch@...le.com>

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ