@@ -538,7 +538,7 @@ static void setup_modinfo_##field(struct module *mod, const char *s) \
538
538
{ \
539
539
mod->field = kstrdup(s, GFP_KERNEL); \
540
540
} \
541
- static ssize_t show_modinfo_##field(struct module_attribute *mattr, \
541
+ static ssize_t show_modinfo_##field(const struct module_attribute *mattr, \
542
542
struct module_kobject *mk, char *buffer) \
543
543
{ \
544
544
return scnprintf(buffer, PAGE_SIZE, "%s\n", mk->mod->field); \
@@ -552,7 +552,7 @@ static void free_modinfo_##field(struct module *mod) \
552
552
kfree(mod->field); \
553
553
mod->field = NULL; \
554
554
} \
555
- static struct module_attribute modinfo_##field = { \
555
+ static const struct module_attribute modinfo_##field = { \
556
556
.attr = { .name = __stringify(field), .mode = 0444 }, \
557
557
.show = show_modinfo_##field, \
558
558
.setup = setup_modinfo_##field, \
@@ -842,13 +842,13 @@ void symbol_put_addr(void *addr)
842
842
}
843
843
EXPORT_SYMBOL_GPL (symbol_put_addr );
844
844
845
- static ssize_t show_refcnt (struct module_attribute * mattr ,
845
+ static ssize_t show_refcnt (const struct module_attribute * mattr ,
846
846
struct module_kobject * mk , char * buffer )
847
847
{
848
848
return sprintf (buffer , "%i\n" , module_refcount (mk -> mod ));
849
849
}
850
850
851
- static struct module_attribute modinfo_refcnt =
851
+ static const struct module_attribute modinfo_refcnt =
852
852
__ATTR (refcnt , 0444 , show_refcnt , NULL );
853
853
854
854
void __module_get (struct module * module )
@@ -917,7 +917,7 @@ size_t module_flags_taint(unsigned long taints, char *buf)
917
917
return l ;
918
918
}
919
919
920
- static ssize_t show_initstate (struct module_attribute * mattr ,
920
+ static ssize_t show_initstate (const struct module_attribute * mattr ,
921
921
struct module_kobject * mk , char * buffer )
922
922
{
923
923
const char * state = "unknown" ;
@@ -938,10 +938,10 @@ static ssize_t show_initstate(struct module_attribute *mattr,
938
938
return sprintf (buffer , "%s\n" , state );
939
939
}
940
940
941
- static struct module_attribute modinfo_initstate =
941
+ static const struct module_attribute modinfo_initstate =
942
942
__ATTR (initstate , 0444 , show_initstate , NULL );
943
943
944
- static ssize_t store_uevent (struct module_attribute * mattr ,
944
+ static ssize_t store_uevent (const struct module_attribute * mattr ,
945
945
struct module_kobject * mk ,
946
946
const char * buffer , size_t count )
947
947
{
@@ -951,10 +951,10 @@ static ssize_t store_uevent(struct module_attribute *mattr,
951
951
return rc ? rc : count ;
952
952
}
953
953
954
- struct module_attribute module_uevent =
954
+ const struct module_attribute module_uevent =
955
955
__ATTR (uevent , 0200 , NULL , store_uevent );
956
956
957
- static ssize_t show_coresize (struct module_attribute * mattr ,
957
+ static ssize_t show_coresize (const struct module_attribute * mattr ,
958
958
struct module_kobject * mk , char * buffer )
959
959
{
960
960
unsigned int size = mk -> mod -> mem [MOD_TEXT ].size ;
@@ -966,11 +966,11 @@ static ssize_t show_coresize(struct module_attribute *mattr,
966
966
return sprintf (buffer , "%u\n" , size );
967
967
}
968
968
969
- static struct module_attribute modinfo_coresize =
969
+ static const struct module_attribute modinfo_coresize =
970
970
__ATTR (coresize , 0444 , show_coresize , NULL );
971
971
972
972
#ifdef CONFIG_ARCH_WANTS_MODULES_DATA_IN_VMALLOC
973
- static ssize_t show_datasize (struct module_attribute * mattr ,
973
+ static ssize_t show_datasize (const struct module_attribute * mattr ,
974
974
struct module_kobject * mk , char * buffer )
975
975
{
976
976
unsigned int size = 0 ;
@@ -980,11 +980,11 @@ static ssize_t show_datasize(struct module_attribute *mattr,
980
980
return sprintf (buffer , "%u\n" , size );
981
981
}
982
982
983
- static struct module_attribute modinfo_datasize =
983
+ static const struct module_attribute modinfo_datasize =
984
984
__ATTR (datasize , 0444 , show_datasize , NULL );
985
985
#endif
986
986
987
- static ssize_t show_initsize (struct module_attribute * mattr ,
987
+ static ssize_t show_initsize (const struct module_attribute * mattr ,
988
988
struct module_kobject * mk , char * buffer )
989
989
{
990
990
unsigned int size = 0 ;
@@ -994,10 +994,10 @@ static ssize_t show_initsize(struct module_attribute *mattr,
994
994
return sprintf (buffer , "%u\n" , size );
995
995
}
996
996
997
- static struct module_attribute modinfo_initsize =
997
+ static const struct module_attribute modinfo_initsize =
998
998
__ATTR (initsize , 0444 , show_initsize , NULL );
999
999
1000
- static ssize_t show_taint (struct module_attribute * mattr ,
1000
+ static ssize_t show_taint (const struct module_attribute * mattr ,
1001
1001
struct module_kobject * mk , char * buffer )
1002
1002
{
1003
1003
size_t l ;
@@ -1007,10 +1007,10 @@ static ssize_t show_taint(struct module_attribute *mattr,
1007
1007
return l ;
1008
1008
}
1009
1009
1010
- static struct module_attribute modinfo_taint =
1010
+ static const struct module_attribute modinfo_taint =
1011
1011
__ATTR (taint , 0444 , show_taint , NULL );
1012
1012
1013
- struct module_attribute * modinfo_attrs [] = {
1013
+ const struct module_attribute * const modinfo_attrs [] = {
1014
1014
& module_uevent ,
1015
1015
& modinfo_version ,
1016
1016
& modinfo_srcversion ,
@@ -1027,7 +1027,7 @@ struct module_attribute *modinfo_attrs[] = {
1027
1027
NULL ,
1028
1028
};
1029
1029
1030
- size_t modinfo_attrs_count = ARRAY_SIZE (modinfo_attrs );
1030
+ const size_t modinfo_attrs_count = ARRAY_SIZE (modinfo_attrs );
1031
1031
1032
1032
static const char vermagic [] = VERMAGIC_STRING ;
1033
1033
@@ -1681,7 +1681,7 @@ static void module_license_taint_check(struct module *mod, const char *license)
1681
1681
1682
1682
static void setup_modinfo (struct module * mod , struct load_info * info )
1683
1683
{
1684
- struct module_attribute * attr ;
1684
+ const struct module_attribute * attr ;
1685
1685
int i ;
1686
1686
1687
1687
for (i = 0 ; (attr = modinfo_attrs [i ]); i ++ ) {
@@ -1692,7 +1692,7 @@ static void setup_modinfo(struct module *mod, struct load_info *info)
1692
1692
1693
1693
static void free_modinfo (struct module * mod )
1694
1694
{
1695
- struct module_attribute * attr ;
1695
+ const struct module_attribute * attr ;
1696
1696
int i ;
1697
1697
1698
1698
for (i = 0 ; (attr = modinfo_attrs [i ]); i ++ ) {
@@ -2332,11 +2332,20 @@ static int rewrite_section_headers(struct load_info *info, int flags)
2332
2332
return 0 ;
2333
2333
}
2334
2334
2335
+ static const char * const module_license_offenders [] = {
2336
+ /* driverloader was caught wrongly pretending to be under GPL */
2337
+ "driverloader" ,
2338
+
2339
+ /* lve claims to be GPL but upstream won't provide source */
2340
+ "lve" ,
2341
+ };
2342
+
2335
2343
/*
2336
2344
* These calls taint the kernel depending certain module circumstances */
2337
2345
static void module_augment_kernel_taints (struct module * mod , struct load_info * info )
2338
2346
{
2339
2347
int prev_taint = test_taint (TAINT_PROPRIETARY_MODULE );
2348
+ size_t i ;
2340
2349
2341
2350
if (!get_modinfo (info , "intree" )) {
2342
2351
if (!test_taint (TAINT_OOT_MODULE ))
@@ -2385,15 +2394,11 @@ static void module_augment_kernel_taints(struct module *mod, struct load_info *i
2385
2394
if (strcmp (mod -> name , "ndiswrapper" ) == 0 )
2386
2395
add_taint (TAINT_PROPRIETARY_MODULE , LOCKDEP_NOW_UNRELIABLE );
2387
2396
2388
- /* driverloader was caught wrongly pretending to be under GPL */
2389
- if (strcmp (mod -> name , "driverloader" ) == 0 )
2390
- add_taint_module (mod , TAINT_PROPRIETARY_MODULE ,
2391
- LOCKDEP_NOW_UNRELIABLE );
2392
-
2393
- /* lve claims to be GPL but upstream won't provide source */
2394
- if (strcmp (mod -> name , "lve" ) == 0 )
2395
- add_taint_module (mod , TAINT_PROPRIETARY_MODULE ,
2396
- LOCKDEP_NOW_UNRELIABLE );
2397
+ for (i = 0 ; i < ARRAY_SIZE (module_license_offenders ); ++ i ) {
2398
+ if (strcmp (mod -> name , module_license_offenders [i ]) == 0 )
2399
+ add_taint_module (mod , TAINT_PROPRIETARY_MODULE ,
2400
+ LOCKDEP_NOW_UNRELIABLE );
2401
+ }
2397
2402
2398
2403
if (!prev_taint && test_taint (TAINT_PROPRIETARY_MODULE ))
2399
2404
pr_warn ("%s: module license taints kernel.\n" , mod -> name );
@@ -2948,9 +2953,12 @@ static noinline int do_init_module(struct module *mod)
2948
2953
/* Switch to core kallsyms now init is done: kallsyms may be walking! */
2949
2954
rcu_assign_pointer (mod -> kallsyms , & mod -> core_kallsyms );
2950
2955
#endif
2951
- ret = module_enable_rodata_ro (mod , true );
2956
+ ret = module_enable_rodata_ro_after_init (mod );
2952
2957
if (ret )
2953
- goto fail_mutex_unlock ;
2958
+ pr_warn ("%s: module_enable_rodata_ro_after_init() returned %d, "
2959
+ "ro_after_init data might still be writable\n" ,
2960
+ mod -> name , ret );
2961
+
2954
2962
mod_tree_remove_init (mod );
2955
2963
module_arch_freeing_init (mod );
2956
2964
for_class_mod_mem_type (type , init ) {
@@ -2989,8 +2997,6 @@ static noinline int do_init_module(struct module *mod)
2989
2997
2990
2998
return 0 ;
2991
2999
2992
- fail_mutex_unlock :
2993
- mutex_unlock (& module_mutex );
2994
3000
fail_free_freeinit :
2995
3001
kfree (freeinit );
2996
3002
fail :
@@ -3118,7 +3124,7 @@ static int complete_formation(struct module *mod, struct load_info *info)
3118
3124
module_bug_finalize (info -> hdr , info -> sechdrs , mod );
3119
3125
module_cfi_finalize (info -> hdr , info -> sechdrs , mod );
3120
3126
3121
- err = module_enable_rodata_ro (mod , false );
3127
+ err = module_enable_rodata_ro (mod );
3122
3128
if (err )
3123
3129
goto out_strict_rwx ;
3124
3130
err = module_enable_data_nx (mod );
0 commit comments