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 CFE611DE8A6; Wed, 19 Feb 2025 09:05:01 +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=1739955901; cv=none; b=rY/CmpT7ul8IpEXtPwFID2kdXFjTD7H8uisAsjBK6BnKw1Q4Sk+KEKmEbIjtw+ePScCXAE7Pi7L2cGYIqJMjYCVedNUewLXSU/h1o6iwxYOlUyvRgiTqOpKaarQEI4tZSrl1Fi9ikoUsmvz34Zb7L8qY1XrYR/6xCVpoIOD3hu0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739955901; c=relaxed/simple; bh=AHKTlcrZuGnozJ0epa/KWVamWIXzyX0sicNhUSVRAag=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=u1ie23ca80wkKqx98mlMPzhrZDoDpLgU4IUdTSO1LLoLx3eqVeAl/YLxrpynOUN8RDUrl+N40s2ZofZOVfiAUVvYx0u6h++GtniMDH+PemLvOizLK0iu5MU6tdFrwgnFl71f6+Epn/7aurvDr96p7NPHJhG2Aiz4deJSOfYZmxI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=DbTKn/3I; 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="DbTKn/3I" Received: by smtp.kernel.org (Postfix) with ESMTPSA id E82CDC4CED1; Wed, 19 Feb 2025 09:05:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1739955901; bh=AHKTlcrZuGnozJ0epa/KWVamWIXzyX0sicNhUSVRAag=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=DbTKn/3In/ItGuBrwSMmyv7rfWfgZK9CJTX00vwzpFZvZiKbNkohdjudwzV+mMPfI 42FWO8n5ZUfaKmoojqqYyv9KOnwAjAZr9tZvLLhFmirIQvNwd+0BceryhaJ3fv0ZLZ m6UmOVE9i+0RTnaZyaZo9mNlmzeqIAISmwKjsfAU= 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 6.6 150/152] vsock: Orphan socket after transport release Date: Wed, 19 Feb 2025 09:29:23 +0100 Message-ID: <20250219082555.980574749@linuxfoundation.org> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250219082550.014812078@linuxfoundation.org> References: <20250219082550.014812078@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 6.6-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: 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 @@ -823,13 +823,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);