aboutsummaryrefslogtreecommitdiffstats
path: root/virt/kvm
diff options
context:
space:
mode:
authorDarrick J. Wong <djwong@us.ibm.com>2009-10-14 19:21:00 -0400
committerMarcelo Tosatti <mtosatti@redhat.com>2009-10-16 11:30:26 -0400
commit0ea4ed8e948c30f88c824c973ee4b9529015fe65 (patch)
treeb7bbcbc50fda3290c3acbb6ca38bd1e4dd3f05c6 /virt/kvm
parent8a8365c560b8b631e0a2d1ac032fbca66a9645bc (diff)
KVM: Prevent kvm_init from corrupting debugfs structures
I'm seeing an oops condition when kvm-intel and kvm-amd are modprobe'd during boot (say on an Intel system) and then rmmod'd: # modprobe kvm-intel kvm_init() kvm_init_debug() kvm_arch_init() <-- stores debugfs dentries internally (success, etc) # modprobe kvm-amd kvm_init() kvm_init_debug() <-- second initialization clobbers kvm's internal pointers to dentries kvm_arch_init() kvm_exit_debug() <-- and frees them # rmmod kvm-intel kvm_exit() kvm_exit_debug() <-- double free of debugfs files! *BOOM* If execution gets to the end of kvm_init(), then the calling module has been established as the kvm provider. Move the debugfs initialization to the end of the function, and remove the now-unnecessary call to kvm_exit_debug() from the error path. That way we avoid trampling on the debugfs entries and freeing them twice. Cc: stable@kernel.org Signed-off-by: Darrick J. Wong <djwong@us.ibm.com> Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
Diffstat (limited to 'virt/kvm')
-rw-r--r--virt/kvm/kvm_main.c7
1 files changed, 3 insertions, 4 deletions
diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
index b7c78a403dc..7495ce34734 100644
--- a/virt/kvm/kvm_main.c
+++ b/virt/kvm/kvm_main.c
@@ -2717,8 +2717,6 @@ int kvm_init(void *opaque, unsigned int vcpu_size,
2717 int r; 2717 int r;
2718 int cpu; 2718 int cpu;
2719 2719
2720 kvm_init_debug();
2721
2722 r = kvm_arch_init(opaque); 2720 r = kvm_arch_init(opaque);
2723 if (r) 2721 if (r)
2724 goto out_fail; 2722 goto out_fail;
@@ -2785,6 +2783,8 @@ int kvm_init(void *opaque, unsigned int vcpu_size,
2785 kvm_preempt_ops.sched_in = kvm_sched_in; 2783 kvm_preempt_ops.sched_in = kvm_sched_in;
2786 kvm_preempt_ops.sched_out = kvm_sched_out; 2784 kvm_preempt_ops.sched_out = kvm_sched_out;
2787 2785
2786 kvm_init_debug();
2787
2788 return 0; 2788 return 0;
2789 2789
2790out_free: 2790out_free:
@@ -2807,7 +2807,6 @@ out_free_0:
2807out: 2807out:
2808 kvm_arch_exit(); 2808 kvm_arch_exit();
2809out_fail: 2809out_fail:
2810 kvm_exit_debug();
2811 return r; 2810 return r;
2812} 2811}
2813EXPORT_SYMBOL_GPL(kvm_init); 2812EXPORT_SYMBOL_GPL(kvm_init);
@@ -2815,6 +2814,7 @@ EXPORT_SYMBOL_GPL(kvm_init);
2815void kvm_exit(void) 2814void kvm_exit(void)
2816{ 2815{
2817 tracepoint_synchronize_unregister(); 2816 tracepoint_synchronize_unregister();
2817 kvm_exit_debug();
2818 misc_deregister(&kvm_dev); 2818 misc_deregister(&kvm_dev);
2819 kmem_cache_destroy(kvm_vcpu_cache); 2819 kmem_cache_destroy(kvm_vcpu_cache);
2820 sysdev_unregister(&kvm_sysdev); 2820 sysdev_unregister(&kvm_sysdev);
@@ -2824,7 +2824,6 @@ void kvm_exit(void)
2824 on_each_cpu(hardware_disable, NULL, 1); 2824 on_each_cpu(hardware_disable, NULL, 1);
2825 kvm_arch_hardware_unsetup(); 2825 kvm_arch_hardware_unsetup();
2826 kvm_arch_exit(); 2826 kvm_arch_exit();
2827 kvm_exit_debug();
2828 free_cpumask_var(cpus_hardware_enabled); 2827 free_cpumask_var(cpus_hardware_enabled);
2829 __free_page(bad_page); 2828 __free_page(bad_page);
2830} 2829}