[Devel] [PATCH RHEL7 COMMIT] ms/vsock: avoid to assign transport if its initialization fails
Vasily Averin
vvs at virtuozzo.com
Thu Apr 22 03:41:49 MSK 2021
The commit is pushed to "branch-rh7-3.10.0-1160.21.1.vz7.174.x-ovz" and will appear at https://src.openvz.org/scm/ovz/vzkernel.git
after rh7-3.10.0-1160.21.1.vz7.174.11
------>
commit c85d7d7c4097911c8a7660ed0e61033d1348edf5
Author: Stefano Garzarella <sgarzare at redhat.com>
Date: Thu Apr 22 03:41:49 2021 +0300
ms/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.
Fixes: c0cfa2d8a788 ("vsock: add multi-transports support")
Reported-and-tested-by: syzbot+e2e5c07bf353b2f79daa at syzkaller.appspotmail.com
Signed-off-by: Stefano Garzarella <sgarzare at redhat.com>
Reviewed-by: Jorgen Hansen <jhansen at vmware.com>
Signed-off-by: David S. Miller <davem at davemloft.net>
https://jira.sw.ru/browse/PSBM-128702
(cherry picked from commit 039fcccaed338b2ff6587178c1219c1ef383a1d9)
Signed-off-by: Konstantin Khorenko <khorenko at virtuozzo.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 ff1b2cdef..cc69c6a 100644
--- a/net/vmw_vsock/af_vsock.c
+++ b/net/vmw_vsock/af_vsock.c
@@ -441,6 +441,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:
@@ -472,9 +473,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);
More information about the Devel
mailing list