From patchwork Mon Feb 10 12:15:00 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michal Luczaj X-Patchwork-Id: 13967788 X-Patchwork-Delegate: kuba@kernel.org Received: from mailtransmit05.runbox.com (mailtransmit05.runbox.com [185.226.149.38]) (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 3B722222575 for ; Mon, 10 Feb 2025 12:40:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.226.149.38 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739191254; cv=none; b=QGabbOjoPTodfHpADLfLhJdFYbz1sp0b7w+chEg2SN/o/qH5zbC8+nz8lIah1fyglXO9sHMQiassPwbEmLmo9oKs3ghoAW7c3R0W6mmlpMnkXwMDesmiCp3WI2AHZKoEun9B3kuJ3gPNOdS37Dy+zMnSjCCxdeDBgOLSelQOePM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739191254; c=relaxed/simple; bh=MqA1FsWvjSKtmaQxWAexnfl6xQ7Kq6tPjk8gZxy9Dus=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=aZOEloX1W28oDQflLDIOZcZaLSpDwCD+sRaqYAyNJPwD0+2ma50L/ERve6aH2Ek4nB07AzUOKyjekJWcUnOwGXOoEYiZf6QY5NH2/uXTD8wd6bKSDongk2ZXjVfBTkew730zKBUllcJBKgXJsr52mQZW9WNcXXyu5r9vVbSWyqk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=rbox.co; spf=pass smtp.mailfrom=rbox.co; dkim=pass (2048-bit key) header.d=rbox.co header.i=@rbox.co header.b=Ba7j6/9l; arc=none smtp.client-ip=185.226.149.38 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=rbox.co Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=rbox.co Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=rbox.co header.i=@rbox.co header.b="Ba7j6/9l" Received: from mailtransmit02.runbox ([10.9.9.162] helo=aibo.runbox.com) by mailtransmit05.runbox.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.93) (envelope-from ) id 1thSh4-00BNte-SF; Mon, 10 Feb 2025 13:15:18 +0100 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=rbox.co; s=selector1; h=Cc:To:In-Reply-To:References:Message-Id: Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date:From; bh=JldiuB0XR8hVWEibYgQzf41tTKrljaWoQOxMRih5Tjs=; b=Ba7j6/9lEiTpBtU1HPrplzpJSi iqaauveifuIcjb3E2ubRll1XTdr5F4CQtRl3bs031GFTg8X/4DlaOC3GthwDyULe9Gy/LhwQ7Jce5 YfiLNIq2pNPDzYxDC9DAXq43sKKDesB5u/KOJauaEvKNHLXb7FMmPs8sipQnFoHkxEYx7sg7cOQ7D MN+qYQjLqsMeSRFqPaLvWQA4ji5KVS4XnQATNCVRWK+uPz2e90dIebM637WSQg9AjhRkNdvairX34 VzJ6FYyU9sD2VzJRz9beruVrSYGYTHCHL1/7weK1huQ95zsCLauVLZCOPEDe5IbVuQINJqEEHsAOZ gTvG9CqQ==; Received: from [10.9.9.72] (helo=submission01.runbox) by mailtransmit02.runbox with esmtp (Exim 4.86_2) (envelope-from ) id 1thSh4-00088s-DD; Mon, 10 Feb 2025 13:15:18 +0100 Received: by submission01.runbox with esmtpsa [Authenticated ID (604044)] (TLS1.2:ECDHE_SECP256R1__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim 4.93) id 1thSgx-007tu3-Il; Mon, 10 Feb 2025 13:15:11 +0100 From: Michal Luczaj Date: Mon, 10 Feb 2025 13:15:00 +0100 Subject: [PATCH net v3 1/2] vsock: Orphan socket after transport release Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250210-vsock-linger-nullderef-v3-1-ef6244d02b54@rbox.co> References: <20250210-vsock-linger-nullderef-v3-0-ef6244d02b54@rbox.co> In-Reply-To: <20250210-vsock-linger-nullderef-v3-0-ef6244d02b54@rbox.co> To: Stefano Garzarella , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman Cc: netdev@vger.kernel.org, Michal Luczaj , syzbot+9d55b199192a4be7d02c@syzkaller.appspotmail.com, Luigi Leonardi X-Mailer: b4 0.14.2 X-Patchwork-Delegate: kuba@kernel.org 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 --- net/vmw_vsock/af_vsock.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/net/vmw_vsock/af_vsock.c b/net/vmw_vsock/af_vsock.c index 075695173648d3a4ecbd04e908130efdbb393b41..53a081d49d28ac1c04e7f8057c8a55e7b73cc131 100644 --- a/net/vmw_vsock/af_vsock.c +++ b/net/vmw_vsock/af_vsock.c @@ -824,13 +824,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 (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);