Skip to content

Commit 41bfad5

Browse files
committed
Merge tag 'modules-6.14-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/modules/linux
Pull modules updates from Petr Pavlu: - Sign modules with sha512 instead of sha1 by default - Don't fail module loading when failing to set the ro_after_init section read-only - Constify 'struct module_attribute' - Cleanups and preparation for const struct bin_attribute - Put known GPL offenders in an array - Extend the preempt disabled section in dereference_symbol_descriptor() * tag 'modules-6.14-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/modules/linux: module: sign with sha512 instead of sha1 by default module: Don't fail module loading when setting ro_after_init section RO failed module: Split module_enable_rodata_ro() module: sysfs: Use const 'struct bin_attribute' module: sysfs: Add notes attributes through attribute_group module: sysfs: Simplify section attribute allocation module: sysfs: Drop 'struct module_sect_attr' module: sysfs: Drop member 'module_sect_attr::address' module: sysfs: Drop member 'module_sect_attrs::nsections' module: Constify 'struct module_attribute' module: Handle 'struct module_version_attribute' as const params: Prepare for 'const struct module_attribute *' module: Put known GPL offenders in an array module: Extend the preempt disabled section in dereference_symbol_descriptor().
2 parents 40648d2 + f3b9354 commit 41bfad5

File tree

8 files changed

+128
-121
lines changed

8 files changed

+128
-121
lines changed

include/linux/kallsyms.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,10 @@ static inline void *dereference_symbol_descriptor(void *ptr)
5757

5858
preempt_disable();
5959
mod = __module_address((unsigned long)ptr);
60-
preempt_enable();
6160

6261
if (mod)
6362
ptr = dereference_module_function_descriptor(mod, ptr);
63+
preempt_enable();
6464
#endif
6565
return ptr;
6666
}

