kvm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] kvm: Prevent kvm_init from corrupting debugfs structures
@ 2009-10-14 23:21 Darrick J. Wong
  2009-10-15  7:12 ` Avi Kivity
  2009-10-15 16:04 ` Marcelo Tosatti
  0 siblings, 2 replies; 3+ messages in thread
From: Darrick J. Wong @ 2009-10-14 23:21 UTC (permalink / raw)
  To: Avi Kivity, Marcelo Tosatti; +Cc: linux-kernel, kvm

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.

Signed-off-by: Darrick J. Wong <djwong@us.ibm.com>
---

 virt/kvm/kvm_main.c |    7 +++----
 1 files changed, 3 insertions(+), 4 deletions(-)


diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
index b7c78a4..7495ce3 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,
 	int r;
 	int cpu;
 
-	kvm_init_debug();
-
 	r = kvm_arch_init(opaque);
 	if (r)
 		goto out_fail;
@@ -2785,6 +2783,8 @@ int kvm_init(void *opaque, unsigned int vcpu_size,
 	kvm_preempt_ops.sched_in = kvm_sched_in;
 	kvm_preempt_ops.sched_out = kvm_sched_out;
 
+	kvm_init_debug();
+
 	return 0;
 
 out_free:
@@ -2807,7 +2807,6 @@ out_free_0:
 out:
 	kvm_arch_exit();
 out_fail:
-	kvm_exit_debug();
 	return r;
 }
 EXPORT_SYMBOL_GPL(kvm_init);
@@ -2815,6 +2814,7 @@ EXPORT_SYMBOL_GPL(kvm_init);
 void kvm_exit(void)
 {
 	tracepoint_synchronize_unregister();
+	kvm_exit_debug();
 	misc_deregister(&kvm_dev);
 	kmem_cache_destroy(kvm_vcpu_cache);
 	sysdev_unregister(&kvm_sysdev);
@@ -2824,7 +2824,6 @@ void kvm_exit(void)
 	on_each_cpu(hardware_disable, NULL, 1);
 	kvm_arch_hardware_unsetup();
 	kvm_arch_exit();
-	kvm_exit_debug();
 	free_cpumask_var(cpus_hardware_enabled);
 	__free_page(bad_page);
 }

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] kvm: Prevent kvm_init from corrupting debugfs structures
  2009-10-14 23:21 [PATCH] kvm: Prevent kvm_init from corrupting debugfs structures Darrick J. Wong
@ 2009-10-15  7:12 ` Avi Kivity
  2009-10-15 16:04 ` Marcelo Tosatti
  1 sibling, 0 replies; 3+ messages in thread
From: Avi Kivity @ 2009-10-15  7:12 UTC (permalink / raw)
  To: djwong; +Cc: Marcelo Tosatti, linux-kernel, kvm

On 10/15/2009 08:21 AM, Darrick J. Wong wrote:
> 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.
>
>    

Looks good.

-- 
I have a truly marvellous patch that fixes the bug which this
signature is too narrow to contain.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] kvm: Prevent kvm_init from corrupting debugfs structures
  2009-10-14 23:21 [PATCH] kvm: Prevent kvm_init from corrupting debugfs structures Darrick J. Wong
  2009-10-15  7:12 ` Avi Kivity
@ 2009-10-15 16:04 ` Marcelo Tosatti
  1 sibling, 0 replies; 3+ messages in thread
From: Marcelo Tosatti @ 2009-10-15 16:04 UTC (permalink / raw)
  To: Darrick J. Wong; +Cc: Avi Kivity, linux-kernel, kvm

On Wed, Oct 14, 2009 at 04:21:00PM -0700, Darrick J. Wong wrote:
> 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.
> 
> Signed-off-by: Darrick J. Wong <djwong@us.ibm.com>

Applied, thanks.


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2009-10-15 16:24 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-10-14 23:21 [PATCH] kvm: Prevent kvm_init from corrupting debugfs structures Darrick J. Wong
2009-10-15  7:12 ` Avi Kivity
2009-10-15 16:04 ` Marcelo Tosatti

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).