29 Sep, 2020

2 commits

  • Currently there are several minor problems with randomization base
    generation code:

    1. It might misbehave in low memory conditions. In particular there
    might be enough space for the kernel on [0, block_sum] but after
    if (base < safe_addr)
    base = safe_addr;
    it might not be enough anymore.

    2. It does not correctly handle minimal address constraint. In condition
    if (base < safe_addr)
    base = safe_addr;
    a synthetic value is compared with an address. If we have a memory
    setup with memory holes due to offline memory regions, and safe_addr is
    close to the end of the first online memory block - we might position
    the kernel in invalid memory.

    3. block_sum calculation logic contains off-by-one error. Let's say we
    have a memory block in which the kernel fits perfectly
    (end - start == kernel_size). In this case:
    if (end - start < kernel_size)
    continue;
    block_sum += end - start - kernel_size;
    block_sum is not increased, while it is a valid kernel position.

    So, address problems listed and explain algorithm used. Besides that
    restructuring the code makes it possible to extend kernel positioning
    algorithm further. Currently we pick position in between single
    [min, max] range (min = safe_addr, max = memory_limit). In future we
    can do that for multiple ranges as well (by calling
    count_valid_kernel_positions for each range).

    Reviewed-by: Philipp Rudo
    Reviewed-by: Alexander Egorenkov
    Signed-off-by: Vasily Gorbik

    Vasily Gorbik
     
  • 0 is a valid random value. To avoid mixing it with error code 0 as an
    return code make get_random() take extra argument to output random
    value and return an error code.

    Reviewed-by: Philipp Rudo
    Reviewed-by: Alexander Egorenkov
    Signed-off-by: Vasily Gorbik

    Vasily Gorbik
     

10 Jun, 2020

