Merge tag 'hardening-v6.9-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/kees...
[linux-2.6-microblaze.git] / arch / x86 / boot / compressed / misc.c
index 1844da2..4535242 100644 (file)
@@ -52,6 +52,7 @@ struct port_io_ops pio_ops;
 
 memptr free_mem_ptr;
 memptr free_mem_end_ptr;
+int spurious_nmi_count;
 
 static char *vidmem;
 static int vidport;
@@ -164,21 +165,34 @@ void __putstr(const char *s)
        outb(0xff & (pos >> 1), vidport+1);
 }
 
-void __puthex(unsigned long value)
+static noinline void __putnum(unsigned long value, unsigned int base,
+                             int mindig)
 {
-       char alpha[2] = "0";
-       int bits;
+       char buf[8*sizeof(value)+1];
+       char *p;
 
-       for (bits = sizeof(value) * 8 - 4; bits >= 0; bits -= 4) {
-               unsigned long digit = (value >> bits) & 0xf;
+       p = buf + sizeof(buf);
+       *--p = '\0';
 
-               if (digit < 0xA)
-                       alpha[0] = '0' + digit;
-               else
-                       alpha[0] = 'a' + (digit - 0xA);
+       while (mindig-- > 0 || value) {
+               unsigned char digit = value % base;
+               digit += (digit >= 10) ? ('a'-10) : '0';
+               *--p = digit;
 
-               __putstr(alpha);
+               value /= base;
        }
+
+       __putstr(p);
+}
+
+void __puthex(unsigned long value)
+{
+       __putnum(value, 16, sizeof(value)*2);
+}
+
+void __putdec(unsigned long value)
+{
+       __putnum(value, 10, 1);
 }
 
 #ifdef CONFIG_X86_NEED_RELOCS
@@ -357,6 +371,19 @@ unsigned long decompress_kernel(unsigned char *outbuf, unsigned long virt_addr,
        return entry;
 }
 
+/*
+ * Set the memory encryption xloadflag based on the mem_encrypt= command line
+ * parameter, if provided.
+ */
+static void parse_mem_encrypt(struct setup_header *hdr)
+{
+       int on = cmdline_find_option_bool("mem_encrypt=on");
+       int off = cmdline_find_option_bool("mem_encrypt=off");
+
+       if (on > off)
+               hdr->xloadflags |= XLF_MEM_ENCRYPTION;
+}
+
 /*
  * The compressed kernel image (ZO), has been moved so that its position
  * is against the end of the buffer used to hold the uncompressed kernel
@@ -387,6 +414,8 @@ asmlinkage __visible void *extract_kernel(void *rmode, unsigned char *output)
        /* Clear flags intended for solely in-kernel use. */
        boot_params_ptr->hdr.loadflags &= ~KASLR_FLAG;
 
+       parse_mem_encrypt(&boot_params_ptr->hdr);
+
        sanitize_boot_params(boot_params_ptr);
 
        if (boot_params_ptr->screen_info.orig_video_mode == 7) {
@@ -493,6 +522,12 @@ asmlinkage __visible void *extract_kernel(void *rmode, unsigned char *output)
        /* Disable exception handling before booting the kernel */
        cleanup_exception_handling();
 
+       if (spurious_nmi_count) {
+               error_putstr("Spurious early NMIs ignored: ");
+               error_putdec(spurious_nmi_count);
+               error_putstr("\n");
+       }
+
        return output + entry_offset;
 }