From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 619F123370B; Mon, 10 Mar 2025 18:23:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741631028; cv=none; b=hIKSrscHJ1qAx3oeCzQTm/gq2492PUJfZ9kseqh+WyUDQLuQv3XFoTuhbCCyQoi6EciL/tU+xWtFb7mrYn40i6fRR37IXoIcHgZQgq5/1KuJJw+12wCYWsJ+5K5TY5vbCN7xtlj61NOQKdGZ0UKbwkmMnUykh9xQGZIhsngnFPg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741631028; c=relaxed/simple; bh=NyVbqaRQWPI/8y+XhEcNgPkotpnt/FMWIzSZe99oRBU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=oklKgMyQC+fAppO8q/66DICfbgJ4pQtElMo/Zmkdfd63s6jpNDWui5aElQOx93m7skTc/N392bybIxkLD6E8wXWmPmBT16FLHPuEjuuT5gu4lrQIq/RqITdt8JSyYXifd8ZjzTpBatlqhBQD7YJzbdPs4iCCXkX3fkXxtOSAX5M= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=yyOubqpb; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="yyOubqpb" Received: by smtp.kernel.org (Postfix) with ESMTPSA id DCE53C4CEED; Mon, 10 Mar 2025 18:23:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1741631028; bh=NyVbqaRQWPI/8y+XhEcNgPkotpnt/FMWIzSZe99oRBU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=yyOubqpbWAOpgso/0ArTqHRolVpPzHjjnEr2/2YNnZl0IW0flPqLitVuACu5lI9cQ PUoceCh/9go68EYxdPUhpl7u0VsWHOKvikdpHrgRVdNDYNf0CLU5amq7EOtGba4XSd wyz4Z6Tvb+fNi78LRHbCJX44IZplkQ4HMF+crhCA= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, syzbot+9d55b199192a4be7d02c@syzkaller.appspotmail.com, Luigi Leonardi , Michal Luczaj , Jakub Kicinski Subject: [PATCH 5.15 617/620] vsock: Orphan socket after transport release Date: Mon, 10 Mar 2025 18:07:43 +0100 Message-ID: <20250310170609.889256516@linuxfoundation.org> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250310170545.553361750@linuxfoundation.org> References: <20250310170545.553361750@linuxfoundation.org> User-Agent: quilt/0.68 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 5.15-stable review patch. If anyone has any objections, please let me know. ------------------ From: Michal Luczaj commit 78dafe1cf3afa02ed71084b350713b07e72a18fb upstream. 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: syzbot+9d55b199192a4be7d02c@syzkaller.appspotmail.com Closes: https://syzkaller.appspot.com/bug?extid=9d55b199192a4be7d02c Fixes: fcdd2242c023 ("vsock: Keep the binding until socket destruction") Tested-by: Luigi Leonardi Reviewed-by: Luigi Leonardi Signed-off-by: Michal Luczaj Link: https://patch.msgid.link/20250210-vsock-linger-nullderef-v3-1-ef6244d02b54@rbox.co Signed-off-by: Jakub Kicinski Signed-off-by: Luigi Leonardi Signed-off-by: Greg Kroah-Hartman --- net/vmw_vsock/af_vsock.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) --- a/net/vmw_vsock/af_vsock.c +++ b/net/vmw_vsock/af_vsock.c @@ -818,13 +818,19 @@ static void __vsock_release(struct sock */ 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 (sock_type_connectible(sk->sk_type)) vsock_remove_sock(vsk); + sock_orphan(sk); sk->sk_shutdown = SHUTDOWN_MASK; skb_queue_purge(&sk->sk_receive_queue);