From: Steven Rostedt <rostedt@goodmis.org>
To: linux-kernel@vger.kernel.org
Cc: Ingo Molnar <mingo@elte.hu>,
Andrew Morton <akpm@linux-foundation.org>,
Jason Baron <jbaron@redhat.com>, "H. Peter Anvin" <hpa@zytor.com>,
Frederic Weisbecker <fweisbec@gmail.com>
Subject: [PATCH 3/5] x86/jump-label: Add safety checks to jump label conversions
Date: Fri, 27 Jan 2012 15:14:45 -0500 [thread overview]
Message-ID: <20120127202031.535429354@goodmis.org> (raw)
In-Reply-To: 20120127201442.080360013@goodmis.org
[-- Attachment #1: Type: text/plain, Size: 2703 bytes --]
From: Steven Rostedt <srostedt@redhat.com>
As with all modifying of kernel text, we need to be very paranoid.
When converting the jump label locations to and from nops to jumps
a check has been added to make sure what we are replacing is what we
expect, otherwise we bug.
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Jason Baron <jbaron@redhat.com>
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
---
arch/x86/kernel/jump_label.c | 32 ++++++++++++++++++++++++++++----
1 files changed, 28 insertions(+), 4 deletions(-)
diff --git a/arch/x86/kernel/jump_label.c b/arch/x86/kernel/jump_label.c
index 0f4c6ba..44f2528 100644
--- a/arch/x86/kernel/jump_label.c
+++ b/arch/x86/kernel/jump_label.c
@@ -26,16 +26,40 @@ union jump_code_union {
static void __jump_label_transform(struct jump_entry *entry,
enum jump_label_type type,
- void *(*poker)(void *, const void *, size_t))
+ void *(*poker)(void *, const void *, size_t),
+ int init)
{
union jump_code_union code;
+ const unsigned char *ideal_nop = ideal_nops[NOP_ATOMIC5];
if (type == JUMP_LABEL_ENABLE) {
+ /*
+ * We are enabling this jump label. If it is not a nop
+ * then something must have gone wrong.
+ */
+ BUG_ON(memcmp((void *)entry->code, ideal_nop, 5) != 0);
+
code.jump = 0xe9;
code.offset = entry->target -
(entry->code + JUMP_LABEL_NOP_SIZE);
- } else
+ } else {
+ /*
+ * We are disabling this jump label. If it is not what
+ * we think it is, then something must have gone wrong.
+ * If this is the first initialization call, then we
+ * are converting the default nop to the ideal nop.
+ */
+ if (init) {
+ unsigned char default_nop[] = { JUMP_LABEL_INIT_NOP };
+ BUG_ON(memcmp((void *)entry->code, default_nop, 5) != 0);
+ } else {
+ code.jump = 0xe9;
+ code.offset = entry->target -
+ (entry->code + JUMP_LABEL_NOP_SIZE);
+ BUG_ON(memcmp((void *)entry->code, &code, 5) != 0);
+ }
memcpy(&code, ideal_nops[NOP_ATOMIC5], JUMP_LABEL_NOP_SIZE);
+ }
(*poker)((void *)entry->code, &code, JUMP_LABEL_NOP_SIZE);
}
@@ -45,7 +69,7 @@ void arch_jump_label_transform(struct jump_entry *entry,
{
get_online_cpus();
mutex_lock(&text_mutex);
- __jump_label_transform(entry, type, text_poke_smp);
+ __jump_label_transform(entry, type, text_poke_smp, 0);
mutex_unlock(&text_mutex);
put_online_cpus();
}
@@ -71,7 +95,7 @@ void arch_jump_label_transform_static(struct jump_entry *entry,
update = 1;
}
if (update)
- __jump_label_transform(entry, type, text_poke_early);
+ __jump_label_transform(entry, type, text_poke_early, 1);
}
#endif
--
1.7.8.3
[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 836 bytes --]
next prev parent reply other threads:[~2012-01-27 20:21 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-01-27 20:14 [PATCH 0/5] [GIT PULL] x86/jump label: Paranoid checks and 2 or 5 byte nops Steven Rostedt
2012-01-27 20:14 ` [PATCH 1/5] x86/jump-label: Use best default nops for inital jump label calls Steven Rostedt
2012-01-27 20:27 ` H. Peter Anvin
2012-01-27 20:49 ` Steven Rostedt
2012-01-27 20:50 ` H. Peter Anvin
2012-01-27 21:00 ` Steven Rostedt
2012-01-30 21:05 ` Michal Marek
2012-01-27 20:14 ` [PATCH 2/5] x86/jump-label: Do not bother updating nops if they are correct Steven Rostedt
2012-01-27 20:34 ` Andrew Morton
2012-01-27 20:42 ` Steven Rostedt
2012-01-27 20:14 ` Steven Rostedt [this message]
2012-01-27 20:14 ` [PATCH 4/5] jump labels: Add infrastructure to update jump labels at compile time Steven Rostedt
2012-01-27 20:14 ` [PATCH 5/5] jump labels/x86: Use etiher 5 byte or 2 byte jumps Steven Rostedt
2012-01-27 21:47 ` Steven Rostedt
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20120127202031.535429354@goodmis.org \
--to=rostedt@goodmis.org \
--cc=akpm@linux-foundation.org \
--cc=fweisbec@gmail.com \
--cc=hpa@zytor.com \
--cc=jbaron@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@elte.hu \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).