1. 07 11月, 2017 5 次提交
    • T
      x86/boot: Add early boot support when running with SEV active · 1958b5fc
      Tom Lendacky 提交于
      Early in the boot process, add checks to determine if the kernel is
      running with Secure Encrypted Virtualization (SEV) active.
      
      Checking for SEV requires checking that the kernel is running under a
      hypervisor (CPUID 0x00000001, bit 31), that the SEV feature is available
      (CPUID 0x8000001f, bit 1) and then checking a non-interceptable SEV MSR
      (0xc0010131, bit 0).
      
      This check is required so that during early compressed kernel booting the
      pagetables (both the boot pagetables and KASLR pagetables (if enabled) are
      updated to include the encryption mask so that when the kernel is
      decompressed into encrypted memory, it can boot properly.
      
      After the kernel is decompressed and continues booting the same logic is
      used to check if SEV is active and set a flag indicating so.  This allows
      to distinguish between SME and SEV, each of which have unique differences
      in how certain things are handled: e.g. DMA (always bounce buffered with
      SEV) or EFI tables (always access decrypted with SME).
      Signed-off-by: NTom Lendacky <thomas.lendacky@amd.com>
      Signed-off-by: NBrijesh Singh <brijesh.singh@amd.com>
      Signed-off-by: NThomas Gleixner <tglx@linutronix.de>
      Reviewed-by: NBorislav Petkov <bp@suse.de>
      Tested-by: NBorislav Petkov <bp@suse.de>
      Cc: Laura Abbott <labbott@redhat.com>
      Cc: Kees Cook <keescook@chromium.org>
      Cc: kvm@vger.kernel.org
      Cc: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
      Cc: Radim Krčmář <rkrcmar@redhat.com>
      Cc: Borislav Petkov <bp@alien8.de>
      Cc: Andy Lutomirski <luto@kernel.org>
      Cc: Paolo Bonzini <pbonzini@redhat.com>
      Cc: "Kirill A. Shutemov" <kirill.shutemov@linux.intel.com>
      Link: https://lkml.kernel.org/r/20171020143059.3291-13-brijesh.singh@amd.com
      1958b5fc
    • C
      x86/build: Add more generated files to the .gitignore file · d786f051
      Changbin Du 提交于
      Some of the files generated by the build process were not listed.
      Signed-off-by: NChangbin Du <changbin.du@intel.com>
      Cc: Linus Torvalds <torvalds@linux-foundation.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Thomas Gleixner <tglx@linutronix.de>
      Cc: yamada.masahiro@socionext.com
      Link: http://lkml.kernel.org/r/1509939179-7556-5-git-send-email-changbin.du@intel.comSigned-off-by: NIngo Molnar <mingo@kernel.org>
      d786f051
    • C
      x86/build: Specify -input-charset=utf-8 for mkisofs · c306ba7b
      Changbin Du 提交于
      It avoids the following warning triggered by newer versions of mkisofs:
      
          -input-charset not specified, using utf-8 (detected in locale settings)
      Signed-off-by: NChangbin Du <changbin.du@intel.com>
      Cc: Linus Torvalds <torvalds@linux-foundation.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Thomas Gleixner <tglx@linutronix.de>
      Cc: yamada.masahiro@socionext.com
      Link: http://lkml.kernel.org/r/1509939179-7556-4-git-send-email-changbin.du@intel.comSigned-off-by: NIngo Molnar <mingo@kernel.org>
      c306ba7b
    • C
      x86/build: Add new paths for isolinux.bin and ldlinux.c32 · 8a7546a0
      Changbin Du 提交于
      Recently I failed to build isoimage target, because the path of isolinux.bin
      changed to /usr/xxx/ISOLINUX/isolinux.bin, as well as ldlinux.c32 which
      changed to /usr/xxx/syslinux/modules/bios/ldlinux.c32.
      
      This patch improves the file search logic:
        - Show a error message instead of silent fail.
        - Add above new paths.
      Signed-off-by: NChangbin Du <changbin.du@intel.com>
      Cc: Linus Torvalds <torvalds@linux-foundation.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Thomas Gleixner <tglx@linutronix.de>
      Cc: yamada.masahiro@socionext.com
      Link: http://lkml.kernel.org/r/1509939179-7556-3-git-send-email-changbin.du@intel.comSigned-off-by: NIngo Molnar <mingo@kernel.org>
      8a7546a0
    • C
      x86/build: Factor out fdimage/isoimage generation commands to standalone script · 4366d57a
      Changbin Du 提交于
      The build messages for fdimage/isoimage generation are pretty unstructured,
      just the raw shell command blocks are printed.
      
      Emit shortened messages similar to existing kbuild messages, and move
      the Makefile commands into a separate shell script - which is much
      easier to handle.
      
      This patch factors out the commands used for fdimage/isoimage generation
      from arch/x86/boot/Makefile to a new script arch/x86/boot/genimage.sh.
      Then it adds the new kbuild command 'genimage' which invokes the new script.
      All fdimages/isoimage files are now generated by a call to 'genimage' with
      different parameters.
      
      Now 'make isoimage' becomes:
      
      	...
      	Kernel: arch/x86/boot/bzImage is ready  (#30)
      	  GENIMAGE arch/x86/boot/image.iso
      	Size of boot image is 4 sectors -> No emulation
      	 15.37% done, estimate finish Sun Nov  5 23:36:57 2017
      	 30.68% done, estimate finish Sun Nov  5 23:36:57 2017
      	 46.04% done, estimate finish Sun Nov  5 23:36:57 2017
      	 61.35% done, estimate finish Sun Nov  5 23:36:57 2017
      	 76.69% done, estimate finish Sun Nov  5 23:36:57 2017
      	 92.00% done, estimate finish Sun Nov  5 23:36:57 2017
      	Total translation table size: 2048
      	Total rockridge attributes bytes: 659
      	Total directory bytes: 0
      	Path table size(bytes): 10
      	Max brk space used 0
      	32608 extents written (63 MB)
      	Kernel: arch/x86/boot/image.iso is ready
      
      Before:
      
      	Kernel: arch/x86/boot/bzImage is ready  (#63)
      	rm -rf arch/x86/boot/isoimage
      	mkdir arch/x86/boot/isoimage
      	for i in lib lib64 share end ; do \
      		if [ -f /usr/$i/syslinux/isolinux.bin ] ; then \
      			cp /usr/$i/syslinux/isolinux.bin arch/x86/boot/isoimage ; \
      			if [ -f /usr/$i/syslinux/ldlinux.c32 ]; then \
      				cp /usr/$i/syslinux/ldlinux.c32 arch/x86/boot/isoimage ; \
      			fi ; \
      			break ; \
      		fi ; \
      		if [ $i = end ] ; then exit 1 ; fi ; \
      	done
      	...
      Suggested-by: NIngo Molnar <mingo@kernel.org>
      Signed-off-by: NChangbin Du <changbin.du@intel.com>
      Cc: Linus Torvalds <torvalds@linux-foundation.org>
      Cc: Masahiro Yamada <yamada.masahiro@socionext.com>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Thomas Gleixner <tglx@linutronix.de>
      Link: http://lkml.kernel.org/r/1509939179-7556-2-git-send-email-changbin.du@intel.comSigned-off-by: NIngo Molnar <mingo@kernel.org>
      4366d57a
  2. 02 11月, 2017 1 次提交
    • G
      License cleanup: add SPDX GPL-2.0 license identifier to files with no license · b2441318
      Greg Kroah-Hartman 提交于
      Many source files in the tree are missing licensing information, which
      makes it harder for compliance tools to determine the correct license.
      
      By default all files without license information are under the default
      license of the kernel, which is GPL version 2.
      
      Update the files which contain no license information with the 'GPL-2.0'
      SPDX license identifier.  The SPDX identifier is a legally binding
      shorthand, which can be used instead of the full boiler plate text.
      
      This patch is based on work done by Thomas Gleixner and Kate Stewart and
      Philippe Ombredanne.
      
      How this work was done:
      
      Patches were generated and checked against linux-4.14-rc6 for a subset of
      the use cases:
       - file had no licensing information it it.
       - file was a */uapi/* one with no licensing information in it,
       - file was a */uapi/* one with existing licensing information,
      
      Further patches will be generated in subsequent months to fix up cases
      where non-standard license headers were used, and references to license
      had to be inferred by heuristics based on keywords.
      
      The analysis to determine which SPDX License Identifier to be applied to
      a file was done in a spreadsheet of side by side results from of the
      output of two independent scanners (ScanCode & Windriver) producing SPDX
      tag:value files created by Philippe Ombredanne.  Philippe prepared the
      base worksheet, and did an initial spot review of a few 1000 files.
      
      The 4.13 kernel was the starting point of the analysis with 60,537 files
      assessed.  Kate Stewart did a file by file comparison of the scanner
      results in the spreadsheet to determine which SPDX license identifier(s)
      to be applied to the file. She confirmed any determination that was not
      immediately clear with lawyers working with the Linux Foundation.
      
      Criteria used to select files for SPDX license identifier tagging was:
       - Files considered eligible had to be source code files.
       - Make and config files were included as candidates if they contained >5
         lines of source
       - File already had some variant of a license header in it (even if <5
         lines).
      
      All documentation files were explicitly excluded.
      
      The following heuristics were used to determine which SPDX license
      identifiers to apply.
      
       - when both scanners couldn't find any license traces, file was
         considered to have no license information in it, and the top level
         COPYING file license applied.
      
         For non */uapi/* files that summary was:
      
         SPDX license identifier                            # files
         ---------------------------------------------------|-------
         GPL-2.0                                              11139
      
         and resulted in the first patch in this series.
      
         If that file was a */uapi/* path one, it was "GPL-2.0 WITH
         Linux-syscall-note" otherwise it was "GPL-2.0".  Results of that was:
      
         SPDX license identifier                            # files
         ---------------------------------------------------|-------
         GPL-2.0 WITH Linux-syscall-note                        930
      
         and resulted in the second patch in this series.
      
       - if a file had some form of licensing information in it, and was one
         of the */uapi/* ones, it was denoted with the Linux-syscall-note if
         any GPL family license was found in the file or had no licensing in
         it (per prior point).  Results summary:
      
         SPDX license identifier                            # files
         ---------------------------------------------------|------
         GPL-2.0 WITH Linux-syscall-note                       270
         GPL-2.0+ WITH Linux-syscall-note                      169
         ((GPL-2.0 WITH Linux-syscall-note) OR BSD-2-Clause)    21
         ((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Clause)    17
         LGPL-2.1+ WITH Linux-syscall-note                      15
         GPL-1.0+ WITH Linux-syscall-note                       14
         ((GPL-2.0+ WITH Linux-syscall-note) OR BSD-3-Clause)    5
         LGPL-2.0+ WITH Linux-syscall-note                       4
         LGPL-2.1 WITH Linux-syscall-note                        3
         ((GPL-2.0 WITH Linux-syscall-note) OR MIT)              3
         ((GPL-2.0 WITH Linux-syscall-note) AND MIT)             1
      
         and that resulted in the third patch in this series.
      
       - when the two scanners agreed on the detected license(s), that became
         the concluded license(s).
      
       - when there was disagreement between the two scanners (one detected a
         license but the other didn't, or they both detected different
         licenses) a manual inspection of the file occurred.
      
       - In most cases a manual inspection of the information in the file
         resulted in a clear resolution of the license that should apply (and
         which scanner probably needed to revisit its heuristics).
      
       - When it was not immediately clear, the license identifier was
         confirmed with lawyers working with the Linux Foundation.
      
       - If there was any question as to the appropriate license identifier,
         the file was flagged for further research and to be revisited later
         in time.
      
      In total, over 70 hours of logged manual review was done on the
      spreadsheet to determine the SPDX license identifiers to apply to the
      source files by Kate, Philippe, Thomas and, in some cases, confirmation
      by lawyers working with the Linux Foundation.
      
      Kate also obtained a third independent scan of the 4.13 code base from
      FOSSology, and compared selected files where the other two scanners
      disagreed against that SPDX file, to see if there was new insights.  The
      Windriver scanner is based on an older version of FOSSology in part, so
      they are related.
      
      Thomas did random spot checks in about 500 files from the spreadsheets
      for the uapi headers and agreed with SPDX license identifier in the
      files he inspected. For the non-uapi files Thomas did random spot checks
      in about 15000 files.
      
      In initial set of patches against 4.14-rc6, 3 files were found to have
      copy/paste license identifier errors, and have been fixed to reflect the
      correct identifier.
      
      Additionally Philippe spent 10 hours this week doing a detailed manual
      inspection and review of the 12,461 patched files from the initial patch
      version early this week with:
       - a full scancode scan run, collecting the matched texts, detected
         license ids and scores
       - reviewing anything where there was a license detected (about 500+
         files) to ensure that the applied SPDX license was correct
       - reviewing anything where there was no detection but the patch license
         was not GPL-2.0 WITH Linux-syscall-note to ensure that the applied
         SPDX license was correct
      
      This produced a worksheet with 20 files needing minor correction.  This
      worksheet was then exported into 3 different .csv files for the
      different types of files to be modified.
      
      These .csv files were then reviewed by Greg.  Thomas wrote a script to
      parse the csv files and add the proper SPDX tag to the file, in the
      format that the file expected.  This script was further refined by Greg
      based on the output to detect more types of files automatically and to
      distinguish between header and source .c files (which need different
      comment types.)  Finally Greg ran the script using the .csv files to
      generate the patches.
      Reviewed-by: NKate Stewart <kstewart@linuxfoundation.org>
      Reviewed-by: NPhilippe Ombredanne <pombredanne@nexb.com>
      Reviewed-by: NThomas Gleixner <tglx@linutronix.de>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      b2441318
  3. 31 8月, 2017 1 次提交
    • N
      x86/boot/KASLR: Work around firmware bugs by excluding EFI_BOOT_SERVICES_* and... · 0982adc7
      Naoya Horiguchi 提交于
      x86/boot/KASLR: Work around firmware bugs by excluding EFI_BOOT_SERVICES_* and EFI_LOADER_* from KASLR's choice
      
      There's a potential bug in how we select the KASLR kernel address n
      the early boot code.
      
      The KASLR boot code currently chooses the kernel image's physical memory
      location from E820_TYPE_RAM regions by walking over all e820 entries.
      
      E820_TYPE_RAM includes EFI_BOOT_SERVICES_CODE and EFI_BOOT_SERVICES_DATA
      as well, so those regions can end up hosting the kernel image. According to
      the UEFI spec, all memory regions marked as EfiBootServicesCode and
      EfiBootServicesData are available as free memory after the first call
      to ExitBootServices(). I.e. so such regions should be usable for the
      kernel, per spec.
      
      In real life however, we have workarounds for broken x86 firmware,
      where we keep such regions reserved until SetVirtualAddressMap() is done.
      
      See the following code in should_map_region():
      
      	static bool should_map_region(efi_memory_desc_t *md)
      	{
      		...
      		/*
      		 * Map boot services regions as a workaround for buggy
      		 * firmware that accesses them even when they shouldn't.
      		 *
      		 * See efi_{reserve,free}_boot_services().
      		 */
      		if (md->type =3D=3D EFI_BOOT_SERVICES_CODE ||
      			md->type =3D=3D EFI_BOOT_SERVICES_DATA)
      				return false;
      
      This workaround suppressed a boot crash, but potential issues still
      remain because no one prevents the regions from overlapping with kernel
      image by KASLR.
      
      So let's make sure that EFI_BOOT_SERVICES_{CODE|DATA} regions are never
      chosen as kernel memory for the workaround to work fine.
      
      Furthermore, EFI_LOADER_{CODE|DATA} regions are also excluded because
      they can be used after ExitBootServices() as defined in EFI spec.
      
      As a result, we choose kernel address only from EFI_CONVENTIONAL_MEMORY
      which is the only memory type we know to be safely free.
      Signed-off-by: NNaoya Horiguchi <n-horiguchi@ah.jp.nec.com>
      Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org>
      Cc: Baoquan He <bhe@redhat.com>
      Cc: Junichi Nomura <j-nomura@ce.jp.nec.com>
      Cc: Kees Cook <keescook@chromium.org>
      Cc: Linus Torvalds <torvalds@linux-foundation.org>
      Cc: Matt Fleming <matt@codeblueprint.co.uk>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Thomas Garnier <thgarnie@google.com>
      Cc: Thomas Gleixner <tglx@linutronix.de>
      Cc: fanc.fnst@cn.fujitsu.com
      Cc: izumi.taku@jp.fujitsu.com
      Link: http://lkml.kernel.org/r/20170828074444.GC23181@hori1.linux.bs1.fc.nec.co.jp
      [ Rewrote/fixed/clarified the changelog and the in code comments. ]
      Signed-off-by: NIngo Molnar <mingo@kernel.org>
      0982adc7
  4. 29 8月, 2017 5 次提交
    • J
      x86/boot: Prevent faulty bootparams.screeninfo from causing harm · fb1cc2f9
      Jan H. Schönherr 提交于
      If a zero for the number of lines manages to slip through, scroll()
      may underflow some offset calculations, causing accesses outside the
      video memory.
      
      Make the check in __putstr() more pessimistic to prevent that.
      Signed-off-by: NJan H. Schönherr <jschoenh@amazon.de>
      Cc: H. Peter Anvin <hpa@zytor.com>
      Cc: Kees Cook <keescook@chromium.org>
      Cc: Linus Torvalds <torvalds@linux-foundation.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Thomas Gleixner <tglx@linutronix.de>
      Link: http://lkml.kernel.org/r/1503858223-14983-1-git-send-email-jschoenh@amazon.deSigned-off-by: NIngo Molnar <mingo@kernel.org>
      fb1cc2f9
    • J
      x86/boot: Provide more slack space during decompression · 5746f055
      Jan H. Schönherr 提交于
      The current slack space is not enough for LZ4, which has a worst case
      overhead of 0.4% for data that cannot be further compressed. With
      an LZ4 compressed kernel with an embedded initrd, the output is likely
      to overwrite the input.
      
      Increase the slack space to avoid that.
      Signed-off-by: NJan H. Schönherr <jschoenh@amazon.de>
      Cc: H. Peter Anvin <hpa@zytor.com>
      Cc: Kees Cook <keescook@chromium.org>
      Cc: Linus Torvalds <torvalds@linux-foundation.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Thomas Gleixner <tglx@linutronix.de>
      Link: http://lkml.kernel.org/r/1503842124-29718-1-git-send-email-jschoenh@amazon.deSigned-off-by: NIngo Molnar <mingo@kernel.org>
      5746f055
    • J
      x86/boot/64: Extract efi_pe_entry() from startup_64() · 9e085cef
      Jiri Slaby 提交于
      Similarly to the 32-bit code, efi_pe_entry body() is somehow squashed into
      startup_64().
      
      In the old days, we forced startup_64() to start at offset 0x200 and efi_pe_entry()
      to start at 0x210. But this requirement was removed long time ago, in:
      
        99f857db ("x86, build: Dynamically find entry points in compressed startup code")
      
      The way it is now makes the code less readable and illogical. Given
      we can now safely extract the inlined efi_pe_entry() body from
      startup_64() into a separate function, we do so.
      
      We also annotate the function appropriatelly by ENTRY+ENDPROC.
      
      ABI offsets are preserved:
      
        0000000000000000 T startup_32
        0000000000000200 T startup_64
        0000000000000390 T efi64_stub_entry
      
      On the top-level, it looked like:
      
      	.org 0x200
      	ENTRY(startup_64)
      	#ifdef CONFIG_EFI_STUB		; start of inlined
      		jmp     preferred_addr
      	GLOBAL(efi_pe_entry)
      		... ; a lot of assembly (efi_pe_entry)
      		leaq    preferred_addr(%rax), %rax
      		jmp     *%rax
      	preferred_addr:
      	#endif				; end of inlined
      		... ; a lot of assembly (startup_64)
      	ENDPROC(startup_64)
      
      And it is now converted into:
      
      	.org 0x200
      	ENTRY(startup_64)
      		... ; a lot of assembly (startup_64)
      	ENDPROC(startup_64)
      
      	#ifdef CONFIG_EFI_STUB
      	ENTRY(efi_pe_entry)
      		... ; a lot of assembly (efi_pe_entry)
      		leaq    startup_64(%rax), %rax
      		jmp     *%rax
      	ENDPROC(efi_pe_entry)
      	#endif
      Signed-off-by: NJiri Slaby <jslaby@suse.cz>
      Cc: Andy Lutomirski <luto@kernel.org>
      Cc: Borislav Petkov <bp@alien8.de>
      Cc: Brian Gerst <brgerst@gmail.com>
      Cc: David Woodhouse <dwmw2@infradead.org>
      Cc: Denys Vlasenko <dvlasenk@redhat.com>
      Cc: H. Peter Anvin <hpa@zytor.com>
      Cc: Josh Poimboeuf <jpoimboe@redhat.com>
      Cc: Linus Torvalds <torvalds@linux-foundation.org>
      Cc: Matt Fleming <matt@codeblueprint.co.uk>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Thomas Gleixner <tglx@linutronix.de>
      Cc: ard.biesheuvel@linaro.org
      Cc: linux-efi@vger.kernel.org
      Link: http://lkml.kernel.org/r/20170824073327.4129-2-jslaby@suse.czSigned-off-by: NIngo Molnar <mingo@kernel.org>
      9e085cef
    • J
      x86/boot/32: Extract efi_pe_entry() from startup_32() · f4dee0bb
      Jiri Slaby 提交于
      The efi_pe_entry() body is somehow squashed into startup_32(). In the old days,
      we forced startup_32() to start at offset 0x00 and efi_pe_entry() to start
      at 0x10.
      
      But this requirement was removed long time ago, in:
      
        99f857db ("x86, build: Dynamically find entry points in compressed startup code")
      
      The way it is now makes the code less readable and illogical. Given
      we can now safely extract the inlined efi_pe_entry() body from
      startup_32() into a separate function, we do so and we separate it to two
      functions as they are marked already: efi_pe_entry() + efi32_stub_entry().
      
      We also annotate the functions appropriatelly by ENTRY+ENDPROC.
      
      ABI offset is preserved:
      
        0000   128 FUNC    GLOBAL DEFAULT    6 startup_32
        0080    60 FUNC    GLOBAL DEFAULT    6 efi_pe_entry
        00bc    68 FUNC    GLOBAL DEFAULT    6 efi32_stub_entry
      
      On the top-level, it looked like this:
      
      	ENTRY(startup_32)
      	#ifdef CONFIG_EFI_STUB		; start of inlined
      		jmp     preferred_addr
      	ENTRY(efi_pe_entry)
      		... ; a lot of assembly (efi_pe_entry)
      	ENTRY(efi32_stub_entry)
      		... ; a lot of assembly (efi32_stub_entry)
      		leal    preferred_addr(%eax), %eax
      		jmp     *%eax
      	preferred_addr:
      	#endif				; end of inlined
      		... ; a lot of assembly (startup_32)
      	ENDPROC(startup_32)
      
      And it is now converted into:
      
      	ENTRY(startup_32)
      		... ; a lot of assembly (startup_32)
      	ENDPROC(startup_32)
      
      	#ifdef CONFIG_EFI_STUB
      	ENTRY(efi_pe_entry)
      		... ; a lot of assembly (efi_pe_entry)
      	ENDPROC(efi_pe_entry)
      
      	ENTRY(efi32_stub_entry)
      		... ; a lot of assembly (efi32_stub_entry)
      		leal    startup_32(%eax), %eax
      		jmp     *%eax
      	ENDPROC(efi32_stub_entry)
      	#endif
      Signed-off-by: NJiri Slaby <jslaby@suse.cz>
      Cc: Andy Lutomirski <luto@kernel.org>
      Cc: Borislav Petkov <bp@alien8.de>
      Cc: Brian Gerst <brgerst@gmail.com>
      Cc: David Woodhouse <dwmw2@infradead.org>
      Cc: Denys Vlasenko <dvlasenk@redhat.com>
      Cc: H. Peter Anvin <hpa@zytor.com>
      Cc: Josh Poimboeuf <jpoimboe@redhat.com>
      Cc: Linus Torvalds <torvalds@linux-foundation.org>
      Cc: Matt Fleming <matt@codeblueprint.co.uk>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Thomas Gleixner <tglx@linutronix.de>
      Cc: ard.biesheuvel@linaro.org
      Cc: linux-efi@vger.kernel.org
      Link: http://lkml.kernel.org/r/20170824073327.4129-1-jslaby@suse.czSigned-off-by: NIngo Molnar <mingo@kernel.org>
      f4dee0bb
    • T
      x86/idt: Unify gate_struct handling for 32/64-bit kernels · 64b163fa
      Thomas Gleixner 提交于
      The first 32 bits of gate struct are the same for 32 and 64 bit kernels.
      
      The 32-bit version uses desc_struct and no designated data structure,
      so we need different accessors for 32 and 64 bit kernels.
      
      Aside of that the macros which are necessary to build the 32-bit
      gate descriptor are horrible to read.
      
      Unify the gate structs and switch all code fiddling with it over.
      Signed-off-by: NThomas Gleixner <tglx@linutronix.de>
      Cc: Andy Lutomirski <luto@kernel.org>
      Cc: Borislav Petkov <bp@alien8.de>
      Cc: Brian Gerst <brgerst@gmail.com>
      Cc: Denys Vlasenko <dvlasenk@redhat.com>
      Cc: H. Peter Anvin <hpa@zytor.com>
      Cc: Josh Poimboeuf <jpoimboe@redhat.com>
      Cc: Linus Torvalds <torvalds@linux-foundation.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Steven Rostedt <rostedt@goodmis.org>
      Link: http://lkml.kernel.org/r/20170828064957.861974317@linutronix.deSigned-off-by: NIngo Molnar <mingo@kernel.org>
      64b163fa
  5. 26 8月, 2017 1 次提交
  6. 17 8月, 2017 2 次提交
    • B
      x86/boot/KASLR: Prefer mirrored memory regions for the kernel physical address · c05cd797
      Baoquan He 提交于
      Currently KASLR will parse all e820 entries of RAM type and add all
      candidate positions into the slots array. After that we choose one slot
      randomly as the new position which the kernel will be decompressed into
      and run at.
      
      On systems with EFI enabled, e820 memory regions are coming from EFI
      memory regions by combining adjacent regions.
      
      These EFI memory regions have various attributes, and the "mirrored"
      attribute is one of them. The physical memory region whose descriptors
      in EFI memory map has EFI_MEMORY_MORE_RELIABLE attribute (bit: 16) are
      mirrored. The address range mirroring feature of the kernel arranges such
      mirrored regions into normal zones and other regions into movable zones.
      
      With the mirroring feature enabled, the code and data of the kernel can only
      be located in the more reliable mirrored regions. However, the current KASLR
      code doesn't check EFI memory entries, and could choose a new kernel position
      in non-mirrored regions. This will break the intended functionality of the
      address range mirroring feature.
      
      To fix this, if EFI is detected, iterate EFI memory map and pick the mirrored
      region to process for adding candidate of randomization slot. If EFI is disabled
      or no mirrored region found, still process the e820 memory map.
      Signed-off-by: NBaoquan He <bhe@redhat.com>
      Cc: Linus Torvalds <torvalds@linux-foundation.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Thomas Gleixner <tglx@linutronix.de>
      Cc: ard.biesheuvel@linaro.org
      Cc: fanc.fnst@cn.fujitsu.com
      Cc: izumi.taku@jp.fujitsu.com
      Cc: keescook@chromium.org
      Cc: linux-efi@vger.kernel.org
      Cc: matt@codeblueprint.co.uk
      Cc: n-horiguchi@ah.jp.nec.com
      Cc: thgarnie@google.com
      Link: http://lkml.kernel.org/r/1502722464-20614-3-git-send-email-bhe@redhat.com
      [ Rewrote most of the text. ]
      Signed-off-by: NIngo Molnar <mingo@kernel.org>
      c05cd797
    • B
      efi: Introduce efi_early_memdesc_ptr to get pointer to memmap descriptor · 02e43c2d
      Baoquan He 提交于
      The existing map iteration helper for_each_efi_memory_desc_in_map can
      only be used after the kernel initializes the EFI subsystem to set up
      struct efi_memory_map.
      
      Before that we also need iterate map descriptors which are stored in several
      intermediate structures, like struct efi_boot_memmap for arch independent
      usage and struct efi_info for x86 arch only.
      
      Introduce efi_early_memdesc_ptr() to get pointer to a map descriptor, and
      replace several places where that primitive is open coded.
      Signed-off-by: NBaoquan He <bhe@redhat.com>
      [ Various improvements to the text. ]
      Acked-by: NMatt Fleming <matt@codeblueprint.co.uk>
      Cc: Linus Torvalds <torvalds@linux-foundation.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Thomas Gleixner <tglx@linutronix.de>
      Cc: ard.biesheuvel@linaro.org
      Cc: fanc.fnst@cn.fujitsu.com
      Cc: izumi.taku@jp.fujitsu.com
      Cc: keescook@chromium.org
      Cc: linux-efi@vger.kernel.org
      Cc: n-horiguchi@ah.jp.nec.com
      Cc: thgarnie@google.com
      Link: http://lkml.kernel.org/r/20170816134651.GF21273@x1Signed-off-by: NIngo Molnar <mingo@kernel.org>
      02e43c2d
  7. 28 7月, 2017 1 次提交
    • M
      x86/boot: Disable the address-of-packed-member compiler warning · 20c6c189
      Matthias Kaehlcke 提交于
      The clang warning 'address-of-packed-member' is disabled for the general
      kernel code, also disable it for the x86 boot code.
      
      This suppresses a bunch of warnings like this when building with clang:
      
      ./arch/x86/include/asm/processor.h:535:30: warning: taking address of
        packed member 'sp0' of class or structure 'x86_hw_tss' may result in an
        unaligned pointer value [-Waddress-of-packed-member]
          return this_cpu_read_stable(cpu_tss.x86_tss.sp0);
                                      ^~~~~~~~~~~~~~~~~~~
      ./arch/x86/include/asm/percpu.h:391:59: note: expanded from macro
        'this_cpu_read_stable'
          #define this_cpu_read_stable(var)       percpu_stable_op("mov", var)
                                                                          ^~~
      ./arch/x86/include/asm/percpu.h:228:16: note: expanded from macro
        'percpu_stable_op'
          : "p" (&(var)));
                   ^~~
      Signed-off-by: NMatthias Kaehlcke <mka@chromium.org>
      Cc: Doug Anderson <dianders@chromium.org>
      Cc: Linus Torvalds <torvalds@linux-foundation.org>
      Cc: Masahiro Yamada <yamada.masahiro@socionext.com>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Thomas Gleixner <tglx@linutronix.de>
      Link: http://lkml.kernel.org/r/20170725215053.135586-1-mka@chromium.orgSigned-off-by: NIngo Molnar <mingo@kernel.org>
      20c6c189
  8. 25 7月, 2017 1 次提交
  9. 20 7月, 2017 1 次提交
  10. 18 7月, 2017 4 次提交
    • T
      x86/mm: Provide general kernel support for memory encryption · 21729f81
      Tom Lendacky 提交于
      Changes to the existing page table macros will allow the SME support to
      be enabled in a simple fashion with minimal changes to files that use these
      macros.  Since the memory encryption mask will now be part of the regular
      pagetable macros, we introduce two new macros (_PAGE_TABLE_NOENC and
      _KERNPG_TABLE_NOENC) to allow for early pagetable creation/initialization
      without the encryption mask before SME becomes active.  Two new pgprot()
      macros are defined to allow setting or clearing the page encryption mask.
      
      The FIXMAP_PAGE_NOCACHE define is introduced for use with MMIO.  SME does
      not support encryption for MMIO areas so this define removes the encryption
      mask from the page attribute.
      
      Two new macros are introduced (__sme_pa() / __sme_pa_nodebug()) to allow
      creating a physical address with the encryption mask.  These are used when
      working with the cr3 register so that the PGD can be encrypted. The current
      __va() macro is updated so that the virtual address is generated based off
      of the physical address without the encryption mask thus allowing the same
      virtual address to be generated regardless of whether encryption is enabled
      for that physical location or not.
      
      Also, an early initialization function is added for SME.  If SME is active,
      this function:
      
       - Updates the early_pmd_flags so that early page faults create mappings
         with the encryption mask.
      
       - Updates the __supported_pte_mask to include the encryption mask.
      
       - Updates the protection_map entries to include the encryption mask so
         that user-space allocations will automatically have the encryption mask
         applied.
      Signed-off-by: NTom Lendacky <thomas.lendacky@amd.com>
      Reviewed-by: NThomas Gleixner <tglx@linutronix.de>
      Reviewed-by: NBorislav Petkov <bp@suse.de>
      Cc: Alexander Potapenko <glider@google.com>
      Cc: Andrey Ryabinin <aryabinin@virtuozzo.com>
      Cc: Andy Lutomirski <luto@kernel.org>
      Cc: Arnd Bergmann <arnd@arndb.de>
      Cc: Borislav Petkov <bp@alien8.de>
      Cc: Brijesh Singh <brijesh.singh@amd.com>
      Cc: Dave Young <dyoung@redhat.com>
      Cc: Dmitry Vyukov <dvyukov@google.com>
      Cc: Jonathan Corbet <corbet@lwn.net>
      Cc: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
      Cc: Larry Woodman <lwoodman@redhat.com>
      Cc: Linus Torvalds <torvalds@linux-foundation.org>
      Cc: Matt Fleming <matt@codeblueprint.co.uk>
      Cc: Michael S. Tsirkin <mst@redhat.com>
      Cc: Paolo Bonzini <pbonzini@redhat.com>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Radim Krčmář <rkrcmar@redhat.com>
      Cc: Rik van Riel <riel@redhat.com>
      Cc: Toshimitsu Kani <toshi.kani@hpe.com>
      Cc: kasan-dev@googlegroups.com
      Cc: kvm@vger.kernel.org
      Cc: linux-arch@vger.kernel.org
      Cc: linux-doc@vger.kernel.org
      Cc: linux-efi@vger.kernel.org
      Cc: linux-mm@kvack.org
      Link: http://lkml.kernel.org/r/b36e952c4c39767ae7f0a41cf5345adf27438480.1500319216.git.thomas.lendacky@amd.comSigned-off-by: NIngo Molnar <mingo@kernel.org>
      21729f81
    • B
      x86/boot/KASLR: Rename process_e820_entry() into process_mem_region() · 27aac205
      Baoquan He 提交于
      Now process_e820_entry() is not limited to e820 entry processing, rename
      it to process_mem_region(). And adjust the code comment accordingly.
      Signed-off-by: NBaoquan He <bhe@redhat.com>
      Acked-by: NKees Cook <keescook@chromium.org>
      Cc: Linus Torvalds <torvalds@linux-foundation.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Thomas Gleixner <tglx@linutronix.de>
      Cc: fanc.fnst@cn.fujitsu.com
      Cc: izumi.taku@jp.fujitsu.com
      Cc: matt@codeblueprint.co.uk
      Cc: thgarnie@google.com
      Link: http://lkml.kernel.org/r/1499603862-11516-4-git-send-email-bhe@redhat.comSigned-off-by: NIngo Molnar <mingo@kernel.org>
      27aac205
    • B
      x86/boot/KASLR: Switch to pass struct mem_vector to process_e820_entry() · 87891b01
      Baoquan He 提交于
      This makes process_e820_entry() be able to process any kind of memory
      region.
      Signed-off-by: NBaoquan He <bhe@redhat.com>
      Acked-by: NKees Cook <keescook@chromium.org>
      Cc: Linus Torvalds <torvalds@linux-foundation.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Thomas Gleixner <tglx@linutronix.de>
      Cc: fanc.fnst@cn.fujitsu.com
      Cc: izumi.taku@jp.fujitsu.com
      Cc: matt@codeblueprint.co.uk
      Cc: thgarnie@google.com
      Link: http://lkml.kernel.org/r/1499603862-11516-3-git-send-email-bhe@redhat.comSigned-off-by: NIngo Molnar <mingo@kernel.org>
      87891b01
    • B
      x86/boot/KASLR: Wrap e820 entries walking code into new function process_e820_entries() · f62995c9
      Baoquan He 提交于
      The original function process_e820_entry() only takes care of each
      e820 entry passed.
      
      And move the E820_TYPE_RAM checking logic into process_e820_entries().
      
      And remove the redundent local variable 'addr' definition in
      find_random_phys_addr().
      Signed-off-by: NBaoquan He <bhe@redhat.com>
      Acked-by: NKees Cook <keescook@chromium.org>
      Cc: Linus Torvalds <torvalds@linux-foundation.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Thomas Gleixner <tglx@linutronix.de>
      Cc: fanc.fnst@cn.fujitsu.com
      Cc: izumi.taku@jp.fujitsu.com
      Cc: matt@codeblueprint.co.uk
      Cc: thgarnie@google.com
      Link: http://lkml.kernel.org/r/1499603862-11516-2-git-send-email-bhe@redhat.comSigned-off-by: NIngo Molnar <mingo@kernel.org>
      f62995c9
  11. 13 7月, 2017 1 次提交
    • D
      include/linux/string.h: add the option of fortified string.h functions · 6974f0c4
      Daniel Micay 提交于
      This adds support for compiling with a rough equivalent to the glibc
      _FORTIFY_SOURCE=1 feature, providing compile-time and runtime buffer
      overflow checks for string.h functions when the compiler determines the
      size of the source or destination buffer at compile-time.  Unlike glibc,
      it covers buffer reads in addition to writes.
      
      GNU C __builtin_*_chk intrinsics are avoided because they would force a
      much more complex implementation.  They aren't designed to detect read
      overflows and offer no real benefit when using an implementation based
      on inline checks.  Inline checks don't add up to much code size and
      allow full use of the regular string intrinsics while avoiding the need
      for a bunch of _chk functions and per-arch assembly to avoid wrapper
      overhead.
      
      This detects various overflows at compile-time in various drivers and
      some non-x86 core kernel code.  There will likely be issues caught in
      regular use at runtime too.
      
      Future improvements left out of initial implementation for simplicity,
      as it's all quite optional and can be done incrementally:
      
      * Some of the fortified string functions (strncpy, strcat), don't yet
        place a limit on reads from the source based on __builtin_object_size of
        the source buffer.
      
      * Extending coverage to more string functions like strlcat.
      
      * It should be possible to optionally use __builtin_object_size(x, 1) for
        some functions (C strings) to detect intra-object overflows (like
        glibc's _FORTIFY_SOURCE=2), but for now this takes the conservative
        approach to avoid likely compatibility issues.
      
      * The compile-time checks should be made available via a separate config
        option which can be enabled by default (or always enabled) once enough
        time has passed to get the issues it catches fixed.
      
      Kees said:
       "This is great to have. While it was out-of-tree code, it would have
        blocked at least CVE-2016-3858 from being exploitable (improper size
        argument to strlcpy()). I've sent a number of fixes for
        out-of-bounds-reads that this detected upstream already"
      
      [arnd@arndb.de: x86: fix fortified memcpy]
        Link: http://lkml.kernel.org/r/20170627150047.660360-1-arnd@arndb.de
      [keescook@chromium.org: avoid panic() in favor of BUG()]
        Link: http://lkml.kernel.org/r/20170626235122.GA25261@beast
      [keescook@chromium.org: move from -mm, add ARCH_HAS_FORTIFY_SOURCE, tweak Kconfig help]
      Link: http://lkml.kernel.org/r/20170526095404.20439-1-danielmicay@gmail.com
      Link: http://lkml.kernel.org/r/1497903987-21002-8-git-send-email-keescook@chromium.orgSigned-off-by: NDaniel Micay <danielmicay@gmail.com>
      Signed-off-by: NKees Cook <keescook@chromium.org>
      Signed-off-by: NArnd Bergmann <arnd@arndb.de>
      Acked-by: NKees Cook <keescook@chromium.org>
      Cc: Mark Rutland <mark.rutland@arm.com>
      Cc: Daniel Axtens <dja@axtens.net>
      Cc: Rasmus Villemoes <linux@rasmusvillemoes.dk>
      Cc: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
      Cc: Chris Metcalf <cmetcalf@ezchip.com>
      Cc: Thomas Gleixner <tglx@linutronix.de>
      Cc: "H. Peter Anvin" <hpa@zytor.com>
      Cc: Ingo Molnar <mingo@elte.hu>
      Signed-off-by: NAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
      6974f0c4
  12. 30 6月, 2017 3 次提交
  13. 24 6月, 2017 1 次提交
  14. 13 6月, 2017 5 次提交
  15. 05 6月, 2017 1 次提交
  16. 31 5月, 2017 1 次提交
    • A
      x86/KASLR: Use the right memcpy() implementation · 5b8b9cf7
      Arnd Bergmann 提交于
      The decompressor has its own implementation of the string functions,
      but has to include the right header to get those, while implicitly
      including linux/string.h may result in a link error:
      
        arch/x86/boot/compressed/kaslr.o: In function `choose_random_location':
        kaslr.c:(.text+0xf51): undefined reference to `_mmx_memcpy'
      
      This has appeared now as KASLR started using memcpy(), via:
      
      	d52e7d5a ("x86/KASLR: Parse all 'memmap=' boot option entries")
      
      Other files in the decompressor already do the same thing.
      Signed-off-by: NArnd Bergmann <arnd@arndb.de>
      Acked-by: NBaoquan He <bhe@redhat.com>
      Cc: Dave Jiang <dave.jiang@intel.com>
      Cc: Kees Cook <keescook@chromium.org>
      Cc: Linus Torvalds <torvalds@linux-foundation.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Thomas Garnier <thgarnie@google.com>
      Cc: Thomas Gleixner <tglx@linutronix.de>
      Link: http://lkml.kernel.org/r/20170530091446.1000183-1-arnd@arndb.deSigned-off-by: NIngo Molnar <mingo@kernel.org>
      5b8b9cf7
  17. 24 5月, 2017 2 次提交
  18. 21 5月, 2017 1 次提交
  19. 08 5月, 2017 1 次提交
    • X
      x86/mm: Add support for gbpages to kernel_ident_mapping_init() · 66aad4fd
      Xunlei Pang 提交于
      Kernel identity mappings on x86-64 kernels are created in two
      ways: by the early x86 boot code, or by kernel_ident_mapping_init().
      
      Native kernels (which is the dominant usecase) use the former,
      but the kexec and the hibernation code uses kernel_ident_mapping_init().
      
      There's a subtle difference between these two ways of how identity
      mappings are created, the current kernel_ident_mapping_init() code
      creates identity mappings always using 2MB page(PMD level) - while
      the native kernel boot path also utilizes gbpages where available.
      
      This difference is suboptimal both for performance and for memory
      usage: kernel_ident_mapping_init() needs to allocate pages for the
      page tables when creating the new identity mappings.
      
      This patch adds 1GB page(PUD level) support to kernel_ident_mapping_init()
      to address these concerns.
      
      The primary advantage would be better TLB coverage/performance,
      because we'd utilize 1GB TLBs instead of 2MB ones.
      
      It is also useful for machines with large number of memory to
      save paging structure allocations(around 4MB/TB using 2MB page)
      when setting identity mappings for all the memory, after using
      1GB page it will consume only 8KB/TB.
      
      ( Note that this change alone does not activate gbpages in kexec,
        we are doing that in a separate patch. )
      Signed-off-by: NXunlei Pang <xlpang@redhat.com>
      Cc: Andy Lutomirski <luto@kernel.org>
      Cc: Borislav Petkov <bp@alien8.de>
      Cc: Brian Gerst <brgerst@gmail.com>
      Cc: Dave Young <dyoung@redhat.com>
      Cc: Denys Vlasenko <dvlasenk@redhat.com>
      Cc: Eric Biederman <ebiederm@xmission.com>
      Cc: H. Peter Anvin <hpa@zytor.com>
      Cc: Josh Poimboeuf <jpoimboe@redhat.com>
      Cc: Linus Torvalds <torvalds@linux-foundation.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Thomas Gleixner <tglx@linutronix.de>
      Cc: Yinghai Lu <yinghai@kernel.org>
      Cc: akpm@linux-foundation.org
      Cc: kexec@lists.infradead.org
      Link: http://lkml.kernel.org/r/1493862171-8799-1-git-send-email-xlpang@redhat.comSigned-off-by: NIngo Molnar <mingo@kernel.org>
      66aad4fd
  20. 07 5月, 2017 1 次提交
    • K
      x86/boot: Declare error() as noreturn · 60854a12
      Kees Cook 提交于
      The compressed boot function error() is used to halt execution, but it
      wasn't marked with "noreturn". This fixes that in preparation for
      supporting kernel FORTIFY_SOURCE, which uses the noreturn annotation
      on panic, and calls error(). GCC would warn about a noreturn function
      calling a non-noreturn function:
      
        arch/x86/boot/compressed/misc.c: In function ‘fortify_panic’:
        arch/x86/boot/compressed/misc.c:416:1: warning: ‘noreturn’ function does return
         }
       ^
      Signed-off-by: NKees Cook <keescook@chromium.org>
      Cc: Daniel Micay <danielmicay@gmail.com>
      Cc: Linus Torvalds <torvalds@linux-foundation.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Thomas Gleixner <tglx@linutronix.de>
      Cc: H. Peter Anvin <hpa@zytor.com>
      Link: http://lkml.kernel.org/r/20170506045116.GA2879@beastSigned-off-by: NIngo Molnar <mingo@kernel.org>
      60854a12
  21. 28 4月, 2017 1 次提交
    • B
      x86/KASLR: Fix kexec kernel boot crash when KASLR randomization fails · da63b6b2
      Baoquan He 提交于
      Dave found that a kdump kernel with KASLR enabled will reset to the BIOS
      immediately if physical randomization failed to find a new position for
      the kernel. A kernel with the 'nokaslr' option works in this case.
      
      The reason is that KASLR will install a new page table for the identity
      mapping, while it missed building it for the original kernel location
      if KASLR physical randomization fails.
      
      This only happens in the kexec/kdump kernel, because the identity mapping
      has been built for kexec/kdump in the 1st kernel for the whole memory by
      calling init_pgtable(). Here if physical randomizaiton fails, it won't build
      the identity mapping for the original area of the kernel but change to a
      new page table '_pgtable'. Then the kernel will triple fault immediately
      caused by no identity mappings.
      
      The normal kernel won't see this bug, because it comes here via startup_32()
      and CR3 will be set to _pgtable already. In startup_32() the identity
      mapping is built for the 0~4G area. In KASLR we just append to the existing
      area instead of entirely overwriting it for on-demand identity mapping
      building. So the identity mapping for the original area of kernel is still
      there.
      
      To fix it we just switch to the new identity mapping page table when physical
      KASLR succeeds. Otherwise we keep the old page table unchanged just like
      "nokaslr" does.
      Signed-off-by: NBaoquan He <bhe@redhat.com>
      Signed-off-by: NDave Young <dyoung@redhat.com>
      Acked-by: NKees Cook <keescook@chromium.org>
      Cc: Borislav Petkov <bp@suse.de>
      Cc: Dave Jiang <dave.jiang@intel.com>
      Cc: Linus Torvalds <torvalds@linux-foundation.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Thomas Garnier <thgarnie@google.com>
      Cc: Thomas Gleixner <tglx@linutronix.de>
      Cc: Yinghai Lu <yinghai@kernel.org>
      Link: http://lkml.kernel.org/r/1493278940-5885-1-git-send-email-bhe@redhat.comSigned-off-by: NIngo Molnar <mingo@kernel.org>
      da63b6b2