vsock: avoid to assign transport if its initialization fails
Subsystems (3)
Stefano Garzarella
maintainerPATCH 1/1 vsock: avoid to assign transport if its initialization fails
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.
--- net/vmw_vsock/af_vsock.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)
net/vmw_vsock/af_vsock.c +8 -1
@@ -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);
Signature · 1 line
2.21.0
Quoted 47 lines
From: Stefano Garzarella [mailto:[email protected]]
Sent: Thursday, November 21, 2019 10:06 AMIf
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:
[email protected]Signed-off-by Stefano Garzarella <[email protected]>--- net/vmw_vsock/af_vsock.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)net/vmw_vsock/af_vsock.c +1
-0@@ -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) {net/vmw_vsock/af_vsock.c +7
-2case 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); --
Quoted 1 line
2.21.0
From: Stefano Garzarella <[email protected]>
Date: Thu, 21 Nov 2019 10:06:09 +0100
Quoted 7 lines
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 [email protected]Signed-off-by Stefano Garzarella <[email protected]>
Applied.