vhost/vsock: Fix error handling in vhost_vsock_init()
Subsystems (6)
PATCH v2 1/1 vhost/vsock: Fix error handling in vhost_vsock_init()
A problem about modprobe vhost_vsock failed is triggered with the following log given:
modprobe: ERROR: could not insert 'vhost_vsock': Device or resource busy
The reason is that vhost_vsock_init() returns misc_register() directly without checking its return value, if misc_register() failed, it returns without calling vsock_core_unregister() on vhost_transport, resulting the vhost_vsock can never be installed later.
A simple call graph is shown as below:
vhost_vsock_init()
vsock_core_register() # register vhost_transport misc_register()
device_create_with_groups()
device_create_groups_vargs()
dev = kzalloc(...) # OOM happened
# return without unregister vhost_transport
Fix by calling vsock_core_unregister() when misc_register() returns error.
---
Changes in v2:
- change to the correct Fixes: tag
drivers/vhost/vsock.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)
drivers/vhost/vsock.c +8 -1
@@ -959,7 +959,14 @@ static int __init vhost_vsock_init(void) VSOCK_TRANSPORT_F_H2G);if (ret <0 )return ret; -return misc_register (&vhost_vsock_misc); + + ret =misc_register (&vhost_vsock_misc); +if (ret) { +vsock_core_unregister (&vhost_transport.transport); +return ret; + } + +return 0 ; }; static void __exit vhost_vsock_exit(void)
Signature · 1 line
2.17.1
Quoted 19 lines · Yuan Can
A problem about modprobe
vhost_vsockfailed is triggered with the following log given:modprobe: ERROR: could not insert '
vhost_vsock': Device or resource busyThe reason is that
vhost_vsock_init()returnsmisc_register()directly without checking its return value, ifmisc_register()failed, it returns without callingvsock_core_unregister()onvhost_transport, resulting thevhost_vsockcan never be installed later.
A simple call graph is shown as below:
vhost_vsock_init()
vsock_core_register()# registervhost_transportmisc_register()
device_create_with_groups()
device_create_groups_vargs()
dev = kzalloc(...) # OOM happened# return without unregister vhost_transport
Quoted 7 lines
Fix by calling
vsock_core_unregister()whenmisc_register()returns error.Fixes 433fc58e6bf2 ("VSOCK: Introduce vhost_vsock.ko")Signed-off-by Yuan Can <[email protected]>---
Changes in v2:
- change to the correct Fixes: tag
I forgot to mention that anyway the patch was okay for me :-) and so:
Thanks,
Stefano
Quoted 27 lines
drivers/vhost/vsock.c| 9 ++++++++-1 file changed, 8 insertions(+), 1 deletion(-)drivers/vhost/vsock.c +8
-1@@ -959,7 +959,14 @@ static int __init vhost_vsock_init(void) VSOCK_TRANSPORT_F_H2G);if (ret <0 )return ret; -return misc_register (&vhost_vsock_misc); + + ret =misc_register (&vhost_vsock_misc); +if (ret) { +vsock_core_unregister (&vhost_transport.transport); +return ret; + } + +return 0 ; }; static void __exit vhost_vsock_exit(void)Signature · 1 line
2.17.1
_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
Quoted 18 lines · Yuan Can
A problem about modprobe
vhost_vsockfailed is triggered with the following log given:modprobe: ERROR: could not insert '
vhost_vsock': Device or resource busyThe reason is that
vhost_vsock_init()returnsmisc_register()directly without checking its return value, ifmisc_register()failed, it returns without callingvsock_core_unregister()onvhost_transport, resulting thevhost_vsockcan never be installed later.
A simple call graph is shown as below:
vhost_vsock_init()
vsock_core_register()# registervhost_transportmisc_register()
device_create_with_groups()
device_create_groups_vargs()
dev = kzalloc(...) # OOM happened
Quoted 6 lines
# return without unregister vhost_transportFix by calling
vsock_core_unregister()whenmisc_register()returns error.Fixes 433fc58e6bf2 ("VSOCK: Introduce vhost_vsock.ko")Signed-off-by Yuan Can <[email protected]>
Quoted 28 lines
---
Changes in v2:
- change to the correct Fixes: tagdrivers/vhost/vsock.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)drivers/vhost/vsock.c +8
-2@@ -959,7 +959,14 @@ static int __init vhost_vsock_init(void) VSOCK_TRANSPORT_F_H2G);if (ret <0 )return ret; -return misc_register (&vhost_vsock_misc); + + ret =misc_register (&vhost_vsock_misc); +if (ret) { +vsock_core_unregister (&vhost_transport.transport); +return ret; + } + +return 0 ; }; static void __exit vhost_vsock_exit(void) --
Quoted 2 lines
2.17.1
_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization