mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: tip-bot for Kees Cook <tipbot@zytor.com>
To: linux-tip-commits@vger.kernel.org
Cc: hpa@zytor.com, bp@suse.de, dvlasenk@redhat.com,
	keescook@chromium.org, linux-kernel@vger.kernel.org,
	tglx@linutronix.de, mingo@kernel.org, lasse.collin@tukaani.org,
	luto@amacapital.net, peterz@infradead.org, yinghai@kernel.org,
	bp@alien8.de, bhe@redhat.com, torvalds@linux-foundation.org,
	gnomes@lxorguk.ukuu.org.uk, brgerst@gmail.com
Subject: [tip:x86/boot] x86/boot: Extract error reporting functions
Date: Tue, 3 May 2016 00:45:42 -0700	[thread overview]
Message-ID: <tip-dc425a6e140bca99bdb4823e9909c9d9b8ba36b6@git.kernel.org> (raw)
In-Reply-To: <1462229461-3370-2-git-send-email-keescook@chromium.org>

Commit-ID:  dc425a6e140bca99bdb4823e9909c9d9b8ba36b6
Gitweb:     http://git.kernel.org/tip/dc425a6e140bca99bdb4823e9909c9d9b8ba36b6
Author:     Kees Cook <keescook@chromium.org>
AuthorDate: Mon, 2 May 2016 15:51:00 -0700
Committer:  Ingo Molnar <mingo@kernel.org>
CommitDate: Tue, 3 May 2016 08:15:58 +0200

x86/boot: Extract error reporting functions

Currently to use warn(), a caller would need to include misc.h. However,
this means they would get the (unavailable during compressed boot)
gcc built-in memcpy family of functions. But since string.c is defining
these memcpy functions for use by misc.c, we end up in a weird circular
dependency.

To break this loop, move the error reporting functions outside of misc.c
with their own header so that they can be independently included by
other sources. Since the screen-writing routines use memmove(), keep the
low-level *_putstr() functions in misc.c.

Signed-off-by: Kees Cook <keescook@chromium.org>
Cc: Andy Lutomirski <luto@amacapital.net>
Cc: Baoquan He <bhe@redhat.com>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Borislav Petkov <bp@suse.de>
Cc: Brian Gerst <brgerst@gmail.com>
Cc: Denys Vlasenko <dvlasenk@redhat.com>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Lasse Collin <lasse.collin@tukaani.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: One Thousand Gnomes <gnomes@lxorguk.ukuu.org.uk>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Yinghai Lu <yinghai@kernel.org>
Link: http://lkml.kernel.org/r/1462229461-3370-2-git-send-email-keescook@chromium.org
Signed-off-by: Ingo Molnar <mingo@kernel.org>
---
 arch/x86/boot/compressed/Makefile |  2 +-
 arch/x86/boot/compressed/error.c  | 22 ++++++++++++++++++++++
 arch/x86/boot/compressed/error.h  |  7 +++++++
 arch/x86/boot/compressed/kaslr.c  |  1 +
 arch/x86/boot/compressed/misc.c   | 18 +-----------------
 arch/x86/boot/compressed/misc.h   |  1 -
 arch/x86/boot/compressed/string.c |  2 ++
 7 files changed, 34 insertions(+), 19 deletions(-)

diff --git a/arch/x86/boot/compressed/Makefile b/arch/x86/boot/compressed/Makefile
index 75f2233..77ce3a0 100644
--- a/arch/x86/boot/compressed/Makefile
+++ b/arch/x86/boot/compressed/Makefile
@@ -70,7 +70,7 @@ $(obj)/../voffset.h: vmlinux FORCE
 $(obj)/misc.o: $(obj)/../voffset.h
 
 vmlinux-objs-y := $(obj)/vmlinux.lds $(obj)/head_$(BITS).o $(obj)/misc.o \
-	$(obj)/string.o $(obj)/cmdline.o \
+	$(obj)/string.o $(obj)/cmdline.o $(obj)/error.o \
 	$(obj)/piggy.o $(obj)/cpuflags.o
 
 vmlinux-objs-$(CONFIG_EARLY_PRINTK) += $(obj)/early_serial_console.o
