Skip to contentSkip to conversation

Prevent trace call into unloaded module text

PATCH Applied Wu Fengguang 2 participants 5 messages Nov 24, 2008 – Nov 27, 2008 KVM

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Prevent trace call into unloaded module text

Add marker_synchronize_unregister() before module unloading. This prevents possible trace calls into unloaded module text.

---

virt/kvm/kvm_main.c +1 -0
index a87f45e..64f38b3 100644
@@ -2102,5 +2102,6 @@ void kvm_exit(void)
 	kvm_arch_exit();
 	kvm_exit_debug();
 	__free_page(bad_page);
+	marker_synchronize_unregister();
 }
 EXPORT_SYMBOL_GPL(kvm_exit);
#1 lore raw
Quoted 11 lines · Wu Fengguang

Add marker_synchronize_unregister() before module unloading. This prevents possible trace calls into unloaded module text.

---

virt/kvm/kvm_main.c +0 -0
index a87f45e..64f38b3 100644

virt/kvm/kvm_main.c void kvm_exit(void) · line 2107

Quoted 6 lines
virt/kvm/kvm_main.c +1 -0
@@ -2102,5 +2102,6 @@ void kvm_exit(void)
 	kvm_arch_exit();
 	kvm_exit_debug();
 	__free_page(bad_page);
+	marker_synchronize_unregister();
 }
 EXPORT_SYMBOL_GPL(kvm_exit);

What about kvm-intel.ko and kvm-amd.ko? They also contain markers.

(and, why doesn't module unload do this automatically?)

Signature · 1 line
error compiling committee.c: too many arguments to function
#2 lore raw
Quoted 4 lines · Avi Kivity
Quoted 3 lines · Wu Fengguang

Add marker_synchronize_unregister() before module unloading. This prevents possible trace calls into unloaded module text.

Quoted 16 lines
Quoted 8 lines

---

virt/kvm/kvm_main.c +0 -0
index a87f45e..64f38b3 100644

virt/kvm/kvm_main.c void kvm_exit(void) · line 2107

Quoted 6 lines
virt/kvm/kvm_main.c +1 -0
@@ -2102,5 +2102,6 @@ void kvm_exit(void)
 	kvm_arch_exit();
 	kvm_exit_debug();
 	__free_page(bad_page);
+	marker_synchronize_unregister();
 }
 EXPORT_SYMBOL_GPL(kvm_exit);

What about kvm-intel.ko and kvm-amd.ko? They also contain markers.

vmx_exit and svm_exit() all calls into kvm_exit(), so they have been handled in a common way.

Quoted 1 line

(and, why doesn't module unload do this automatically?)

Maybe most modules don't need it for now?

Thanks,
Fengguang

#3 lore raw
Quoted 22 lines · Wu Fengguang
Quoted 4 lines · Avi Kivity
Quoted 3 lines · Wu Fengguang

Add marker_synchronize_unregister() before module unloading. This prevents possible trace calls into unloaded module text.

Quoted 16 lines
Quoted 8 lines

---

virt/kvm/kvm_main.c +0 -0
index a87f45e..64f38b3 100644

virt/kvm/kvm_main.c void kvm_exit(void) · line 2107

Quoted 6 lines
virt/kvm/kvm_main.c +1 -0
@@ -2102,5 +2102,6 @@ void kvm_exit(void)
 	kvm_arch_exit();
 	kvm_exit_debug();
 	__free_page(bad_page);
+	marker_synchronize_unregister();
 }
 EXPORT_SYMBOL_GPL(kvm_exit);

What about kvm-intel.ko and kvm-amd.ko? They also contain markers.

Quoted 6 lines

vmx_exit and svm_exit() all calls into kvm_exit(), so they have been handled in a common way.

Quoted 1 line

(and, why doesn't module unload do this automatically?)

Maybe most modules don't need it for now?

OK I got a better answer: because marker_synchronize_unregister() must be called after marker_probe_unregister() calls and the tear down of any private data the trace functions rely on. So there are no automatic way.

Below is the updated patch.

Thanks,
Fengguang
---
Prevent trace call into torn down text or data

Add marker_synchronize_unregister() immediately after probe unregisters. This prevents possible trace calls into unloaded module text, or the trace functions accessing invalidated data.

---

virt/kvm/kvm_trace.c +1 -0
index 41dcc84..f598744 100644
@@ -252,6 +252,7 @@ void kvm_trace_cleanup(void)
 			struct kvm_trace_probe *p = &kvm_trace_probes[i];
 			marker_probe_unregister(p->name, p->probe_func, p);
 		}
+		marker_synchronize_unregister();
 
 		relay_close(kt->rchan);
 		debugfs_remove(kt->lost_file);
Applied
#4 lore raw
Quoted 2 lines · Wu Fengguang

Below is the updated patch.

Applied, thanks.

Signature · 1 line
error compiling committee.c: too many arguments to function