Skip to content

Commit 9e66762

Browse files
Peter ZijlstraIngo Molnar
authored andcommitted
jump_label: Fix jump_label_text_reserved() vs __init
It turns out that jump_label_text_reserved() was reporting __init text as being reserved past the time when the __init text was freed and re-used. For a long time, this resulted in, at worst, not being able to kprobe text that happened to land at the re-used address. However a recent commit e7bf1ba ("jump_label, x86: Emit short JMP") made it a fatal mistake because it now needs to read the instruction in order to determine the conflict -- an instruction that's no longer there. Fixes: 4c3ef6d ("jump label: Add jump_label_text_reserved() to reserve jump points") Reported-by: kernel test robot <[email protected]> Signed-off-by: Peter Zijlstra (Intel) <[email protected]> Signed-off-by: Ingo Molnar <[email protected]> Reviewed-by: Masami Hiramatsu <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 4840ce2 commit 9e66762

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

kernel/jump_label.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -316,14 +316,16 @@ static int addr_conflict(struct jump_entry *entry, void *start, void *end)
316316
}
317317

318318
static int __jump_label_text_reserved(struct jump_entry *iter_start,
319-
struct jump_entry *iter_stop, void *start, void *end)
319+
struct jump_entry *iter_stop, void *start, void *end, bool init)
320320
{
321321
struct jump_entry *iter;
322322

323323
iter = iter_start;
324324
while (iter < iter_stop) {
325-
if (addr_conflict(iter, start, end))
326-
return 1;
325+
if (init || !jump_entry_is_init(iter)) {
326+
if (addr_conflict(iter, start, end))
327+
return 1;
328+
}
327329
iter++;
328330
}
329331

@@ -562,7 +564,7 @@ static int __jump_label_mod_text_reserved(void *start, void *end)
562564

563565
ret = __jump_label_text_reserved(mod->jump_entries,
564566
mod->jump_entries + mod->num_jump_entries,
565-
start, end);
567+
start, end, mod->state == MODULE_STATE_COMING);
566568

567569
module_put(mod);
568570

@@ -788,8 +790,9 @@ early_initcall(jump_label_init_module);
788790
*/
789791
int jump_label_text_reserved(void *start, void *end)
790792
{
793+
bool init = system_state < SYSTEM_RUNNING;
791794
int ret = __jump_label_text_reserved(__start___jump_table,
792-
__stop___jump_table, start, end);
795+
__stop___jump_table, start, end, init);
793796

794797
if (ret)
795798
return ret;

0 commit comments

Comments
 (0)