Skip to content

Commit 4d98ead

Browse files
committed
Merge tag 'modules-for-v4.10' of git://git.kernel.org/pub/scm/linux/kernel/git/jeyu/linux
Pull modules updates from Jessica Yu: "Summary of modules changes for the 4.10 merge window: - The rodata= cmdline parameter has been extended to additionally apply to module mappings - Fix a hard to hit race between module loader error/clean up handling and ftrace registration - Some code cleanups, notably panic.c and modules code use a unified taint_flags table now. This is much cleaner than duplicating the taint flag code in modules.c" * tag 'modules-for-v4.10' of git://git.kernel.org/pub/scm/linux/kernel/git/jeyu/linux: module: fix DEBUG_SET_MODULE_RONX typo module: extend 'rodata=off' boot cmdline parameter to module mappings module: Fix a comment above strong_try_module_get() module: When modifying a module's text ignore modules which are going away too module: Ensure a module's state is set accordingly during module coming cleanup code module: remove trailing whitespace taint/module: Clean up global and module taint flags handling modpost: free allocated memory
2 parents a57cb1c + 4d217a5 commit 4d98ead

7 files changed

Lines changed: 89 additions & 58 deletions

File tree

include/linux/init.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,9 @@ void prepare_namespace(void);
126126
void __init load_default_modules(void);
127127
int __init init_rootfs(void);
128128

129+
#if defined(CONFIG_DEBUG_RODATA) || defined(CONFIG_DEBUG_SET_MODULE_RONX)
130+
extern bool rodata_enabled;
131+
#endif
129132
#ifdef CONFIG_DEBUG_RODATA
130133
void mark_rodata_ro(void);
131134
#endif

