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

* RE: [PATCH net-next] vsock: avoid to assign transport if its initialization fails
  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
  1 sibling, 0 replies; 3+ messages in thread
From: Jorgen Hansen @ 2019-11-21 15:14 UTC (permalink / raw)
  To: 'Stefano Garzarella', davem
  Cc: netdev, linux-kernel, syzbot+e2e5c07bf353b2f79daa,
	Stefan Hajnoczi, Dexuan Cui

> From: Stefano Garzarella [mailto:sgarzare@redhat.com]
> Sent: Thursday, November 21, 2019 10:06 AM
> 
> 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

Reviewed-by: Jorgen Hansen <jhansen@vmware.com>


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

* Re: [PATCH net-next] vsock: avoid to assign transport if its initialization fails
  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
  1 sibling, 0 replies; 3+ messages in thread
From: David Miller @ 2019-11-21 19:37 UTC (permalink / raw)
  To: sgarzare
  Cc: netdev, linux-kernel, syzbot+e2e5c07bf353b2f79daa, stefanha,
	decui, jhansen

From: Stefano Garzarella <sgarzare@redhat.com>
Date: Thu, 21 Nov 2019 10:06:09 +0100

> 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>

Applied.

^ permalink raw reply	[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).