Commit 068518f6 authored by Michal Luczaj's avatar Michal Luczaj Committed by Liu Jian
Browse files

vsock: Orphan socket after transport release

mainline inclusion
from mainline-v6.14-rc3
commit 78dafe1cf3afa02ed71084b350713b07e72a18fb
category: bugfix
bugzilla: https://gitee.com/src-openeuler/kernel/issues/IBPC5N
CVE: CVE-2025-21756

Reference: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=78dafe1cf3afa02ed71084b350713b07e72a18fb



-------------------------------------------------

During socket release, sock_orphan() is called without considering that it
sets sk->sk_wq to NULL. Later, if SO_LINGER is enabled, this leads to a
null pointer dereferenced in virtio_transport_wait_close().

Orphan the socket only after transport release.

Partially reverts the 'Fixes:' commit.

KASAN: null-ptr-deref in range [0x0000000000000018-0x000000000000001f]
 lock_acquire+0x19e/0x500
 _raw_spin_lock_irqsave+0x47/0x70
 add_wait_queue+0x46/0x230
 virtio_transport_release+0x4e7/0x7f0
 __vsock_release+0xfd/0x490
 vsock_release+0x90/0x120
 __sock_release+0xa3/0x250
 sock_close+0x14/0x20
 __fput+0x35e/0xa90
 __x64_sys_close+0x78/0xd0
 do_syscall_64+0x93/0x1b0
 entry_SYSCALL_64_after_hwframe+0x76/0x7e

Reported-by: default avatar <syzbot+9d55b199192a4be7d02c@syzkaller.appspotmail.com>
Closes: https://syzkaller.appspot.com/bug?extid=9d55b199192a4be7d02c


Fixes: fcdd2242c023 ("vsock: Keep the binding until socket destruction")
Tested-by: default avatarLuigi Leonardi <leonardi@redhat.com>
Reviewed-by: default avatarLuigi Leonardi <leonardi@redhat.com>
Signed-off-by: default avatarMichal Luczaj <mhal@rbox.co>
Link: https://patch.msgid.link/20250210-vsock-linger-nullderef-v3-1-ef6244d02b54@rbox.co


Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>

Conflicts:
	net/vmw_vsock/af_vsock.c
[Did not backport 135ffc7becc8.]
Signed-off-by: default avatarLiu Jian <liujian56@huawei.com>
parent 92742c0e
Loading
Loading
Loading
Loading
+7 −1
Original line number Diff line number Diff line
@@ -775,13 +775,19 @@ static void __vsock_release(struct sock *sk, int level)
		 */
		lock_sock_nested(sk, level);

		sock_orphan(sk);
		/* Indicate to vsock_remove_sock() that the socket is being released and
		 * can be removed from the bound_table. Unlike transport reassignment
		 * case, where the socket must remain bound despite vsock_remove_sock()
		 * being called from the transport release() callback.
		 */
		sock_set_flag(sk, SOCK_DEAD);

		if (vsk->transport)
			vsk->transport->release(vsk);
		else if (sk->sk_type == SOCK_STREAM)
			vsock_remove_sock(vsk);

		sock_orphan(sk);
		sk->sk_shutdown = SHUTDOWN_MASK;

		skb_queue_purge(&sk->sk_receive_queue);