diff --git a/arch/x86/boot/compressed/error.c b/arch/x86/boot/compressed/error.c
new file mode 100644
index 0000000..6248740
--- /dev/null
+++ b/arch/x86/boot/compressed/error.c
@@ -0,0 +1,22 @@
+/*
+ * Callers outside of misc.c need access to the error reporting routines,
+ * but the *_putstr() functions need to stay in misc.c because of how
+ * memcpy() and memmove() are defined for the compressed boot environment.
+ */
+#include "misc.h"
+
+void warn(char *m)
+{
+	error_putstr("\n\n");
+	error_putstr(m);
+	error_putstr("\n\n");
+}
+
+void error(char *m)
+{
+	warn(m);
+	error_putstr(" -- System halted");
+
+	while (1)
+		asm("hlt");
+}
diff --git a/arch/x86/boot/compressed/error.h b/arch/x86/boot/compressed/error.h
new file mode 100644
index 0000000..2e59dac
--- /dev/null
+++ b/arch/x86/boot/compressed/error.h
@@ -0,0 +1,7 @@
+#ifndef BOOT_COMPRESSED_ERROR_H
+#define BOOT_COMPRESSED_ERROR_H
+
+void warn(char *m);
+void error(char *m);
+
+#endif /* BOOT_COMPRESSED_ERROR_H */
diff --git a/arch/x86/boot/compressed/kaslr.c b/arch/x86/boot/compressed/kaslr.c
index 8741a6d..f1818d9 100644
--- a/arch/x86/boot/compressed/kaslr.c
+++ b/arch/x86/boot/compressed/kaslr.c
@@ -10,6 +10,7 @@
  *
  */
 #include "misc.h"
+#include "error.h"
 
 #include <asm/msr.h>
 #include <asm/archrandom.h>
diff --git a/arch/x86/boot/compressed/misc.c b/arch/x86/boot/compressed/misc.c
index 8f0253d..9536d77 100644
--- a/arch/x86/boot/compressed/misc.c
+++ b/arch/x86/boot/compressed/misc.c
@@ -12,6 +12,7 @@
  */
 
 #include "misc.h"
+#include "error.h"
 #include "../string.h"
 #include "../voffset.h"
 
@@ -36,7 +37,6 @@
 #define memmove		memmove
 
 /* Functions used by the included decompressor code below. */
-static void error(char *m);
 void *memmove(void *dest, const void *src, size_t n);
 
 /*
@@ -169,22 +169,6 @@ void __puthex(unsigned long value)
 	}
 }
 
-void warn(char *m)
-{
-	error_putstr("\n\n");
-	error_putstr(m);
-	error_putstr("\n\n");
-}
-
-static void error(char *m)
-{
-	warn(m);
-	error_putstr(" -- System halted");
-
-	while (1)
-		asm("hlt");
-}
-
 #if CONFIG_X86_NEED_RELOCS
 static void handle_relocations(void *output, unsigned long output_len)
 {
diff --git a/arch/x86/boot/compressed/misc.h b/arch/x86/boot/compressed/misc.h
index e75f6cf..9887e0d 100644
--- a/arch/x86/boot/compressed/misc.h
+++ b/arch/x86/boot/compressed/misc.h
@@ -35,7 +35,6 @@ extern memptr free_mem_end_ptr;
 extern struct boot_params *boot_params;
 void __putstr(const char *s);
 void __puthex(unsigned long value);
-void warn(char *m);
 #define error_putstr(__x)  __putstr(__x)
 #define error_puthex(__x)  __puthex(__x)
 
diff --git a/arch/x86/boot/compressed/string.c b/arch/x86/boot/compressed/string.c
index 2befeca..faa4dc7 100644
--- a/arch/x86/boot/compressed/string.c
+++ b/arch/x86/boot/compressed/string.c
@@ -5,6 +5,8 @@
  * trust the gcc built-in implementations as they may do unexpected things
  * (e.g. FPU ops) in the minimal decompression stub execution environment.
  */
+#include "error.h"
+
 #include "../string.c"
 
 #ifdef CONFIG_X86_32

  reply	other threads:[~2016-05-03  7:47 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-05-02 22:50 [PATCH v5 0/2] x86/boot: Warn on future overlapping memcpy() use Kees Cook
2016-05-02 22:51 ` [PATCH v5 1/2] x86/boot: Extract error reporting functions Kees Cook
2016-05-03  7:45   ` tip-bot for Kees Cook [this message]
2016-05-02 22:51 ` [PATCH v5 2/2] x86/boot: Warn on future overlapping memcpy() use Kees Cook
2016-05-03  7:46   ` [tip:x86/boot] " tip-bot for Kees Cook

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-dc425a6e140bca99bdb4823e9909c9d9b8ba36b6@git.kernel.org \
    --to=tipbot@zytor.com \
    --cc=bhe@redhat.com \
    --cc=bp@alien8.de \
    --cc=bp@suse.de \
    --cc=brgerst@gmail.com \
    --cc=dvlasenk@redhat.com \
    --cc=gnomes@lxorguk.ukuu.org.uk \
    --cc=hpa@zytor.com \
    --cc=keescook@chromium.org \
    --cc=lasse.collin@tukaani.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-tip-commits@vger.kernel.org \
    --cc=luto@amacapital.net \
    --cc=mingo@kernel.org \
    --cc=peterz@infradead.org \
    --cc=tglx@linutronix.de \
    --cc=torvalds@linux-foundation.org \
    --cc=yinghai@kernel.org \
    /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

Powered by JetHome