From: tip-bot for Mateusz Jurczyk <tipbot@zytor.com>
To: linux-tip-commits@vger.kernel.org
Cc: mjurczyk@google.com, linux-kernel@vger.kernel.org, hpa@zytor.com,
bp@suse.de, luto@kernel.org, mingo@kernel.org,
tglx@linutronix.de
Subject: [tip:x86/urgent] x86/alternatives: Prevent uninitialized stack byte read in apply_alternatives()
Date: Wed, 24 May 2017 07:25:09 -0700 [thread overview]
Message-ID: <tip-fc152d22d6e9fac95a9a990e6c29510bdf1b9425@git.kernel.org> (raw)
In-Reply-To: <20170524135500.27223-1-mjurczyk@google.com>
Commit-ID: fc152d22d6e9fac95a9a990e6c29510bdf1b9425
Gitweb: http://git.kernel.org/tip/fc152d22d6e9fac95a9a990e6c29510bdf1b9425
Author: Mateusz Jurczyk <mjurczyk@google.com>
AuthorDate: Wed, 24 May 2017 15:55:00 +0200
Committer: Thomas Gleixner <tglx@linutronix.de>
CommitDate: Wed, 24 May 2017 16:18:12 +0200
x86/alternatives: Prevent uninitialized stack byte read in apply_alternatives()
In the current form of the code, if a->replacementlen is 0, the reference
to *insnbuf for comparison touches potentially garbage memory. While it
doesn't affect the execution flow due to the subsequent a->replacementlen
comparison, it is (rightly) detected as use of uninitialized memory by a
runtime instrumentation currently under my development, and could be
detected as such by other tools in the future, too (e.g. KMSAN).
Fix the "false-positive" by reordering the conditions to first check the
replacement instruction length before referencing specific opcode bytes.
Signed-off-by: Mateusz Jurczyk <mjurczyk@google.com>
Reviewed-by: Borislav Petkov <bp@suse.de>
Cc: Andy Lutomirski <luto@kernel.org>
Link: http://lkml.kernel.org/r/20170524135500.27223-1-mjurczyk@google.com
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
---
arch/x86/kernel/alternative.c | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)
diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c
index c5b8f76..32e14d1 100644
--- a/arch/x86/kernel/alternative.c
+++ b/arch/x86/kernel/alternative.c
@@ -409,8 +409,13 @@ void __init_or_module noinline apply_alternatives(struct alt_instr *start,
memcpy(insnbuf, replacement, a->replacementlen);
insnbuf_sz = a->replacementlen;
- /* 0xe8 is a relative jump; fix the offset. */
- if (*insnbuf == 0xe8 && a->replacementlen == 5) {
+ /*
+ * 0xe8 is a relative jump; fix the offset.
+ *
+ * Instruction length is checked before the opcode to avoid
+ * accessing uninitialized bytes for zero-length replacements.
+ */
+ if (a->replacementlen == 5 && *insnbuf == 0xe8) {
*(s32 *)(insnbuf + 1) += replacement - instr;
DPRINTK("Fix CALL offset: 0x%x, CALL 0x%lx",
*(s32 *)(insnbuf + 1),
prev parent reply other threads:[~2017-05-24 14:27 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-05-24 12:51 [PATCH] x86: " Mateusz Jurczyk
2017-05-24 13:04 ` Borislav Petkov
2017-05-24 13:55 ` [PATCH v2] " Mateusz Jurczyk
2017-05-24 14:02 ` Borislav Petkov
2017-05-24 14:25 ` tip-bot for Mateusz Jurczyk [this message]
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=tip-fc152d22d6e9fac95a9a990e6c29510bdf1b9425@git.kernel.org \
--to=tipbot@zytor.com \
--cc=bp@suse.de \
--cc=hpa@zytor.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-tip-commits@vger.kernel.org \
--cc=luto@kernel.org \
--cc=mingo@kernel.org \
--cc=mjurczyk@google.com \
--cc=tglx@linutronix.de \
/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
all inboxes | Powered by JetHome®