2 commits

  • The replacement of with made the include
    of the latter in the middle of asm includes. Fix this up with the aid of
    the below script and manual adjustments here and there.

    import sys
    import re

    if len(sys.argv) is not 3:
    print "USAGE: %s " % (sys.argv[0])
    sys.exit(1)

    hdr_to_move="#include " % sys.argv[2]
    moved = False
    in_hdrs = False

    with open(sys.argv[1], "r") as f:
    lines = f.readlines()
    for _line in lines:
    line = _line.rstrip('
    ')
    if line == hdr_to_move:
    continue
    if line.startswith("#include
    Cc: Geert Uytterhoeven
    Cc: Greentime Hu
    Cc: Greg Ungerer
    Cc: Guan Xuetao
    Cc: Guo Ren
    Cc: Heiko Carstens
    Cc: Helge Deller
    Cc: Ingo Molnar
    Cc: Ley Foon Tan
    Cc: Mark Salter
    Cc: Matthew Wilcox
    Cc: Matt Turner
    Cc: Max Filippov
    Cc: Michael Ellerman
    Cc: Michal Simek
    Cc: Nick Hu
    Cc: Paul Walmsley
    Cc: Richard Weinberger
    Cc: Rich Felker
    Cc: Russell King
    Cc: Stafford Horne
    Cc: Thomas Bogendoerfer
    Cc: Thomas Gleixner
    Cc: Tony Luck
    Cc: Vincent Chen
    Cc: Vineet Gupta
    Cc: Will Deacon
    Cc: Yoshinori Sato
    Link: http://lkml.kernel.org/r/20200514170327.31389-4-rppt@kernel.org
    Signed-off-by: Linus Torvalds

    Mike Rapoport
     
  • The include/linux/pgtable.h is going to be the home of generic page table
    manipulation functions.

    Start with moving asm-generic/pgtable.h to include/linux/pgtable.h and
    make the latter include asm/pgtable.h.

    Signed-off-by: Mike Rapoport
    Signed-off-by: Andrew Morton
    Cc: Arnd Bergmann
    Cc: Borislav Petkov
    Cc: Brian Cain
    Cc: Catalin Marinas
    Cc: Chris Zankel
    Cc: "David S. Miller"
    Cc: Geert Uytterhoeven
    Cc: Greentime Hu
    Cc: Greg Ungerer
    Cc: Guan Xuetao
    Cc: Guo Ren
    Cc: Heiko Carstens
    Cc: Helge Deller
    Cc: Ingo Molnar
    Cc: Ley Foon Tan
    Cc: Mark Salter
    Cc: Matthew Wilcox
    Cc: Matt Turner
    Cc: Max Filippov
    Cc: Michael Ellerman
    Cc: Michal Simek
    Cc: Nick Hu
    Cc: Paul Walmsley
    Cc: Richard Weinberger
    Cc: Rich Felker
    Cc: Russell King
    Cc: Stafford Horne
    Cc: Thomas Bogendoerfer
    Cc: Thomas Gleixner
    Cc: Tony Luck
    Cc: Vincent Chen
    Cc: Vineet Gupta
    Cc: Will Deacon
    Cc: Yoshinori Sato
    Link: http://lkml.kernel.org/r/20200514170327.31389-3-rppt@kernel.org
    Signed-off-by: Linus Torvalds

    Mike Rapoport
     

18 Feb, 2020

1 commit

  • Clang warns:

    ../arch/s390/boot/kaslr.c:78:25: warning: passing 'char *' to parameter
    of type 'const u8 *' (aka 'const unsigned char *') converts between
    pointers to integer
    types with different sign [-Wpointer-sign]
    (char *) entropy, (char *) entropy,
    ^~~~~~~~~~~~~~~~
    ../arch/s390/include/asm/cpacf.h:280:28: note: passing argument to
    parameter 'src' here
    u8 *dest, const u8 *src, long src_len)
    ^
    2 warnings generated.

    Fix the cast to match what else is done in this function.

    Fixes: b2d24b97b2a9 ("s390/kernel: add support for kernel address space layout randomization (KASLR)")
    Link: https://github.com/ClangBuiltLinux/linux/issues/862
    Link: https://lkml.kernel.org/r/20200208141052.48476-1-natechancellor@gmail.com
    Signed-off-by: Nathan Chancellor
    Signed-off-by: Vasily Gorbik

    Nathan Chancellor
     

18 Sep, 2019

1 commit

  • Pull s390 updates from Vasily Gorbik:

    - Add support for IBM z15 machines.

    - Add SHA3 and CCA AES cipher key support in zcrypt and pkey
    refactoring.

    - Move to arch_stack_walk infrastructure for the stack unwinder.

    - Various kasan fixes and improvements.

    - Various command line parsing fixes.

    - Improve decompressor phase debuggability.

    - Lift no bss usage restriction for the early code.

    - Use refcount_t for reference counters for couple of places in mm
    code.

    - Logging improvements and return code fix in vfio-ccw code.

    - Couple of zpci fixes and minor refactoring.

    - Remove some outdated documentation.

    - Fix secure boot detection.

    - Other various minor code clean ups.

    * tag 's390-5.4-1' of git://git.kernel.org/pub/scm/linux/kernel/git/s390/linux: (48 commits)
    s390: remove pointless drivers-y in drivers/s390/Makefile
    s390/cpum_sf: Fix line length and format string
    s390/pci: fix MSI message data
    s390: add support for IBM z15 machines
    s390/crypto: Support for SHA3 via CPACF (MSA6)
    s390/startup: add pgm check info printing
    s390/crypto: xts-aes-s390 fix extra run-time crypto self tests finding
    vfio-ccw: fix error return code in vfio_ccw_sch_init()
    s390: vfio-ap: fix warning reset not completed
    s390/base: remove unused s390_base_mcck_handler
    s390/sclp: Fix bit checked for has_sipl
    s390/zcrypt: fix wrong handling of cca cipher keygenflags
    s390/kasan: add kdump support
    s390/setup: avoid using strncmp with hardcoded length
    s390/sclp: avoid using strncmp with hardcoded length
    s390/module: avoid using strncmp with hardcoded length
    s390/pci: avoid using strncmp with hardcoded length
    s390/kaslr: reserve memory for kasan usage
    s390/mem_detect: provide single get_mem_detect_end
    s390/cmma: reuse kstrtobool for option value parsing
    ...

    Linus Torvalds
     

26 Aug, 2019

1 commit

  • Sometimes the kernel fails to boot with:
    "The Linux kernel failed to boot with the KernelAddressSanitizer:
    out of memory during initialisation" even with big amounts of memory when
    both kaslr and kasan are enabled.

    The problem is that kasan initialization code requires 1/8 of physical
    memory plus some for page tables. To keep as much code instrumented
    as possible kasan avoids using memblock for memory allocations. Instead
    kasan uses trivial memory allocator which simply chops off the memory
    from the end of online physical memory. For that reason when kaslr is
    enabled together with kasan avoid positioning kernel into upper memory
    region which would be utilized during kasan initialization.

    Reviewed-by: Gerald Schaefer
    Signed-off-by: Vasily Gorbik

    Vasily Gorbik
     

30 Jul, 2019

1 commit

  • Add __swsusp_reset_dma declaration to avoid the following sparse warnings:
    arch/s390/kernel/setup.c:107:15: warning: symbol '__swsusp_reset_dma' was not declared. Should it be static?
    arch/s390/boot/startup.c:52:15: warning: symbol '__swsusp_reset_dma' was not declared. Should it be static?

    Add verify_facilities declaration to avoid the following sparse warning:
    arch/s390/boot/als.c:105:6: warning: symbol 'verify_facilities' was not declared. Should it be static?

    Include "boot.h" into arch/s390/boot/kaslr.c to expose get_random_base
    function declaration and avoid the following sparse warning:
    arch/s390/boot/kaslr.c:90:15: warning: symbol 'get_random_base' was not declared. Should it be static?

    Signed-off-by: Vasily Gorbik

    Vasily Gorbik
     

29 Apr, 2019

1 commit