KVM: Prevent kvm_init from corrupting debugfs structures
commit6fa5a4d48a5cb7aa452cc34120f9122301ec8c93
authorDarrick J. Wong <djwong@us.ibm.com>
Fri, 6 Nov 2009 14:00:51 +0000 (6 12:00 -0200)
committerGreg Kroah-Hartman <gregkh@suse.de>
Tue, 10 Nov 2009 00:23:10 +0000 (9 16:23 -0800)
tree43190636e41db59b1cbdaeb6091a15a02c0ef85e
parent77608cc64e305111725bbefe7d238d9f6da38c5d
KVM: Prevent kvm_init from corrupting debugfs structures

commit: 0ea4ed8e948c30f88c824c973ee4b9529015fe65 upstream

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>
Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
virt/kvm/kvm_main.c