include/linux/module.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,9 @@ struct module_kobject {
5252

5353
struct module_attribute {
5454
struct attribute attr;
55-
ssize_t (*show)(struct module_attribute *, struct module_kobject *,
55+
ssize_t (*show)(const struct module_attribute *, struct module_kobject *,
5656
char *);
57-
ssize_t (*store)(struct module_attribute *, struct module_kobject *,
57+
ssize_t (*store)(const struct module_attribute *, struct module_kobject *,
5858
const char *, size_t count);
5959
void (*setup)(struct module *, const char *);
6060
int (*test)(struct module *);
@@ -67,10 +67,10 @@ struct module_version_attribute {
6767
const char *version;
6868
};
6969

70-
extern ssize_t __modver_version_show(struct module_attribute *,
70+
extern ssize_t __modver_version_show(const struct module_attribute *,
7171
struct module_kobject *, char *);
7272

73-
extern struct module_attribute module_uevent;
73+
extern const struct module_attribute module_uevent;
7474

7575
/* These are either module local, or the kernel's dummy ones. */
7676
extern int init_module(void);
@@ -275,7 +275,7 @@ extern typeof(name) __mod_device_table__##type##__##name \
275275
#else
276276
#define MODULE_VERSION(_version) \
277277
MODULE_INFO(version, _version); \
278-
static struct module_version_attribute __modver_attr \
278+
static const struct module_version_attribute __modver_attr \
279279
__used __section("__modver") \
280280
__aligned(__alignof__(struct module_version_attribute)) \
281281
= { \

kernel/module/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,7 @@ comment "Do not forget to sign required modules with scripts/sign-file"
231231
choice
232232
prompt "Hash algorithm to sign modules"
233233
depends on MODULE_SIG || IMA_APPRAISE_MODSIG
234+
default MODULE_SIG_SHA512
234235
help
235236
This determines which sort of hashing algorithm will be used during
236237
signature generation. This algorithm _must_ be built into the kernel

kernel/module/internal.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ struct kernel_symbol {
4747
extern struct mutex module_mutex;
4848
extern struct list_head modules;
4949

50-
extern struct module_attribute *modinfo_attrs[];
51-
extern size_t modinfo_attrs_count;
50+
extern const struct module_attribute *const modinfo_attrs[];
51+
extern const size_t modinfo_attrs_count;
5252

5353
/* Provided by the linker */
5454
extern const struct kernel_symbol __start___ksymtab[];
@@ -327,7 +327,8 @@ static inline struct module *mod_find(unsigned long addr, struct mod_tree_root *
327327
}
328328
#endif /* CONFIG_MODULES_TREE_LOOKUP */
329329

330-
int module_enable_rodata_ro(const struct module *mod, bool after_init);
330+
int module_enable_rodata_ro(const struct module *mod);
331+
int module_enable_rodata_ro_after_init(const struct module *mod);
331332
int module_enable_data_nx(const struct module *mod);
332333
int module_enable_text_rox(const struct module *mod);
333334
int module_enforce_rwx_sections(Elf_Ehdr *hdr, Elf_Shdr *sechdrs,

kernel/module/main.c

Lines changed: 40 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -538,7 +538,7 @@ static void setup_modinfo_##field(struct module *mod, const char *s) \
538538
{ \
539539
mod->field = kstrdup(s, GFP_KERNEL); \
540540
} \
541-
static ssize_t show_modinfo_##field(struct module_attribute *mattr, \
541+
static ssize_t show_modinfo_##field(const struct module_attribute *mattr, \
542542
struct module_kobject *mk, char *buffer) \
543543
{ \
544544
return scnprintf(buffer, PAGE_SIZE, "%s\n", mk->mod->field); \
@@ -552,7 +552,7 @@ static void free_modinfo_##field(struct module *mod) \
552552
kfree(mod->field); \
553553
mod->field = NULL; \
554554
} \
555-
static struct module_attribute modinfo_##field = { \
555+
static const struct module_attribute modinfo_##field = { \
556556
.attr = { .name = __stringify(field), .mode = 0444 }, \
557557
.show = show_modinfo_##field, \
558558
.setup = setup_modinfo_##field, \
@@ -842,13 +842,13 @@ void symbol_put_addr(void *addr)
842842
}
843843
EXPORT_SYMBOL_GPL(symbol_put_addr);
844844

845-
static ssize_t show_refcnt(struct module_attribute *mattr,
845+
static ssize_t show_refcnt(const struct module_attribute *mattr,
846846
struct module_kobject *mk, char *buffer)
847847
{
848848
return sprintf(buffer, "%i\n", module_refcount(mk->mod));
849849
}
850850

851-
static struct module_attribute modinfo_refcnt =
851+
static const struct module_attribute modinfo_refcnt =
852852
__ATTR(refcnt, 0444, show_refcnt, NULL);
853853

854854
void __module_get(struct module *module)
@@ -917,7 +917,7 @@ size_t module_flags_taint(unsigned long taints, char *buf)
917917
return l;
918918
}
919919

920-
static ssize_t show_initstate(struct module_attribute *mattr,
920+
static ssize_t show_initstate(const struct module_attribute *mattr,
921921
struct module_kobject *mk, char *buffer)
922922
{
923923
const char *state = "unknown";
@@ -938,10 +938,10 @@ static ssize_t show_initstate(struct module_attribute *mattr,
938938
return sprintf(buffer, "%s\n", state);
939939
}
940940

941-
static struct module_attribute modinfo_initstate =
941+
static const struct module_attribute modinfo_initstate =
942942
__ATTR(initstate, 0444, show_initstate, NULL);
943943

944-
static ssize_t store_uevent(struct module_attribute *mattr,
944+
static ssize_t store_uevent(const struct module_attribute *mattr,
945945
struct module_kobject *mk,
946946
const char *buffer, size_t count)
947947
{
@@ -951,10 +951,10 @@ static ssize_t store_uevent(struct module_attribute *mattr,
951951
return rc ? rc : count;
952952
}
953953

954-
struct module_attribute module_uevent =
954+
const struct module_attribute module_uevent =
955955
__ATTR(uevent, 0200, NULL, store_uevent);
956956

957-
static ssize_t show_coresize(struct module_attribute *mattr,
957+
static ssize_t show_coresize(const struct module_attribute *mattr,
958958
struct module_kobject *mk, char *buffer)
959959
{
960960
unsigned int size = mk->mod->mem[MOD_TEXT].size;
@@ -966,11 +966,11 @@ static ssize_t show_coresize(struct module_attribute *mattr,
966966
return sprintf(buffer, "%u\n", size);
967967
}
968968

969-
static struct module_attribute modinfo_coresize =
969+
static const struct module_attribute modinfo_coresize =
970970
__ATTR(coresize, 0444, show_coresize, NULL);
971971

972972
#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,
974974
struct module_kobject *mk, char *buffer)
975975
{
976976
unsigned int size = 0;
@@ -980,11 +980,11 @@ static ssize_t show_datasize(struct module_attribute *mattr,
980980
return sprintf(buffer, "%u\n", size);
981981
}
982982

983-
static struct module_attribute modinfo_datasize =
983+
static const struct module_attribute modinfo_datasize =
984984
__ATTR(datasize, 0444, show_datasize, NULL);
985985
#endif
986986

987-
static ssize_t show_initsize(struct module_attribute *mattr,
987+
static ssize_t show_initsize(const struct module_attribute *mattr,
988988
struct module_kobject *mk, char *buffer)
989989
{
990990
unsigned int size = 0;
@@ -994,10 +994,10 @@ static ssize_t show_initsize(struct module_attribute *mattr,
994994
return sprintf(buffer, "%u\n", size);
995995
}
996996

997-
static struct module_attribute modinfo_initsize =
997+
static const struct module_attribute modinfo_initsize =
998998
__ATTR(initsize, 0444, show_initsize, NULL);
999999

1000-
static ssize_t show_taint(struct module_attribute *mattr,
1000+
static ssize_t show_taint(const struct module_attribute *mattr,
10011001
struct module_kobject *mk, char *buffer)
10021002
{
10031003
size_t l;
@@ -1007,10 +1007,10 @@ static ssize_t show_taint(struct module_attribute *mattr,
10071007
return l;
10081008
}
10091009

1010-
static struct module_attribute modinfo_taint =
1010+
static const struct module_attribute modinfo_taint =
10111011
__ATTR(taint, 0444, show_taint, NULL);
10121012

1013-
struct module_attribute *modinfo_attrs[] = {
1013+
const struct module_attribute *const modinfo_attrs[] = {
10141014
&module_uevent,
10151015
&modinfo_version,
10161016
&modinfo_srcversion,
@@ -1027,7 +1027,7 @@ struct module_attribute *modinfo_attrs[] = {
10271027
NULL,
10281028
};
10291029

1030-
size_t modinfo_attrs_count = ARRAY_SIZE(modinfo_attrs);
1030+
const size_t modinfo_attrs_count = ARRAY_SIZE(modinfo_attrs);
10311031

10321032
static const char vermagic[] = VERMAGIC_STRING;
10331033

@@ -1681,7 +1681,7 @@ static void module_license_taint_check(struct module *mod, const char *license)
16811681

16821682
static void setup_modinfo(struct module *mod, struct load_info *info)
16831683
{
1684-
struct module_attribute *attr;
1684+
const struct module_attribute *attr;
16851685
int i;
16861686

16871687
for (i = 0; (attr = modinfo_attrs[i]); i++) {
@@ -1692,7 +1692,7 @@ static void setup_modinfo(struct module *mod, struct load_info *info)
16921692

16931693
static void free_modinfo(struct module *mod)
16941694
{
1695-
struct module_attribute *attr;
1695+
const struct module_attribute *attr;
16961696
int i;
16971697

16981698
for (i = 0; (attr = modinfo_attrs[i]); i++) {
@@ -2332,11 +2332,20 @@ static int rewrite_section_headers(struct load_info *info, int flags)
23322332
return 0;
23332333
}
23342334

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+
23352343
/*
23362344
* These calls taint the kernel depending certain module circumstances */
23372345
static void module_augment_kernel_taints(struct module *mod, struct load_info *info)
23382346
{
23392347
int prev_taint = test_taint(TAINT_PROPRIETARY_MODULE);
2348+
size_t i;
23402349

23412350
if (!get_modinfo(info, "intree")) {
23422351
if (!test_taint(TAINT_OOT_MODULE))
@@ -2385,15 +2394,11 @@ static void module_augment_kernel_taints(struct module *mod, struct load_info *i
23852394
if (strcmp(mod->name, "ndiswrapper") == 0)
23862395
add_taint(TAINT_PROPRIETARY_MODULE, LOCKDEP_NOW_UNRELIABLE);
23872396

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+
}
23972402

23982403
if (!prev_taint && test_taint(TAINT_PROPRIETARY_MODULE))
23992404
pr_warn("%s: module license taints kernel.\n", mod->name);
@@ -2948,9 +2953,12 @@ static noinline int do_init_module(struct module *mod)
29482953
/* Switch to core kallsyms now init is done: kallsyms may be walking! */
29492954
rcu_assign_pointer(mod->kallsyms, &mod->core_kallsyms);
29502955
#endif
2951-
ret = module_enable_rodata_ro(mod, true);
2956+
ret = module_enable_rodata_ro_after_init(mod);
29522957
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+
29542962
mod_tree_remove_init(mod);
29552963
module_arch_freeing_init(mod);
29562964
for_class_mod_mem_type(type, init) {
@@ -2989,8 +2997,6 @@ static noinline int do_init_module(struct module *mod)
29892997

29902998
return 0;
29912999

2992-
fail_mutex_unlock:
2993-
mutex_unlock(&module_mutex);
29943000
fail_free_freeinit:
29953001
kfree(freeinit);
29963002
fail:
@@ -3118,7 +3124,7 @@ static int complete_formation(struct module *mod, struct load_info *info)
31183124
module_bug_finalize(info->hdr, info->sechdrs, mod);
31193125
module_cfi_finalize(info->hdr, info->sechdrs, mod);
31203126

3121-
err = module_enable_rodata_ro(mod, false);
3127+
err = module_enable_rodata_ro(mod);
31223128
if (err)
31233129
goto out_strict_rwx;
31243130
err = module_enable_data_nx(mod);

kernel/module/strict_rwx.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ int module_enable_text_rox(const struct module *mod)
4747
return 0;
4848
}
4949

50-
int module_enable_rodata_ro(const struct module *mod, bool after_init)
50+
int module_enable_rodata_ro(const struct module *mod)
5151
{
5252
int ret;
5353

@@ -61,12 +61,17 @@ int module_enable_rodata_ro(const struct module *mod, bool after_init)
6161
if (ret)
6262
return ret;
6363

64-
if (after_init)
65-
return module_set_memory(mod, MOD_RO_AFTER_INIT, set_memory_ro);
66-
6764
return 0;
6865
}
6966

67+
int module_enable_rodata_ro_after_init(const struct module *mod)
68+
{
69+
if (!IS_ENABLED(CONFIG_STRICT_MODULE_RWX) || !rodata_enabled)
70+
return 0;
71+
72+
return module_set_memory(mod, MOD_RO_AFTER_INIT, set_memory_ro);
73+
}
74+
7075
int module_enable_data_nx(const struct module *mod)
7176
{
7277
if (!IS_ENABLED(CONFIG_STRICT_MODULE_RWX))

0 commit comments

Comments
 (0)