linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net-next] vsock: avoid to assign transport if its initialization fails
@ 2019-11-21  9:06 Stefano Garzarella
  2019-11-21 15:14 ` Jorgen Hansen
  2019-11-21 19:37 ` David Miller
  0 siblings, 2 replies; 3+ messages in thread
From: Stefano Garzarella @ 2019-11-21  9:06 UTC (permalink / raw)
  To: davem
  Cc: netdev, linux-kernel, syzbot+e2e5c07bf353b2f79daa,
	Stefan Hajnoczi, Dexuan Cui, Jorgen Hansen

If transport->init() fails, we can't assign the transport to the
socket, because it's not initialized correctly, and any future
calls to the transport callbacks would have an unexpected behavior.

Fixes: c0cfa2d8a788 ("vsock: add multi-transports support")
Reported-and-tested-by: syzbot+e2e5c07bf353b2f79daa@syzkaller.appspotmail.com
Signed-off-by: Stefano Garzarella <sgarzare@redhat.com>
---
 net/vmw_vsock/af_vsock.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/net/vmw_vsock/af_vsock.c b/net/vmw_vsock/af_vsock.c
index cc8659838bf2..74db4cd637a7 100644
--- a/net/vmw_vsock/af_vsock.c
+++ b/net/vmw_vsock/af_vsock.c
@@ -412,6 +412,7 @@ int vsock_assign_transport(struct vsock_sock *vsk, struct vsock_sock *psk)
 	const struct vsock_transport *new_transport;
 	struct sock *sk = sk_vsock(vsk);
 	unsigned int remote_cid = vsk->remote_addr.svm_cid;
+	int ret;
 
 	switch (sk->sk_type) {
 	case SOCK_DGRAM:
@@ -443,9 +444,15 @@ int vsock_assign_transport(struct vsock_sock *vsk, struct vsock_sock *psk)
 	if (!new_transport || !try_module_get(new_transport->module))
 		return -ENODEV;
 
+	ret = new_transport->init(vsk, psk);
+	if (ret) {
+		module_put(new_transport->module);
+		return ret;
+	}
+
 	vsk->transport = new_transport;
 
-	return vsk->transport->init(vsk, psk);
+	return 0;
 }
 EXPORT_SYMBOL_GPL(vsock_assign_transport);
 
-- 
2.21.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2019-11-21 19:37 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-11-21  9:06 [PATCH net-next] vsock: avoid to assign transport if its initialization fails Stefano Garzarella
2019-11-21 15:14 ` Jorgen Hansen
2019-11-21 19:37 ` David Miller

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).