Skip to content

Commit 2992ef2

Browse files
jpoimboeJiri Kosina
authored andcommitted
livepatch/module: make TAINT_LIVEPATCH module-specific
There's no reliable way to determine which module tainted the kernel with TAINT_LIVEPATCH. For example, /sys/module/<klp module>/taint doesn't report it. Neither does the "mod -t" command in the crash tool. Make it crystal clear who the guilty party is by associating TAINT_LIVEPATCH with any module which sets the "livepatch" modinfo attribute. The flag will still get set in the kernel like before, but now it also sets the same flag in mod->taint. Note that now the taint flag gets set when the module is loaded rather than when it's enabled. I also renamed find_livepatch_modinfo() to check_modinfo_livepatch() to better reflect its purpose: it's basically a livepatch-specific sub-function of check_modinfo(). Reported-by: Chunyu Hu <[email protected]> Reviewed-by: Petr Mladek <[email protected]> Acked-by: Miroslav Benes <[email protected]> Acked-by: Jessica Yu <[email protected]> Acked-by: Rusty Russell <[email protected]> Signed-off-by: Josh Poimboeuf <[email protected]> Signed-off-by: Jiri Kosina <[email protected]>
1 parent 5ad75fc commit 2992ef2

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

kernel/livepatch/core.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -545,9 +545,6 @@ static int __klp_enable_patch(struct klp_patch *patch)
545545
list_prev_entry(patch, list)->state == KLP_DISABLED)
546546
return -EBUSY;
547547

548-
pr_notice_once("tainting kernel with TAINT_LIVEPATCH\n");
549-
add_taint(TAINT_LIVEPATCH, LOCKDEP_STILL_OK);
550-
551548
pr_notice("enabling patch '%s'\n", patch->mod->name);
552549

553550
klp_for_each_object(patch, obj) {

kernel/module.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1149,6 +1149,8 @@ static size_t module_flags_taint(struct module *mod, char *buf)
11491149
buf[l++] = 'C';
11501150
if (mod->taints & (1 << TAINT_UNSIGNED_MODULE))
11511151
buf[l++] = 'E';
1152+
if (mod->taints & (1 << TAINT_LIVEPATCH))
1153+
buf[l++] = 'K';
11521154
/*
11531155
* TAINT_FORCED_RMMOD: could be added.
11541156
* TAINT_CPU_OUT_OF_SPEC, TAINT_MACHINE_CHECK, TAINT_BAD_PAGE don't
@@ -2792,14 +2794,17 @@ static int copy_chunked_from_user(void *dst, const void __user *usrc, unsigned l
27922794
}
27932795

27942796
#ifdef CONFIG_LIVEPATCH
2795-
static int find_livepatch_modinfo(struct module *mod, struct load_info *info)
2797+
static int check_modinfo_livepatch(struct module *mod, struct load_info *info)
27962798
{
2797-
mod->klp = get_modinfo(info, "livepatch") ? true : false;
2799+
if (get_modinfo(info, "livepatch")) {
2800+
mod->klp = true;
2801+
add_taint_module(mod, TAINT_LIVEPATCH, LOCKDEP_STILL_OK);
2802+
}
27982803

27992804
return 0;
28002805
}
28012806
#else /* !CONFIG_LIVEPATCH */
2802-
static int find_livepatch_modinfo(struct module *mod, struct load_info *info)
2807+
static int check_modinfo_livepatch(struct module *mod, struct load_info *info)
28032808
{
28042809
if (get_modinfo(info, "livepatch")) {
28052810
pr_err("%s: module is marked as livepatch module, but livepatch support is disabled",
@@ -2969,7 +2974,7 @@ static int check_modinfo(struct module *mod, struct load_info *info, int flags)
29692974
"is unknown, you have been warned.\n", mod->name);
29702975
}
29712976

2972-
err = find_livepatch_modinfo(mod, info);
2977+
err = check_modinfo_livepatch(mod, info);
29732978
if (err)
29742979
return err;
29752980

0 commit comments

Comments
 (0)