Skip to content

Commit

Permalink
static_call: Fix the module key fixup
Browse files Browse the repository at this point in the history
Provided the target address of a R_X86_64_PC32 relocation is aligned,
the low two bits should be invariant between the relative and absolute
value.

Turns out the address is not aligned and things go sideways, ensure we
transfer the bits in the absolute form when fixing up the key address.

Fixes: 73f44fe ("static_call: Allow module use without exposing static_call_key")
Reported-by: Steven Rostedt <rostedt@goodmis.org>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Tested-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
Link: https://lkml.kernel.org/r/20210225220351.GE4746@worktop.programming.kicks-ass.net
  • Loading branch information
Peter Zijlstra authored and Ingo Molnar committed Mar 6, 2021
1 parent a38fd87 commit 50bf808
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions kernel/static_call.c
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,8 @@ static int static_call_add_module(struct module *mod)
struct static_call_site *site;

for (site = start; site != stop; site++) {
unsigned long addr = (unsigned long)static_call_key(site);
unsigned long s_key = (long)site->key + (long)&site->key;
unsigned long addr = s_key & ~STATIC_CALL_SITE_FLAGS;
unsigned long key;

/*
Expand All @@ -373,8 +374,8 @@ static int static_call_add_module(struct module *mod)
return -EINVAL;
}

site->key = (key - (long)&site->key) |
(site->key & STATIC_CALL_SITE_FLAGS);
key |= s_key & STATIC_CALL_SITE_FLAGS;
site->key = key - (long)&site->key;
}

return __static_call_init(mod, start, stop);
Expand Down

0 comments on commit 50bf808

Please sign in to comment.