* Re: [PATCH] static_call: Fix the module key fixup
2021-02-25 22:03 ` [PATCH] static_call: Fix the module key fixup Peter Zijlstra
@ 2021-02-26 3:11 ` Steven Rostedt
2021-03-01 10:16 ` [tip: locking/urgent] " tip-bot2 for Peter Zijlstra
2021-03-06 11:54 ` [tip: locking/core] " tip-bot2 for Peter Zijlstra
2 siblings, 0 replies; 5+ messages in thread
From: Steven Rostedt @ 2021-02-26 3:11 UTC (permalink / raw)
To: Peter Zijlstra; +Cc: LKML, Linus Torvalds, Josh Poimboeuf
On Thu, 25 Feb 2021 23:03:51 +0100
Peter Zijlstra <peterz@infradead.org> wrote:
> Subject: static_call: Fix the module key fixup
>
> 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.
>
Link: https://lore.kernel.org/lkml/20210225131221.11dab26e@gandalf.local.home/
> Reported-by: Steven Rostedt <rostedt@goodmis.org>
Tested-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
-- Steve
> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
> ---
> kernel/static_call.c | 7 ++++---
> 1 file changed, 4 insertions(+), 3 deletions(-)
>
> diff --git a/kernel/static_call.c b/kernel/static_call.c
> index 6906c6ec4c97..ae825295cf68 100644
> --- a/kernel/static_call.c
> +++ b/kernel/static_call.c
> @@ -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;
>
> /*
> @@ -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);
^ permalink raw reply [flat|nested] 5+ messages in thread
* [tip: locking/urgent] static_call: Fix the module key fixup
2021-02-25 22:03 ` [PATCH] static_call: Fix the module key fixup Peter Zijlstra
2021-02-26 3:11 ` Steven Rostedt
@ 2021-03-01 10:16 ` tip-bot2 for Peter Zijlstra
2021-03-06 11:54 ` [tip: locking/core] " tip-bot2 for Peter Zijlstra
2 siblings, 0 replies; 5+ messages in thread
From: tip-bot2 for Peter Zijlstra @ 2021-03-01 10:16 UTC (permalink / raw)
To: linux-tip-commits
Cc: Steven Rostedt, Peter Zijlstra (Intel), x86, linux-kernel
The following commit has been merged into the locking/urgent branch of tip:
Commit-ID: 8b97c027dfe4ba195be08fd0e18f716005763b8a
Gitweb: https://git.kernel.org/tip/8b97c027dfe4ba195be08fd0e18f716005763b8a
Author: Peter Zijlstra <peterz@infradead.org>
AuthorDate: Thu, 25 Feb 2021 23:03:51 +01:00
Committer: Peter Zijlstra <peterz@infradead.org>
CommitterDate: Mon, 01 Mar 2021 11:02:10 +01:00
static_call: Fix the module key fixup
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: 73f44fe19d35 ("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>
Tested-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
Link: https://lkml.kernel.org/r/20210225220351.GE4746@worktop.programming.kicks-ass.net
---
kernel/static_call.c | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/kernel/static_call.c b/kernel/static_call.c
index 6906c6e..ae82529 100644
--- a/kernel/static_call.c
+++ b/kernel/static_call.c
@@ -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;
/*
@@ -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);
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [tip: locking/core] static_call: Fix the module key fixup
2021-02-25 22:03 ` [PATCH] static_call: Fix the module key fixup Peter Zijlstra
2021-02-26 3:11 ` Steven Rostedt
2021-03-01 10:16 ` [tip: locking/urgent] " tip-bot2 for Peter Zijlstra
@ 2021-03-06 11:54 ` tip-bot2 for Peter Zijlstra
2 siblings, 0 replies; 5+ messages in thread
From: tip-bot2 for Peter Zijlstra @ 2021-03-06 11:54 UTC (permalink / raw)
To: linux-tip-commits
Cc: Steven Rostedt, Peter Zijlstra (Intel), Ingo Molnar, x86, linux-kernel
The following commit has been merged into the locking/core branch of tip:
Commit-ID: 50bf8080a94d171e843fc013abec19d8ab9f50ae
Gitweb: https://git.kernel.org/tip/50bf8080a94d171e843fc013abec19d8ab9f50ae
Author: Peter Zijlstra <peterz@infradead.org>
AuthorDate: Thu, 25 Feb 2021 23:03:51 +01:00
Committer: Ingo Molnar <mingo@kernel.org>
CommitterDate: Sat, 06 Mar 2021 12:49:08 +01:00
static_call: Fix the module key fixup
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: 73f44fe19d35 ("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
---
kernel/static_call.c | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/kernel/static_call.c b/kernel/static_call.c
index 6906c6e..ae82529 100644
--- a/kernel/static_call.c
+++ b/kernel/static_call.c
@@ -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;
/*
@@ -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);
^ permalink raw reply related [flat|nested] 5+ messages in thread