include/linux/kernel.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -511,6 +511,15 @@ extern enum system_states {
511511
#define TAINT_UNSIGNED_MODULE 13
512512
#define TAINT_SOFTLOCKUP 14
513513
#define TAINT_LIVEPATCH 15
514+
#define TAINT_FLAGS_COUNT 16
515+
516+
struct taint_flag {
517+
char true; /* character printed when tainted */
518+
char false; /* character printed when not tainted */
519+
bool module; /* also show as a per-module taint flag */
520+
};
521+
522+
extern const struct taint_flag taint_flags[TAINT_FLAGS_COUNT];
514523

515524
extern const char hex_asc[];
516525
#define hex_asc_lo(x) hex_asc[((x) & 0x0f)]

include/linux/module.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,7 @@ struct module {
399399
/* Arch-specific module values */
400400
struct mod_arch_specific arch;
401401

402-
unsigned int taints; /* same bits as kernel:tainted */
402+
unsigned long taints; /* same bits as kernel:taint_flags */
403403

404404
#ifdef CONFIG_GENERIC_BUG
405405
/* Support for BUG */
@@ -412,7 +412,7 @@ struct module {
412412
/* Protected by RCU and/or module_mutex: use rcu_dereference() */
413413
struct mod_kallsyms *kallsyms;
414414
struct mod_kallsyms core_kallsyms;
415-
415+
416416
/* Section attributes */
417417
struct module_sect_attrs *sect_attrs;
418418

init/main.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@
8181
#include <linux/integrity.h>
8282
#include <linux/proc_ns.h>
8383
#include <linux/io.h>
84+
#include <linux/cache.h>
8485

8586
#include <asm/io.h>
8687
#include <asm/bugs.h>
@@ -925,14 +926,16 @@ static int try_to_run_init_process(const char *init_filename)
925926

926927
static noinline void __init kernel_init_freeable(void);
927928

928-
#ifdef CONFIG_DEBUG_RODATA
929-
static bool rodata_enabled = true;
929+
#if defined(CONFIG_DEBUG_RODATA) || defined(CONFIG_DEBUG_SET_MODULE_RONX)
930+
bool rodata_enabled __ro_after_init = true;
930931
static int __init set_debug_rodata(char *str)
931932
{
932933
return strtobool(str, &rodata_enabled);
933934
}
934935
__setup("rodata=", set_debug_rodata);
936+
#endif
935937

938+
#ifdef CONFIG_DEBUG_RODATA
936939
static void mark_readonly(void)
937940
{
938941
if (rodata_enabled)

kernel/module.c

Lines changed: 43 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -313,8 +313,11 @@ struct load_info {
313313
} index;
314314
};
315315

316-
/* We require a truly strong try_module_get(): 0 means failure due to
317-
ongoing or failed initialization etc. */
316+
/*
317+
* We require a truly strong try_module_get(): 0 means success.
318+
* Otherwise an error is returned due to ongoing or failed
319+
* initialization etc.
320+
*/
318321
static inline int strong_try_module_get(struct module *mod)
319322
{
320323
BUG_ON(mod && mod->state == MODULE_STATE_UNFORMED);
@@ -330,7 +333,7 @@ static inline void add_taint_module(struct module *mod, unsigned flag,
330333
enum lockdep_ok lockdep_ok)
331334
{
332335
add_taint(flag, lockdep_ok);
333-
mod->taints |= (1U << flag);
336+
set_bit(flag, &mod->taints);
334337
}
335338

336339
/*
@@ -1138,24 +1141,13 @@ static inline int module_unload_init(struct module *mod)
11381141
static size_t module_flags_taint(struct module *mod, char *buf)
11391142
{
11401143
size_t l = 0;
1144+
int i;
1145+
1146+
for (i = 0; i < TAINT_FLAGS_COUNT; i++) {
1147+
if (taint_flags[i].module && test_bit(i, &mod->taints))
1148+
buf[l++] = taint_flags[i].true;
1149+
}
11411150

1142-
if (mod->taints & (1 << TAINT_PROPRIETARY_MODULE))
1143-
buf[l++] = 'P';
1144-
if (mod->taints & (1 << TAINT_OOT_MODULE))
1145-
buf[l++] = 'O';
1146-
if (mod->taints & (1 << TAINT_FORCED_MODULE))
1147-
buf[l++] = 'F';
1148-
if (mod->taints & (1 << TAINT_CRAP))
1149-
buf[l++] = 'C';
1150-
if (mod->taints & (1 << TAINT_UNSIGNED_MODULE))
1151-
buf[l++] = 'E';
1152-
if (mod->taints & (1 << TAINT_LIVEPATCH))
1153-
buf[l++] = 'K';
1154-
/*
1155-
* TAINT_FORCED_RMMOD: could be added.
1156-
* TAINT_CPU_OUT_OF_SPEC, TAINT_MACHINE_CHECK, TAINT_BAD_PAGE don't
1157-
* apply to modules.
1158-
*/
11591151
return l;
11601152
}
11611153

@@ -1911,6 +1903,9 @@ static void frob_writable_data(const struct module_layout *layout,
19111903
/* livepatching wants to disable read-only so it can frob module. */
19121904
void module_disable_ro(const struct module *mod)
19131905
{
1906+
if (!rodata_enabled)
1907+
return;
1908+
19141909
frob_text(&mod->core_layout, set_memory_rw);
19151910
frob_rodata(&mod->core_layout, set_memory_rw);
19161911
frob_ro_after_init(&mod->core_layout, set_memory_rw);
@@ -1920,6 +1915,9 @@ void module_disable_ro(const struct module *mod)
19201915

19211916
void module_enable_ro(const struct module *mod, bool after_init)
19221917
{
1918+
if (!rodata_enabled)
1919+
return;
1920+
19231921
frob_text(&mod->core_layout, set_memory_ro);
19241922
frob_rodata(&mod->core_layout, set_memory_ro);
19251923
frob_text(&mod->init_layout, set_memory_ro);
@@ -1952,6 +1950,9 @@ void set_all_modules_text_rw(void)
19521950
{
19531951
struct module *mod;
19541952

1953+
if (!rodata_enabled)
1954+
return;
1955+
19551956
mutex_lock(&module_mutex);
19561957
list_for_each_entry_rcu(mod, &modules, list) {
19571958
if (mod->state == MODULE_STATE_UNFORMED)
@@ -1968,9 +1969,18 @@ void set_all_modules_text_ro(void)
19681969
{
19691970
struct module *mod;
19701971

1972+
if (!rodata_enabled)
1973+
return;
1974+
19711975
mutex_lock(&module_mutex);
19721976
list_for_each_entry_rcu(mod, &modules, list) {
1973-
if (mod->state == MODULE_STATE_UNFORMED)
1977+
/*
1978+
* Ignore going modules since it's possible that ro
1979+
* protection has already been disabled, otherwise we'll
1980+
* run into protection faults at module deallocation.
1981+
*/
1982+
if (mod->state == MODULE_STATE_UNFORMED ||
1983+
mod->state == MODULE_STATE_GOING)
19741984
continue;
19751985

19761986
frob_text(&mod->core_layout, set_memory_ro);
@@ -1981,10 +1991,12 @@ void set_all_modules_text_ro(void)
19811991

19821992
static void disable_ro_nx(const struct module_layout *layout)
19831993
{
1984-
frob_text(layout, set_memory_rw);
1985-
frob_rodata(layout, set_memory_rw);
1994+
if (rodata_enabled) {
1995+
frob_text(layout, set_memory_rw);
1996+
frob_rodata(layout, set_memory_rw);
1997+
frob_ro_after_init(layout, set_memory_rw);
1998+
}
19861999
frob_rodata(layout, set_memory_x);
1987-
frob_ro_after_init(layout, set_memory_rw);
19882000
frob_ro_after_init(layout, set_memory_x);
19892001
frob_writable_data(layout, set_memory_x);
19902002
}
@@ -3709,6 +3721,7 @@ static int load_module(struct load_info *info, const char __user *uargs,
37093721
sysfs_cleanup:
37103722
mod_sysfs_teardown(mod);
37113723
coming_cleanup:
3724+
mod->state = MODULE_STATE_GOING;
37123725
blocking_notifier_call_chain(&module_notify_list,
37133726
MODULE_STATE_GOING, mod);
37143727
klp_module_going(mod);
@@ -4042,6 +4055,10 @@ int module_kallsyms_on_each_symbol(int (*fn)(void *, const char *,
40424055
}
40434056
#endif /* CONFIG_KALLSYMS */
40444057

4058+
/* Maximum number of characters written by module_flags() */
4059+
#define MODULE_FLAGS_BUF_SIZE (TAINT_FLAGS_COUNT + 4)
4060+
4061+
/* Keep in sync with MODULE_FLAGS_BUF_SIZE !!! */
40454062
static char *module_flags(struct module *mod, char *buf)
40464063
{
40474064
int bx = 0;
@@ -4086,7 +4103,7 @@ static void m_stop(struct seq_file *m, void *p)
40864103
static int m_show(struct seq_file *m, void *p)
40874104
{
40884105
struct module *mod = list_entry(p, struct module, list);
4089-
char buf[8];
4106+
char buf[MODULE_FLAGS_BUF_SIZE];
40904107

40914108
/* We always ignore unformed modules. */
40924109
if (mod->state == MODULE_STATE_UNFORMED)
@@ -4257,7 +4274,7 @@ EXPORT_SYMBOL_GPL(__module_text_address);
42574274
void print_modules(void)
42584275
{
42594276
struct module *mod;
4260-
char buf[8];
4277+
char buf[MODULE_FLAGS_BUF_SIZE];
42614278

42624279
printk(KERN_DEFAULT "Modules linked in:");
42634280
/* Most callers should already have preempt disabled, but make sure */

kernel/panic.c

Lines changed: 25 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -298,30 +298,27 @@ void panic(const char *fmt, ...)
298298

299299
EXPORT_SYMBOL(panic);
300300

301-
302-
struct tnt {
303-
u8 bit;
304-
char true;
305-
char false;
306-
};
307-
308-
static const struct tnt tnts[] = {
309-
{ TAINT_PROPRIETARY_MODULE, 'P', 'G' },
310-
{ TAINT_FORCED_MODULE, 'F', ' ' },
311-
{ TAINT_CPU_OUT_OF_SPEC, 'S', ' ' },
312-
{ TAINT_FORCED_RMMOD, 'R', ' ' },
313-
{ TAINT_MACHINE_CHECK, 'M', ' ' },
314-
{ TAINT_BAD_PAGE, 'B', ' ' },
315-
{ TAINT_USER, 'U', ' ' },
316-
{ TAINT_DIE, 'D', ' ' },
317-
{ TAINT_OVERRIDDEN_ACPI_TABLE, 'A', ' ' },
318-
{ TAINT_WARN, 'W', ' ' },
319-
{ TAINT_CRAP, 'C', ' ' },
320-
{ TAINT_FIRMWARE_WORKAROUND, 'I', ' ' },
321-
{ TAINT_OOT_MODULE, 'O', ' ' },
322-
{ TAINT_UNSIGNED_MODULE, 'E', ' ' },
323-
{ TAINT_SOFTLOCKUP, 'L', ' ' },
324-
{ TAINT_LIVEPATCH, 'K', ' ' },
301+
/*
302+
* TAINT_FORCED_RMMOD could be a per-module flag but the module
303+
* is being removed anyway.
304+
*/
305+
const struct taint_flag taint_flags[TAINT_FLAGS_COUNT] = {
306+
{ 'P', 'G', true }, /* TAINT_PROPRIETARY_MODULE */
307+
{ 'F', ' ', true }, /* TAINT_FORCED_MODULE */
308+
{ 'S', ' ', false }, /* TAINT_CPU_OUT_OF_SPEC */
309+
{ 'R', ' ', false }, /* TAINT_FORCED_RMMOD */
310+
{ 'M', ' ', false }, /* TAINT_MACHINE_CHECK */
311+
{ 'B', ' ', false }, /* TAINT_BAD_PAGE */
312+
{ 'U', ' ', false }, /* TAINT_USER */
313+
{ 'D', ' ', false }, /* TAINT_DIE */
314+
{ 'A', ' ', false }, /* TAINT_OVERRIDDEN_ACPI_TABLE */
315+
{ 'W', ' ', false }, /* TAINT_WARN */
316+
{ 'C', ' ', true }, /* TAINT_CRAP */
317+
{ 'I', ' ', false }, /* TAINT_FIRMWARE_WORKAROUND */
318+
{ 'O', ' ', true }, /* TAINT_OOT_MODULE */
319+
{ 'E', ' ', true }, /* TAINT_UNSIGNED_MODULE */
320+
{ 'L', ' ', false }, /* TAINT_SOFTLOCKUP */
321+
{ 'K', ' ', true }, /* TAINT_LIVEPATCH */
325322
};
326323

327324
/**
@@ -348,16 +345,16 @@ static const struct tnt tnts[] = {
348345
*/
349346
const char *print_tainted(void)
350347
{
351-
static char buf[ARRAY_SIZE(tnts) + sizeof("Tainted: ")];
348+
static char buf[TAINT_FLAGS_COUNT + sizeof("Tainted: ")];
352349

353350
if (tainted_mask) {
354351
char *s;
355352
int i;
356353

357354
s = buf + sprintf(buf, "Tainted: ");
358-
for (i = 0; i < ARRAY_SIZE(tnts); i++) {
359-
const struct tnt *t = &tnts[i];
360-
*s++ = test_bit(t->bit, &tainted_mask) ?
355+
for (i = 0; i < TAINT_FLAGS_COUNT; i++) {
356+
const struct taint_flag *t = &taint_flags[i];
357+
*s++ = test_bit(i, &tainted_mask) ?
361358
t->true : t->false;
362359
}
363360
*s = 0;

scripts/mod/modpost.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2371,6 +2371,7 @@ static void write_dump(const char *fname)
23712371
}
23722372
}
23732373
write_if_changed(&buf, fname);
2374+
free(buf.p);
23742375
}
23752376

23762377
struct ext_sym_list {
@@ -2496,6 +2497,7 @@ int main(int argc, char **argv)
24962497
"Set CONFIG_SECTION_MISMATCH_WARN_ONLY=y to allow them.\n");
24972498
}
24982499
}
2500+
free(buf.p);
24992501

25002502
return err;
25012503
}

0 commit comments

Comments
 (0)