net: cleanup before character devices
PATCH 1/1 net: cleanup before character devices
Otherwise, vhost-user causes a use-after-free.
--- vl.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
vl.c +3 -3
@@ -4327,9 +4327,6 @@ int main(int argc, char **argv, char **envp)qemu_opts_del (icount_opts); } -/* clean up network at qemu process termination */ -atexit (&net_cleanup); -if (default_net) {QemuOptsList *net =qemu_find_opts ("net" );qemu_opts_set (net,NULL ,"type" ,"nic" , &error_abort);
@@ -4596,6 +4593,9 @@ int main(int argc, char **argv, char **envp)#ifdef CONFIG_TPM tpm_cleanup ();#endif + +/* vhost-user must be cleaned up before chardevs. */ +net_cleanup ();qemu_chr_cleanup ();return 0 ;
Signature · 1 line
1.8.3.1
Hi
Quoted 3 lines · Paolo Bonzini
Otherwise, vhost-user causes a use-after-free.
Signed-off-by Paolo Bonzini <[email protected]>
Sorry I didn't see the criticals in make check after my patch... Thanks for fixing it this quickly
Quoted 19 lines
--- vl.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)vl.c +0
-3@@ -4327,9 +4327,6 @@ int main(int argc, char **argv, char **envp)qemu_opts_del (icount_opts); } -/* clean up network at qemu process termination */ -atexit (&net_cleanup); -if (default_net) {QemuOptsList *net =qemu_find_opts ("net" );qemu_opts_set (net,NULL ,"type" ,"nic" , &error_abort);
vl.c int main(int argc, char **argv, char **envp) · line 4598
Quoted 6 lines
vl.c +3
-0@@ -4596,6 +4593,9 @@ int main(int argc, char **argv, char **envp)#ifdef CONFIG_TPM tpm_cleanup ();#endif + +/* vhost-user must be cleaned up before chardevs. */ +net_cleanup ();
Alternatively, if it's better to keep the atexit(net_cleanup), we could have atexit(qemu_chr_cleanup) here, so it's only called on normal exit and after net_cleanup.
Quoted 7 lines
vl.c +0
-1qemu_chr_cleanup ();return 0 ; --1.8.3.1
Signature · 1 line
Marc-André Lureau
Quoted 3 lines · Marc-André Lureau
Alternatively, if it's better to keep the
atexit(net_cleanup), we could haveatexit(qemu_chr_cleanup)here, so it's only called on normal exit and afternet_cleanup.
No, atexit functions are called in LIFO order (which actually makes sense if you think about it :)).
Paolo
Quoted 22 lines · Paolo Bonzini
Otherwise, vhost-user causes a use-after-free.
Signed-off-by Paolo Bonzini <[email protected]>--- vl.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)vl.c +0
-3@@ -4327,9 +4327,6 @@ int main(int argc, char **argv, char **envp)qemu_opts_del (icount_opts); } -/* clean up network at qemu process termination */ -atexit (&net_cleanup); -if (default_net) {QemuOptsList *net =qemu_find_opts ("net" );qemu_opts_set (net,NULL ,"type" ,"nic" , &error_abort);
vl.c int main(int argc, char **argv, char **envp) · line 4601
Quoted 9 lines
vl.c +3
-0@@ -4596,6 +4593,9 @@ int main(int argc, char **argv, char **envp)#ifdef CONFIG_TPM tpm_cleanup ();#endif + +/* vhost-user must be cleaned up before chardevs. */ +net_cleanup ();qemu_chr_cleanup ();return 0 ;
Patch does not seems to be applied on master. Which tree is this patch based?
Thanks
Quoted 27 lines · Jason Wang
Quoted 24 lines · Paolo Bonzini
Otherwise, vhost-user causes a use-after-free.
Signed-off-by Paolo Bonzini <[email protected]>--- vl.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)vl.c +0
-2@@ -4327,9 +4327,6 @@ int main(int argc, char **argv, char **envp)qemu_opts_del (icount_opts); } -/* clean up network at qemu process termination */ -atexit (&net_cleanup); - if (default_net) {QemuOptsList *net =qemu_find_opts ("net" );qemu_opts_set (net,NULL ,"type" ,"nic" , &error_abort);@@ -4596,6 +4593,9 @@ int main(int argc, char **argv, char **envp)#ifdef CONFIG_TPM tpm_cleanup ();#endif
Quoted 8 lines
vl.c int main(int argc, char **argv, char **envp) · line 4601
Quoted 5 lines
vl.c +3
-0+ +/* vhost-user must be cleaned up before chardevs. */ +net_cleanup ();qemu_chr_cleanup ();return 0 ;Patch does not seems to be applied on master. Which tree is this patch based?
It's applied on top of Marc-André's character device cleanup series.
Paolo
Quoted 35 lines · Paolo Bonzini
Quoted 25 lines · Jason Wang
Quoted 23 lines · Paolo Bonzini
Otherwise, vhost-user causes a use-after-free.
Signed-off-by Paolo Bonzini <[email protected]>--- vl.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)vl.c +0
-2@@ -4327,9 +4327,6 @@ int main(int argc, char **argv, char **envp)qemu_opts_del (icount_opts); } -/* clean up network at qemu process termination */ -atexit (&net_cleanup); - if (default_net) {QemuOptsList *net =qemu_find_opts ("net" );qemu_opts_set (net,NULL ,"type" ,"nic" , &error_abort);@@ -4596,6 +4593,9 @@ int main(int argc, char **argv, char **envp)#ifdef CONFIG_TPM tpm_cleanup ();Quoted 8 lines
vl.c int main(int argc, char **argv, char **envp) · line 4601
Quoted 6 lines
vl.c +3
-0#endif + +/* vhost-user must be cleaned up before chardevs. */ +net_cleanup ();qemu_chr_cleanup ();return 0 ;Patch does not seems to be applied on master. Which tree is this patch based?
Quoted 4 lines
It's applied on top of Marc-André's character device cleanup series.
Paolo
Ok, but looks like the issue we tried to solve with commit f30dbae63a46f23116715dff8d130c7d01ff02be will appear again?
Quoted 38 lines · Jason Wang
Quoted 35 lines · Paolo Bonzini
Quoted 33 lines · Jason Wang
Quoted 21 lines · Paolo Bonzini
Otherwise, vhost-user causes a use-after-free.
Signed-off-by Paolo Bonzini <[email protected]>--- vl.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)vl.c +0
-2@@ -4327,9 +4327,6 @@ int main(int argc, char **argv, char **envp)qemu_opts_del (icount_opts); } -/* clean up network at qemu process termination */ -atexit (&net_cleanup); - if (default_net) {QemuOptsList *net =qemu_find_opts ("net" );qemu_opts_set (net,NULL ,"type" ,"nic" , &error_abort);vl.c int main(int argc, char **argv, char **envp) · line 4600
Quoted 8 lines
vl.c +3
-0@@ -4596,6 +4593,9 @@ int main(int argc, char **argv, char **envp)#ifdef CONFIG_TPM tpm_cleanup ();#endif + +/* vhost-user must be cleaned up before chardevs. */ +net_cleanup ();qemu_chr_cleanup ();return 0 ;Patch does not seems to be applied on master. Which tree is this patch based?
Quoted 4 lines
Quoted 1 line
It's applied on top of Marc-André's character device cleanup series.
Ok, but looks like the issue we tried to solve with commit
f30dbae63a46f23116715dff8d130c7d01ff02bewill appear again?
You're right. :/
Marc-André, I think a possible solution is this:
1) add a Notifier to struct TAPState and register it with qemu_add_exit_notifier. The notifier, when called, invokes the down_script.
2) in tap_cleanup, invoke the down_script and unregister the notifier with qemu_remove_exit_notifier.
Can you implement this?
Paolo
Hi
----- Original Message -----
Quoted 50 lines · Jason Wang
Quoted 38 lines · Paolo Bonzini
Quoted 35 lines · Jason Wang
Quoted 33 lines · Paolo Bonzini
Quoted 21 lines
Otherwise, vhost-user causes a use-after-free.
Signed-off-by Paolo Bonzini <[email protected]>--- vl.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)vl.c +0
-2@@ -4327,9 +4327,6 @@ int main(int argc, char **argv, char **envp)qemu_opts_del (icount_opts); } -/* clean up network at qemu process termination */ -atexit (&net_cleanup); - if (default_net) {QemuOptsList *net =qemu_find_opts ("net" );qemu_opts_set (net,NULL ,"type" ,"nic" , &error_abort);vl.c int main(int argc, char **argv, char **envp) · line 4600
Quoted 8 lines
vl.c +3
-0@@ -4596,6 +4593,9 @@ int main(int argc, char **argv, char **envp)#ifdef CONFIG_TPM tpm_cleanup ();#endif + +/* vhost-user must be cleaned up before chardevs. */ +net_cleanup ();qemu_chr_cleanup ();return 0 ;Patch does not seems to be applied on master. Which tree is this patch based?
Quoted 4 lines
Quoted 1 line
It's applied on top of Marc-André's character device cleanup series.
Ok, but looks like the issue we tried to solve with commit
f30dbae63a46f23116715dff8d130c7d01ff02bewill appear again?You're right. :/
Marc-André, I think a possible solution is this:
Quoted 7 lines
1) add a Notifier to struct TAPState and register it with
qemu_add_exit_notifier. The notifier, when called, invokes thedown_script.2) in
tap_cleanup, invoke thedown_scriptand unregister the notifier withqemu_remove_exit_notifier.Can you implement this?
What if we register an exit notifier right before leaving main() ? (qemu_add_exit_notifier(&chr_cleanup_notifier))
So that qemu_chr_cleanup() is only invoked at the last time when doing main() exit?
Quoted 56 lines · Marc-André Lureau
Hi
----- Original Message -----
Quoted 53 lines · Jason Wang
Quoted 38 lines · Paolo Bonzini
Quoted 35 lines · Jason Wang
Quoted 33 lines · Paolo Bonzini
Quoted 21 lines
Otherwise, vhost-user causes a use-after-free.
Signed-off-by Paolo Bonzini <[email protected]>--- vl.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)vl.c +0
-2@@ -4327,9 +4327,6 @@ int main(int argc, char **argv, char **envp)qemu_opts_del (icount_opts); } -/* clean up network at qemu process termination */ -atexit (&net_cleanup); - if (default_net) {QemuOptsList *net =qemu_find_opts ("net" );qemu_opts_set (net,NULL ,"type" ,"nic" , &error_abort);vl.c int main(int argc, char **argv, char **envp) · line 4600
Quoted 8 lines
vl.c +3
-0@@ -4596,6 +4593,9 @@ int main(int argc, char **argv, char **envp)#ifdef CONFIG_TPM tpm_cleanup ();#endif + +/* vhost-user must be cleaned up before chardevs. */ +net_cleanup ();qemu_chr_cleanup ();return 0 ;Patch does not seems to be applied on master. Which tree is this patch based?
Quoted 4 lines
Quoted 1 line
It's applied on top of Marc-André's character device cleanup series.
Ok, but looks like the issue we tried to solve with commit
f30dbae63a46f23116715dff8d130c7d01ff02bewill appear again?You're right. :/
Marc-André, I think a possible solution is this:
1) add a Notifier to struct TAPState and register it with
qemu_add_exit_notifier. The notifier, when called, invokes thedown_script.
Quoted 6 lines
Quoted 4 lines
2) in
tap_cleanup, invoke thedown_scriptand unregister the notifier withqemu_remove_exit_notifier.Can you implement this?
What if we register an exit notifier right before leaving
main()? (qemu_add_exit_notifier(&chr_cleanup_notifier))
Exit notifiers are run with atexit (the difference is that you can remove them, which is exactly what we need here!). You would have the same issue as before, where you cannot rely on the order of execution.
The logic is:
1) main tears down objects in the "correct" order, which is net before char
2) if something wants to do cleanup at exit() time, they can register an exit notifier on creation and unregister it on cleanup. It can be TAPState, or I guess Unix socket chardevs could also do this and it would be nice. However, it's okay for me if you only change TAPState.
So an exit() does the bare minimum necessary cleanup, whereas a "quit" or SIGTERM brings down everything.
Thanks,
Paolo
Quoted 2 lines
So that
qemu_chr_cleanup()is only invoked at the last time when doingmain()exit?