@@ -1588,7 +1588,7 @@ static int check_kprobe_address_safe(struct kprobe *p,
15881588 }
15891589
15901590 /* Get module refcount and reject __init functions for loaded modules. */
1591- if (* probed_mod ) {
1591+ if (IS_ENABLED ( CONFIG_MODULES ) && * probed_mod ) {
15921592 /*
15931593 * We must hold a refcount of the probed module while updating
15941594 * its code to prohibit unexpected unloading.
@@ -1603,12 +1603,13 @@ static int check_kprobe_address_safe(struct kprobe *p,
16031603 * kprobes in there.
16041604 */
16051605 if (within_module_init ((unsigned long )p -> addr , * probed_mod ) &&
1606- (* probed_mod )-> state != MODULE_STATE_COMING ) {
1606+ ! module_is_coming (* probed_mod )) {
16071607 module_put (* probed_mod );
16081608 * probed_mod = NULL ;
16091609 ret = - ENOENT ;
16101610 }
16111611 }
1612+
16121613out :
16131614 preempt_enable ();
16141615 jump_label_unlock ();
@@ -2488,24 +2489,6 @@ int kprobe_add_area_blacklist(unsigned long start, unsigned long end)
24882489 return 0 ;
24892490}
24902491
2491- /* Remove all symbols in given area from kprobe blacklist */
2492- static void kprobe_remove_area_blacklist (unsigned long start , unsigned long end )
2493- {
2494- struct kprobe_blacklist_entry * ent , * n ;
2495-
2496- list_for_each_entry_safe (ent , n , & kprobe_blacklist , list ) {
2497- if (ent -> start_addr < start || ent -> start_addr >= end )
2498- continue ;
2499- list_del (& ent -> list );
2500- kfree (ent );
2501- }
2502- }
2503-
2504- static void kprobe_remove_ksym_blacklist (unsigned long entry )
2505- {
2506- kprobe_remove_area_blacklist (entry , entry + 1 );
2507- }
2508-
25092492int __weak arch_kprobe_get_kallsym (unsigned int * symnum , unsigned long * value ,
25102493 char * type , char * sym )
25112494{
@@ -2570,6 +2553,25 @@ static int __init populate_kprobe_blacklist(unsigned long *start,
25702553 return ret ? : arch_populate_kprobe_blacklist ();
25712554}
25722555
2556+ #ifdef CONFIG_MODULES
2557+ /* Remove all symbols in given area from kprobe blacklist */
2558+ static void kprobe_remove_area_blacklist (unsigned long start , unsigned long end )
2559+ {
2560+ struct kprobe_blacklist_entry * ent , * n ;
2561+
2562+ list_for_each_entry_safe (ent , n , & kprobe_blacklist , list ) {
2563+ if (ent -> start_addr < start || ent -> start_addr >= end )
2564+ continue ;
2565+ list_del (& ent -> list );
2566+ kfree (ent );
2567+ }
2568+ }
2569+
2570+ static void kprobe_remove_ksym_blacklist (unsigned long entry )
2571+ {
2572+ kprobe_remove_area_blacklist (entry , entry + 1 );
2573+ }
2574+
25732575static void add_module_kprobe_blacklist (struct module * mod )
25742576{
25752577 unsigned long start , end ;
@@ -2672,6 +2674,17 @@ static struct notifier_block kprobe_module_nb = {
26722674 .priority = 0
26732675};
26742676
2677+ static int kprobe_register_module_notifier (void )
2678+ {
2679+ return register_module_notifier (& kprobe_module_nb );
2680+ }
2681+ #else
2682+ static int kprobe_register_module_notifier (void )
2683+ {
2684+ return 0 ;
2685+ }
2686+ #endif /* CONFIG_MODULES */
2687+
26752688void kprobe_free_init_mem (void )
26762689{
26772690 void * start = (void * )(& __init_begin );
@@ -2731,7 +2744,7 @@ static int __init init_kprobes(void)
27312744 if (!err )
27322745 err = register_die_notifier (& kprobe_exceptions_nb );
27332746 if (!err )
2734- err = register_module_notifier ( & kprobe_module_nb );
2747+ err = kprobe_register_module_notifier ( );
27352748
27362749 kprobes_initialized = (err == 0 );
27372750 kprobe_sysctls_init ();
0 commit comments