13 Jan, 2021

1 commit

  • commit 311bea3cb9ee20ef150ca76fc60a592bf6b159f5 upstream.

    With GNU binutils 2.35+, linking with BFD produces warnings for vmlinux:
    aarch64-linux-gnu-ld: warning: -z norelro ignored

    BFD can produce this warning when the target emulation mode does not
    support RELRO program headers, and -z relro or -z norelro is passed.

    Alan Modra clarifies:
    The default linker emulation for an aarch64-linux ld.bfd is
    -maarch64linux, the default for an aarch64-elf linker is
    -maarch64elf. They are not equivalent. If you choose -maarch64elf
    you get an emulation that doesn't support -z relro.

    The ARCH=arm64 kernel prefers -maarch64elf, but may fall back to
    -maarch64linux based on the toolchain configuration.

    LLD will always create RELRO program header regardless of target
    emulation.

    To avoid the above warning when linking with BFD, pass -z norelro only
    when linking with LLD or with -maarch64linux.

    Fixes: 3b92fa7485eb ("arm64: link with -z norelro regardless of CONFIG_RELOCATABLE")
    Fixes: 3bbd3db86470 ("arm64: relocatable: fix inconsistencies in linker script and options")
    Cc: # 5.0.x-
    Reported-by: kernelci.org bot
    Reported-by: Quentin Perret
    Signed-off-by: Nick Desaulniers
    Reviewed-by: Nathan Chancellor
    Acked-by: Ard Biesheuvel
    Cc: Alan Modra
    Cc: Fāng-ruì Sòng
    Link: https://lore.kernel.org/r/20201218002432.788499-1-ndesaulniers@google.com
    Signed-off-by: Catalin Marinas
    Signed-off-by: Greg Kroah-Hartman

    Nick Desaulniers
     

01 Dec, 2020

1 commit

  • Currently, '--orphan-handling=warn' is spread out across four different
    architectures in their respective Makefiles, which makes it a little
    unruly to deal with in case it needs to be disabled for a specific
    linker version (in this case, ld.lld 10.0.1).

    To make it easier to control this, hoist this warning into Kconfig and
    the main Makefile so that disabling it is simpler, as the warning will
    only be enabled in a couple places (main Makefile and a couple of
    compressed boot folders that blow away LDFLAGS_vmlinx) and making it
    conditional is easier due to Kconfig syntax. One small additional
    benefit of this is saving a call to ld-option on incremental builds
    because we will have already evaluated it for CONFIG_LD_ORPHAN_WARN.

    To keep the list of supported architectures the same, introduce
    CONFIG_ARCH_WANT_LD_ORPHAN_WARN, which an architecture can select to
    gain this automatically after all of the sections are specified and size
    asserted. A special thanks to Kees Cook for the help text on this
    config.

    Link: https://github.com/ClangBuiltLinux/linux/issues/1187
    Acked-by: Kees Cook
    Acked-by: Michael Ellerman (powerpc)
    Reviewed-by: Nick Desaulniers
    Tested-by: Nick Desaulniers
    Signed-off-by: Nathan Chancellor
    Signed-off-by: Masahiro Yamada

    Nathan Chancellor
     

24 Oct, 2020

1 commit

  • Pull more arm64 updates from Will Deacon:
    "A small selection of further arm64 fixes and updates. Most of these
    are fixes that came in during the merge window, with the exception of
    the HAVE_MOVE_PMD mremap() speed-up which we discussed back in 2018
    and somehow forgot to enable upstream.

    - Improve performance of Spectre-v2 mitigation on Falkor CPUs (if
    you're lucky enough to have one)

    - Select HAVE_MOVE_PMD. This has been shown to improve mremap()
    performance, which is used heavily by the Android runtime GC, and
    it seems we forgot to enable this upstream back in 2018.

    - Ensure linker flags are consistent between LLVM and BFD

    - Fix stale comment in Spectre mitigation rework

    - Fix broken copyright header

    - Fix KASLR randomisation of the linear map

    - Prevent arm64-specific prctl()s from compat tasks (return -EINVAL)"

    Link: https://lore.kernel.org/kvmarm/20181108181201.88826-3-joelaf@google.com/

    * tag 'arm64-upstream' of git://git.kernel.org/pub/scm/linux/kernel/git/arm64/linux:
    arm64: proton-pack: Update comment to reflect new function name
    arm64: spectre-v2: Favour CPU-specific mitigation at EL2
    arm64: link with -z norelro regardless of CONFIG_RELOCATABLE
    arm64: Fix a broken copyright header in gen_vdso_offsets.sh
    arm64: mremap speedup - Enable HAVE_MOVE_PMD
    arm64: mm: use single quantity to represent the PA to VA translation
    arm64: reject prctl(PR_PAC_RESET_KEYS) on compat tasks

    Linus Torvalds
     

23 Oct, 2020

1 commit

  • Pull Kbuild updates from Masahiro Yamada:

    - Support 'make compile_commands.json' to generate the compilation
    database more easily, avoiding stale entries

    - Support 'make clang-analyzer' and 'make clang-tidy' for static checks
    using clang-tidy

    - Preprocess scripts/modules.lds.S to allow CONFIG options in the
    module linker script

    - Drop cc-option tests from compiler flags supported by our minimal
    GCC/Clang versions

    - Use always 12-digits commit hash for CONFIG_LOCALVERSION_AUTO=y

    - Use sha1 build id for both BFD linker and LLD

    - Improve deb-pkg for reproducible builds and rootless builds

    - Remove stale, useless scripts/namespace.pl

    - Turn -Wreturn-type warning into error

    - Fix build error of deb-pkg when CONFIG_MODULES=n

    - Replace 'hostname' command with more portable 'uname -n'

    - Various Makefile cleanups

    * tag 'kbuild-v5.10' of git://git.kernel.org/pub/scm/linux/kernel/git/masahiroy/linux-kbuild: (34 commits)
    kbuild: Use uname for LINUX_COMPILE_HOST detection
    kbuild: Only add -fno-var-tracking-assignments for old GCC versions
    kbuild: remove leftover comment for filechk utility
    treewide: remove DISABLE_LTO
    kbuild: deb-pkg: clean up package name variables
    kbuild: deb-pkg: do not build linux-headers package if CONFIG_MODULES=n
    kbuild: enforce -Werror=return-type
    scripts: remove namespace.pl
    builddeb: Add support for all required debian/rules targets
    builddeb: Enable rootless builds
    builddeb: Pass -n to gzip for reproducible packages
    kbuild: split the build log of kallsyms
    kbuild: explicitly specify the build id style
    scripts/setlocalversion: make git describe output more reliable
    kbuild: remove cc-option test of -Werror=date-time
    kbuild: remove cc-option test of -fno-stack-check
    kbuild: remove cc-option test of -fno-strict-overflow
    kbuild: move CFLAGS_{KASAN,UBSAN,KCSAN} exports to relevant Makefiles
    kbuild: remove redundant CONFIG_KASAN check from scripts/Makefile.kasan
    kbuild: do not create built-in objects for external module builds
    ...

    Linus Torvalds
     

20 Oct, 2020

1 commit

  • With CONFIG_EXPERT=y, CONFIG_KASAN=y, CONFIG_RANDOMIZE_BASE=n,
    CONFIG_RELOCATABLE=n, we observe the following failure when trying to
    link the kernel image with LD=ld.lld:

    error: section: .exit.data is not contiguous with other relro sections

    ld.lld defaults to -z relro while ld.bfd defaults to -z norelro. This
    was previously fixed, but only for CONFIG_RELOCATABLE=y.

    Fixes: 3bbd3db86470 ("arm64: relocatable: fix inconsistencies in linker script and options")
    Signed-off-by: Nick Desaulniers
    Cc: stable@vger.kernel.org
    Link: https://lore.kernel.org/r/20201016175339.2429280-1-ndesaulniers@google.com
    Signed-off-by: Will Deacon

    Nick Desaulniers
     

13 Oct, 2020

1 commit

  • Pull orphan section checking from Ingo Molnar:
    "Orphan link sections were a long-standing source of obscure bugs,
    because the heuristics that various linkers & compilers use to handle
    them (include these bits into the output image vs discarding them
    silently) are both highly idiosyncratic and also version dependent.

    Instead of this historically problematic mess, this tree by Kees Cook
    (et al) adds build time asserts and build time warnings if there's any
    orphan section in the kernel or if a section is not sized as expected.

    And because we relied on so many silent assumptions in this area, fix
    a metric ton of dependencies and some outright bugs related to this,
    before we can finally enable the checks on the x86, ARM and ARM64
    platforms"

    * tag 'core-build-2020-10-12' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: (36 commits)
    x86/boot/compressed: Warn on orphan section placement
    x86/build: Warn on orphan section placement
    arm/boot: Warn on orphan section placement
    arm/build: Warn on orphan section placement
    arm64/build: Warn on orphan section placement
    x86/boot/compressed: Add missing debugging sections to output
    x86/boot/compressed: Remove, discard, or assert for unwanted sections
    x86/boot/compressed: Reorganize zero-size section asserts
    x86/build: Add asserts for unwanted sections
    x86/build: Enforce an empty .got.plt section
    x86/asm: Avoid generating unused kprobe sections
    arm/boot: Handle all sections explicitly
    arm/build: Assert for unwanted sections
    arm/build: Add missing sections
    arm/build: Explicitly keep .ARM.attributes sections
    arm/build: Refactor linker script headers
    arm64/build: Assert for unwanted sections
    arm64/build: Add missing DWARF sections
    arm64/build: Use common DISCARDS in linker script
    arm64/build: Remove .eh_frame* sections due to unwind tables
    ...

    Linus Torvalds
     

24 Sep, 2020

1 commit

  • There was a request to preprocess the module linker script like we
    do for the vmlinux one. (https://lkml.org/lkml/2020/8/21/512)

    The difference between vmlinux.lds and module.lds is that the latter
    is needed for external module builds, thus must be cleaned up by
    'make mrproper' instead of 'make clean'. Also, it must be created
    by 'make modules_prepare'.

    You cannot put it in arch/$(SRCARCH)/kernel/, which is cleaned up by
    'make clean'. I moved arch/$(SRCARCH)/kernel/module.lds to
    arch/$(SRCARCH)/include/asm/module.lds.h, which is included from
    scripts/module.lds.S.

    scripts/module.lds is fine because 'make clean' keeps all the
    build artifacts under scripts/.

    You can add arch-specific sections in .

    Signed-off-by: Masahiro Yamada
    Tested-by: Jessica Yu
    Acked-by: Will Deacon
    Acked-by: Geert Uytterhoeven
    Acked-by: Palmer Dabbelt
    Reviewed-by: Kees Cook
    Acked-by: Jessica Yu

    Masahiro Yamada
     

07 Sep, 2020

1 commit

  • TEXT_OFFSET serves no purpose, and for this reason, it was redefined
    as 0x0 in the v5.8 timeframe. Since this does not appear to have caused
    any issues that require us to revisit that decision, let's get rid of the
    macro entirely, along with any references to it.

    Signed-off-by: Ard Biesheuvel
    Link: https://lore.kernel.org/r/20200825135440.11288-1-ardb@kernel.org
    Signed-off-by: Will Deacon

    Ard Biesheuvel
     

03 Sep, 2020

1 commit

  • We don't want to depend on the linker's orphan section placement
    heuristics as these can vary between linkers, and may change between
    versions. All sections need to be explicitly handled in the linker
    script.

    With all sections now handled, enable orphan section warnings.

    Signed-off-by: Kees Cook
    Signed-off-by: Ingo Molnar
    Acked-by: Will Deacon
    Reviewed-by: Nick Desaulniers
    Link: https://lore.kernel.org/r/20200902025347.2504702-2-keescook@chromium.org

    Kees Cook
     

01 Sep, 2020

1 commit

  • Avoid .eh_frame* section generation by making sure both CFLAGS and AFLAGS
    contain -fno-asychronous-unwind-tables and -fno-unwind-tables.

    With all sources of .eh_frame now removed from the build, drop this
    DISCARD so we can be alerted in the future if it returns unexpectedly
    once orphan section warnings have been enabled.

    Suggested-by: Ard Biesheuvel
    Signed-off-by: Kees Cook
    Signed-off-by: Ingo Molnar
    Acked-by: Will Deacon
    Link: https://lore.kernel.org/r/20200821194310.3089815-11-keescook@chromium.org

    Kees Cook
     

28 Aug, 2020

2 commits

  • vdso32 should only be installed if CONFIG_COMPAT_VDSO is enabled,
    since it's not even supposed to be compiled otherwise, and arm64
    builds without a 32bit crosscompiler will fail.

    Fixes: 8d75785a8142 ("ARM64: vdso32: Install vdso32 from vdso_install")
    Signed-off-by: Frank van der Linden
    Cc: stable@vger.kernel.org [5.4+]
    Link: https://lore.kernel.org/r/20200827234012.19757-1-fllinden@amazon.com
    Signed-off-by: Catalin Marinas

    Frank van der Linden
     
  • Commit 7c78f67e9bd9 ("arm64: enable tlbi range instructions") breaks
    LLVM's integrated assembler, because -Wa,-march is only passed to
    external assemblers and therefore, the new instructions are not enabled
    when IAS is used.

    This change adds a common architecture version preamble, which can be
    used in inline assembly blocks that contain instructions that require
    a newer architecture version, and uses it to fix __TLBI_0 and __TLBI_1
    with ARM64_TLB_RANGE.

    Fixes: 7c78f67e9bd9 ("arm64: enable tlbi range instructions")
    Signed-off-by: Sami Tolvanen
    Tested-by: Nathan Chancellor
    Reviewed-by: Nathan Chancellor
    Link: https://github.com/ClangBuiltLinux/linux/issues/1106
    Link: https://lore.kernel.org/r/20200827203608.1225689-1-samitolvanen@google.com
    Signed-off-by: Catalin Marinas

    Sami Tolvanen
     

22 Aug, 2020

1 commit

  • Add the 32-bit vdso Makefile to the vdso_install rule so that 'make
    vdso_install' installs the 32-bit compat vdso when it is compiled.

    Fixes: a7f71a2c8903 ("arm64: compat: Add vDSO")
    Signed-off-by: Stephen Boyd
    Reviewed-by: Vincenzo Frascino
    Acked-by: Will Deacon
    Cc: Vincenzo Frascino
    Link: https://lore.kernel.org/r/20200818014950.42492-1-swboyd@chromium.org
    Signed-off-by: Catalin Marinas

    Stephen Boyd
     

04 Aug, 2020

1 commit

  • Pull arm64 and cross-arch updates from Catalin Marinas:
    "Here's a slightly wider-spread set of updates for 5.9.

    Going outside the usual arch/arm64/ area is the removal of
    read_barrier_depends() series from Will and the MSI/IOMMU ID
    translation series from Lorenzo.

    The notable arm64 updates include ARMv8.4 TLBI range operations and
    translation level hint, time namespace support, and perf.

    Summary:

    - Removal of the tremendously unpopular read_barrier_depends()
    barrier, which is a NOP on all architectures apart from Alpha, in
    favour of allowing architectures to override READ_ONCE() and do
    whatever dance they need to do to ensure address dependencies
    provide LOAD -> LOAD/STORE ordering.

    This work also offers a potential solution if compilers are shown
    to convert LOAD -> LOAD address dependencies into control
    dependencies (e.g. under LTO), as weakly ordered architectures will
    effectively be able to upgrade READ_ONCE() to smp_load_acquire().
    The latter case is not used yet, but will be discussed further at
    LPC.

    - Make the MSI/IOMMU input/output ID translation PCI agnostic,
    augment the MSI/IOMMU ACPI/OF ID mapping APIs to accept an input ID
    bus-specific parameter and apply the resulting changes to the
    device ID space provided by the Freescale FSL bus.

    - arm64 support for TLBI range operations and translation table level
    hints (part of the ARMv8.4 architecture version).

    - Time namespace support for arm64.

    - Export the virtual and physical address sizes in vmcoreinfo for
    makedumpfile and crash utilities.

    - CPU feature handling cleanups and checks for programmer errors
    (overlapping bit-fields).

    - ACPI updates for arm64: disallow AML accesses to EFI code regions
    and kernel memory.

    - perf updates for arm64.

    - Miscellaneous fixes and cleanups, most notably PLT counting
    optimisation for module loading, recordmcount fix to ignore
    relocations other than R_AARCH64_CALL26, CMA areas reserved for
    gigantic pages on 16K and 64K configurations.

    - Trivial typos, duplicate words"

    Link: http://lkml.kernel.org/r/20200710165203.31284-1-will@kernel.org
    Link: http://lkml.kernel.org/r/20200619082013.13661-1-lorenzo.pieralisi@arm.com

    * tag 'arm64-upstream' of git://git.kernel.org/pub/scm/linux/kernel/git/arm64/linux: (82 commits)
    arm64: use IRQ_STACK_SIZE instead of THREAD_SIZE for irq stack
    arm64/mm: save memory access in check_and_switch_context() fast switch path
    arm64: sigcontext.h: delete duplicated word
    arm64: ptrace.h: delete duplicated word
    arm64: pgtable-hwdef.h: delete duplicated words
    bus: fsl-mc: Add ACPI support for fsl-mc
    bus/fsl-mc: Refactor the MSI domain creation in the DPRC driver
    of/irq: Make of_msi_map_rid() PCI bus agnostic
    of/irq: make of_msi_map_get_device_domain() bus agnostic
    dt-bindings: arm: fsl: Add msi-map device-tree binding for fsl-mc bus
    of/device: Add input id to of_dma_configure()
    of/iommu: Make of_map_rid() PCI agnostic
    ACPI/IORT: Add an input ID to acpi_dma_configure()
    ACPI/IORT: Remove useless PCI bus walk
    ACPI/IORT: Make iort_msi_map_rid() PCI agnostic
    ACPI/IORT: Make iort_get_device_domain IRQ domain agnostic
    ACPI/IORT: Make iort_match_node_callback walk the ACPI namespace for NC
    arm64: enable time namespace support
    arm64/vdso: Restrict splitting VVAR VMA
    arm64/vdso: Handle faults on timens page
    ...

    Linus Torvalds
     

26 Jul, 2020

1 commit

  • …it/tip/tip into master

    Pull EFI fixes from Ingo Molnar:
    "Various EFI fixes:

    - Fix the layering violation in the use of the EFI runtime services
    availability mask in users of the 'efivars' abstraction

    - Revert build fix for GCC v4.8 which is no longer supported

    - Clean up some x86 EFI stub details, some of which are borderline
    bugs that copy around garbage into padding fields - let's fix these
    out of caution.

    - Fix build issues while working on RISC-V support

    - Avoid --whole-archive when linking the stub on arm64"

    * tag 'efi-urgent-2020-07-25' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip:
    efi: Revert "efi/x86: Fix build with gcc 4"
    efi/efivars: Expose RT service availability via efivars abstraction
    efi/libstub: Move the function prototypes to header file
    efi/libstub: Fix gcc error around __umoddi3 for 32 bit builds
    efi/libstub/arm64: link stub lib.a conditionally
    efi/x86: Only copy upto the end of setup_header
    efi/x86: Remove unused variables

    Linus Torvalds
     

15 Jul, 2020

1 commit

  • TLBI RANGE feature instoduces new assembly instructions and only
    support by binutils >= 2.30. Add necessary Kconfig logic to allow
    this to be enabled and pass '-march=armv8.4-a' to KBUILD_CFLAGS.

    Signed-off-by: Zhenyu Ye
    Link: https://lore.kernel.org/r/20200715071945.897-3-yezhenyu2@huawei.com
    Signed-off-by: Catalin Marinas

    Zhenyu Ye
     

09 Jul, 2020

1 commit

  • Since commit 799c43415442 ("kbuild: thin archives make default for
    all archs"), core-y is passed to the linker with --whole-archive.
    Hence, the whole of stub library is linked to vmlinux.

    Use libs-y so that lib.a is passed after --no-whole-archive for
    conditional linking.

    The unused drivers/firmware/efi/libstub/relocate.o will be dropped
    for ARCH=arm64.

    Signed-off-by: Masahiro Yamada
    Link: https://lore.kernel.org/r/20200604022031.164207-1-masahiroy@kernel.org
    Signed-off-by: Ard Biesheuvel

    Masahiro Yamada
     

15 Jun, 2020

1 commit

  • TEXT_OFFSET was recently changed to 0x0, in preparation for its removal
    at a later stage, and a warning is emitted into the kernel log when the
    bootloader appears to have failed to take the TEXT_OFFSET image header
    value into account.

    Ironically, this warning itself fails to take TEXT_OFFSET into account,
    and compares the kernel image's alignment modulo 2M against a hardcoded
    value of 0x0, and so the warning will trigger spuriously when TEXT_OFFSET
    randomization is enabled.

    Given the intent to get rid of TEXT_OFFSET entirely, let's fix this
    oversight by just removing support for TEXT_OFFSET randomization.

    Signed-off-by: Ard Biesheuvel
    Acked-by: Mark Rutland
    Link: https://lore.kernel.org/r/20200615101939.634391-1-ardb@kernel.org
    Signed-off-by: Will Deacon

    Ard Biesheuvel
     

07 Jun, 2020

1 commit

  • Pull Kbuild updates from Masahiro Yamada:

    - fix warnings in 'make clean' for ARCH=um, hexagon, h8300, unicore32

    - ensure to rebuild all objects when the compiler is upgraded

    - exclude system headers from dependency tracking and fixdep processing

    - fix potential bit-size mismatch between the kernel and BPF user-mode
    helper

    - add the new syntax 'userprogs' to build user-space programs for the
    target architecture (the same arch as the kernel)

    - compile user-space sample code under samples/ for the target arch
    instead of the host arch

    - make headers_install fail if a CONFIG option is leaked to user-space

    - sanitize the output format of scripts/checkstack.pl

    - handle ARM 'push' instruction in scripts/checkstack.pl

    - error out before modpost if a module name conflict is found

    - error out when multiple directories are passed to M= because this
    feature is broken for a long time

    - add CONFIG_DEBUG_INFO_COMPRESSED to support compressed debug info

    - a lot of cleanups of modpost

    - dump vmlinux symbols out into vmlinux.symvers, and reuse it in the
    second pass of modpost

    - do not run the second pass of modpost if nothing in modules is
    updated

    - install modules.builtin(.modinfo) by 'make install' as well as by
    'make modules_install' because it is useful even when
    CONFIG_MODULES=n

    - add new command line variables, GZIP, BZIP2, LZOP, LZMA, LZ4, and XZ
    to allow users to use alternatives such as pigz, pbzip2, etc.

    * tag 'kbuild-v5.8' of git://git.kernel.org/pub/scm/linux/kernel/git/masahiroy/linux-kbuild: (96 commits)
    kbuild: add variables for compression tools
    Makefile: install modules.builtin even if CONFIG_MODULES=n
    mksysmap: Fix the mismatch of '.L' symbols in System.map
    kbuild: doc: rename LDFLAGS to KBUILD_LDFLAGS
    modpost: change elf_info->size to size_t
    modpost: remove is_vmlinux() helper
    modpost: strip .o from modname before calling new_module()
    modpost: set have_vmlinux in new_module()
    modpost: remove mod->skip struct member
    modpost: add mod->is_vmlinux struct member
    modpost: remove is_vmlinux() call in check_for_{gpl_usage,unused}()
    modpost: remove mod->is_dot_o struct member
    modpost: move -d option in scripts/Makefile.modpost
    modpost: remove -s option
    modpost: remove get_next_text() and make {grab,release_}file static
    modpost: use read_text_file() and get_line() for reading text files
    modpost: avoid false-positive file open error
    modpost: fix potential mmap'ed file overrun in get_src_version()
    modpost: add read_text_file() and get_line() helpers
    modpost: do not call get_modinfo() for vmlinux(.o)
    ...

    Linus Torvalds
     

29 May, 2020

2 commits

  • Support for Clang's Shadow Call Stack in the kernel
    (Sami Tolvanen and Will Deacon)
    * for-next/scs:
    arm64: entry-ftrace.S: Update comment to indicate that x18 is live
    scs: Move DEFINE_SCS macro into core code
    scs: Remove references to asm/scs.h from core code
    scs: Move scs_overflow_check() out of architecture code
    arm64: scs: Use 'scs_sp' register alias for x18
    scs: Move accounting into alloc/free functions
    arm64: scs: Store absolute SCS stack pointer value in thread_info
    efi/libstub: Disable Shadow Call Stack
    arm64: scs: Add shadow stacks for SDEI
    arm64: Implement Shadow Call Stack
    arm64: Disable SCS for hypervisor code
    arm64: vdso: Disable Shadow Call Stack
    arm64: efi: Restore register x18 if it was corrupted
    arm64: Preserve register x18 when CPU is suspended
    arm64: Reserve register x18 from general allocation with SCS
    scs: Disable when function graph tracing is enabled
    scs: Add support for stack usage debugging
    scs: Add page accounting for shadow call stack allocations
    scs: Add support for Clang's Shadow Call Stack (SCS)

    Will Deacon
     
  • Support for Branch Target Identification (BTI) in user and kernel
    (Mark Brown and others)
    * for-next/bti: (39 commits)
    arm64: vdso: Fix CFI directives in sigreturn trampoline
    arm64: vdso: Don't prefix sigreturn trampoline with a BTI C instruction
    arm64: bti: Fix support for userspace only BTI
    arm64: kconfig: Update and comment GCC version check for kernel BTI
    arm64: vdso: Map the vDSO text with guarded pages when built for BTI
    arm64: vdso: Force the vDSO to be linked as BTI when built for BTI
    arm64: vdso: Annotate for BTI
    arm64: asm: Provide a mechanism for generating ELF note for BTI
    arm64: bti: Provide Kconfig for kernel mode BTI
    arm64: mm: Mark executable text as guarded pages
    arm64: bpf: Annotate JITed code for BTI
    arm64: Set GP bit in kernel page tables to enable BTI for the kernel
    arm64: asm: Override SYM_FUNC_START when building the kernel with BTI
    arm64: bti: Support building kernel C code using BTI
    arm64: Document why we enable PAC support for leaf functions
    arm64: insn: Report PAC and BTI instructions as skippable
    arm64: insn: Don't assume unrecognized HINTs are skippable
    arm64: insn: Provide a better name for aarch64_insn_is_nop()
    arm64: insn: Add constants for new HINT instruction decode
    arm64: Disable old style assembly annotations
    ...

    Will Deacon
     

15 May, 2020

1 commit

  • Reserve the x18 register from general allocation when SCS is enabled,
    because the compiler uses the register to store the current task's
    shadow stack pointer. Note that all external kernel modules must also be
    compiled with -ffixed-x18 if the kernel has SCS enabled.

    Signed-off-by: Sami Tolvanen
    Reviewed-by: Nick Desaulniers
    Reviewed-by: Kees Cook
    Acked-by: Will Deacon
    Signed-off-by: Will Deacon

    Sami Tolvanen
     

12 May, 2020

1 commit

  • $(AS) is not used anywhere in the kernel build, hence commit
    aa824e0c962b ("kbuild: remove AS variable") killed it.

    Remove the left-over code in arch/{arm,arm64}/Makefile.

    Signed-off-by: Masahiro Yamada
    Reviewed-by: Nathan Chancellor
    Acked-by: Will Deacon

    Masahiro Yamada
     

08 May, 2020

2 commits

  • When running with BTI enabled we need to ask the compiler to enable
    generation of BTI landing pads beyond those generated as a result of
    pointer authentication instructions being landing pads. Since the two
    features are practically speaking unlikely to be used separately we
    will make kernel mode BTI depend on pointer authentication in order
    to simplify the Makefile.

    Signed-off-by: Mark Brown
    Reviewed-by: Catalin Marinas
    Link: https://lore.kernel.org/r/20200506195138.22086-3-broonie@kernel.org
    Signed-off-by: Will Deacon

    Mark Brown
     
  • Document the fact that we enable pointer authentication protection for
    leaf functions since there is some narrow potential for ROP protection
    benefits and little overhead has been observed.

    Signed-off-by: Mark Brown
    Link: https://lore.kernel.org/r/20200506195138.22086-2-broonie@kernel.org
    Signed-off-by: Will Deacon

    Mark Brown
     

28 Apr, 2020

2 commits

  • TEXT_OFFSET on arm64 is a historical artifact from the early days of
    the arm64 port where the boot protocol was basically 'copy this image
    to the base of memory + 512k', giving us 512 KB of guaranteed BSS space
    to put the swapper page tables. When the arm64 Image header was added in
    v3.10, it already carried the actual value of TEXT_OFFSET, to allow the
    bootloader to discover it dynamically rather than hardcode it to 512 KB.

    Today, this memory window is not used for any particular purpose, and
    it is simply handed to the page allocator at boot. The only reason it
    still exists is because of the 512k misalignment it causes with respect
    to the 2 MB aligned virtual base address of the kernel, which affects
    the virtual addresses of all statically allocated objects in the kernel
    image.

    However, with the introduction of KASLR in v4.6, we added the concept of
    relocatable kernels, which rewrite all absolute symbol references at
    boot anyway, and so the placement of such kernels in the physical address
    space is irrelevant, provided that the minimum segment alignment is
    honoured (64 KB in most cases, 128 KB for 64k pages kernels with vmap'ed
    stacks enabled). This makes 0x0 and 512 KB equally suitable values for
    TEXT_OFFSET on the off chance that we are dealing with boot loaders that
    ignore the value passed via the header entirely.

    Considering that the distros as well as Android ship KASLR-capable
    kernels today, and the fact that TEXT_OFFSET was discoverable from the
    Image header from the very beginning, let's change this value to 0x0, in
    preparation for removing it entirely at a later date.

    Signed-off-by: Ard Biesheuvel
    Link: https://lore.kernel.org/r/20200415082922.32709-1-ardb@kernel.org
    Signed-off-by: Will Deacon

    Ard Biesheuvel
     
  • Drop the definition and export of GZFLAGS, which was never referenced
    on arm64, and whose last recorded use in the ARM port (on which arm64
    was based original) was removed by patch

    commit 5e89d379edb5ae08b57f39dd8d91697275245cbf [*]
    Author: Russell King
    Date: Wed Oct 16 14:32:17 2002 +0100

    [ARM] Convert ARM makefiles to new kbuild (Sam Ravnborg, Kai, rmk)

    [*] git commit ID based on Thomas Gleixner's historical GIT repository at
    git://git.kernel.org/pub/scm/linux/kernel/git/tglx/history.git

    Signed-off-by: Ard Biesheuvel
    Acked-by: Mark Rutland
    Link: https://lore.kernel.org/r/20200415123049.25504-1-ardb@kernel.org
    Signed-off-by: Will Deacon

    Ard Biesheuvel
     

02 Apr, 2020

1 commit

  • Compilers with branch protection support can be configured to enable it by
    default, it is likely that distributions will do this as part of deploying
    branch protection system wide. As well as the slight overhead from having
    some extra NOPs for unused branch protection features this can cause more
    serious problems when the kernel is providing pointer authentication to
    userspace but not built for pointer authentication itself. In that case our
    switching of keys for userspace can affect the kernel unexpectedly, causing
    pointer authentication instructions in the kernel to corrupt addresses.

    To ensure that we get consistent and reliable behaviour always explicitly
    initialise the branch protection mode, ensuring that the kernel is built
    the same way regardless of the compiler defaults.

    Fixes: 7503197562567 (arm64: add basic pointer authentication support)
    Reported-by: Szabolcs Nagy
    Signed-off-by: Mark Brown
    Cc: stable@vger.kernel.org
    [catalin.marinas@arm.com: remove Kconfig option in favour of Makefile check]
    Signed-off-by: Catalin Marinas

    Mark Brown
     

18 Mar, 2020

1 commit

  • Compile all functions with two ptrauth instructions: PACIASP in the
    prologue to sign the return address, and AUTIASP in the epilogue to
    authenticate the return address (from the stack). If authentication
    fails, the return will cause an instruction abort to be taken, followed
    by an oops and killing the task.

    This should help protect the kernel against attacks using
    return-oriented programming. As ptrauth protects the return address, it
    can also serve as a replacement for CONFIG_STACKPROTECTOR, although note
    that it does not protect other parts of the stack.

    The new instructions are in the HINT encoding space, so on a system
    without ptrauth they execute as NOPs.

    CONFIG_ARM64_PTR_AUTH now not only enables ptrauth for userspace and KVM
    guests, but also automatically builds the kernel with ptrauth
    instructions if the compiler supports it. If there is no compiler
    support, we do not warn that the kernel was built without ptrauth
    instructions.

    GCC 7 and 8 support the -msign-return-address option, while GCC 9
    deprecates that option and replaces it with -mbranch-protection. Support
    both options.

    Clang uses an external assembler hence this patch makes sure that the
    correct parameters (-march=armv8.3-a) are passed down to help it recognize
    the ptrauth instructions.

    Ftrace function tracer works properly with Ptrauth only when
    patchable-function-entry feature is present and is ensured by the
    Kconfig dependency.

    Cc: Catalin Marinas
    Cc: Will Deacon
    Cc: Masahiro Yamada
    Reviewed-by: Kees Cook
    Reviewed-by: Vincenzo Frascino # not co-dev parts
    Co-developed-by: Vincenzo Frascino
    Signed-off-by: Vincenzo Frascino
    Signed-off-by: Kristina Martsenko
    [Amit: Cover leaf function, comments, Ftrace Kconfig]
    Signed-off-by: Amit Daniel Kachhap
    Signed-off-by: Catalin Marinas

    Kristina Martsenko
     

16 Jan, 2020

1 commit


15 Jan, 2020

1 commit

  • As the Kconfig syntax gained support for $(as-instr) tests, move the LSE
    gas support detection from Makefile to the main arm64 Kconfig and remove
    the additional CONFIG_AS_LSE definition and check.

    Cc: Will Deacon
    Reviewed-by: Vladimir Murzin
    Tested-by: Vladimir Murzin
    Signed-off-by: Catalin Marinas
    Signed-off-by: Will Deacon

    Catalin Marinas
     

06 Nov, 2019

1 commit

  • This patch implements FTRACE_WITH_REGS for arm64, which allows a traced
    function's arguments (and some other registers) to be captured into a
    struct pt_regs, allowing these to be inspected and/or modified. This is
    a building block for live-patching, where a function's arguments may be
    forwarded to another function. This is also necessary to enable ftrace
    and in-kernel pointer authentication at the same time, as it allows the
    LR value to be captured and adjusted prior to signing.

    Using GCC's -fpatchable-function-entry=N option, we can have the
    compiler insert a configurable number of NOPs between the function entry
    point and the usual prologue. This also ensures functions are AAPCS
    compliant (e.g. disabling inter-procedural register allocation).

    For example, with -fpatchable-function-entry=2, GCC 8.1.0 compiles the
    following:

    | unsigned long bar(void);
    |
    | unsigned long foo(void)
    | {
    | return bar() + 1;
    | }

    ... to:

    | :
    | nop
    | nop
    | stp x29, x30, [sp, #-16]!
    | mov x29, sp
    | bl 0
    | add x0, x0, #0x1
    | ldp x29, x30, [sp], #16
    | ret

    This patch builds the kernel with -fpatchable-function-entry=2,
    prefixing each function with two NOPs. To trace a function, we replace
    these NOPs with a sequence that saves the LR into a GPR, then calls an
    ftrace entry assembly function which saves this and other relevant
    registers:

    | mov x9, x30
    | bl

    Since patchable functions are AAPCS compliant (and the kernel does not
    use x18 as a platform register), x9-x18 can be safely clobbered in the
    patched sequence and the ftrace entry code.

    There are now two ftrace entry functions, ftrace_regs_entry (which saves
    all GPRs), and ftrace_entry (which saves the bare minimum). A PLT is
    allocated for each within modules.

    Signed-off-by: Torsten Duwe
    [Mark: rework asm, comments, PLTs, initialization, commit message]
    Signed-off-by: Mark Rutland
    Reviewed-by: Amit Daniel Kachhap
    Reviewed-by: Ard Biesheuvel
    Reviewed-by: Torsten Duwe
    Tested-by: Amit Daniel Kachhap
    Tested-by: Torsten Duwe
    Cc: AKASHI Takahiro
    Cc: Catalin Marinas
    Cc: Josh Poimboeuf
    Cc: Julien Thierry
    Cc: Will Deacon

    Torsten Duwe
     

07 Oct, 2019

4 commits

  • CONFIG_COMPAT_VDSO is defined by passing '-DCONFIG_COMPAT_VDSO' to the
    compiler when the generic compat vDSO code is in use. It's much cleaner
    and simpler to expose this as a proper Kconfig option (like x86 does),
    so do that and remove the bodge.

    Acked-by: Catalin Marinas
    Signed-off-by: Will Deacon

    Will Deacon
     
  • There's no need to export COMPATCC, so just define it locally in the
    vdso32/Makefile, which is the only place where it is used.

    Acked-by: Catalin Marinas
    Signed-off-by: Will Deacon

    Will Deacon
     
  • Rather than force the use of GCC for the compat cross-compiler, instead
    extract the target from CROSS_COMPILE_COMPAT and pass it to clang if the
    main compiler is clang.

    Acked-by: Catalin Marinas
    Signed-off-by: Will Deacon

    Will Deacon
     
  • The .config file and the generated include/config/auto.conf can
    end up out of sync after a set of commands since
    CONFIG_CROSS_COMPILE_COMPAT_VDSO is not updated correctly.

    The sequence can be reproduced as follows:

    $ make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- defconfig
    [...]
    $ make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- menuconfig
    [set CONFIG_CROSS_COMPILE_COMPAT_VDSO="arm-linux-gnueabihf-"]
    $ make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu-

    Which results in:

    arch/arm64/Makefile:62: CROSS_COMPILE_COMPAT not defined or empty,
    the compat vDSO will not be built

    even though the compat vDSO has been built:

    $ file arch/arm64/kernel/vdso32/vdso.so
    arch/arm64/kernel/vdso32/vdso.so: ELF 32-bit LSB pie executable, ARM,
    EABI5 version 1 (SYSV), dynamically linked,
    BuildID[sha1]=c67f6c786f2d2d6f86c71f708595594aa25247f6, stripped

    A similar case that involves changing the configuration parameter
    multiple times can be reconducted to the same family of problems.

    Remove the use of CONFIG_CROSS_COMPILE_COMPAT_VDSO altogether and
    instead rely on the cross-compiler prefix coming from the environment
    via CROSS_COMPILE_COMPAT, much like we do for the rest of the kernel.

    Cc: Will Deacon
    Cc: Catalin Marinas
    Reported-by: Will Deacon
    Signed-off-by: Vincenzo Frascino
    Signed-off-by: Will Deacon

    Vincenzo Frascino
     

20 Sep, 2019

1 commit

  • Pull Kbuild updates from Masahiro Yamada:

    - add modpost warn exported symbols marked as 'static' because 'static'
    and EXPORT_SYMBOL is an odd combination

    - break the build early if gold linker is used

    - optimize the Bison rule to produce .c and .h files by a single
    pattern rule

    - handle PREEMPT_RT in the module vermagic and UTS_VERSION

    - warn CONFIG options leaked to the user-space except existing ones

    - make single targets work properly

    - rebuild modules when module linker scripts are updated

    - split the module final link stage into scripts/Makefile.modfinal

    - fix the missed error code in merge_config.sh

    - improve the error message displayed on the attempt of the O= build in
    unclean source tree

    - remove 'clean-dirs' syntax

    - disable -Wimplicit-fallthrough warning for Clang

    - add CONFIG_CC_OPTIMIZE_FOR_SIZE_O3 for ARC

    - remove ARCH_{CPP,A,C}FLAGS variables

    - add $(BASH) to run bash scripts

    - change *CFLAGS_.o to take the relative path to $(obj)
    instead of the basename

    - stop suppressing Clang's -Wunused-function warnings when W=1

    - fix linux/export.h to avoid genksyms calculating CRC of trimmed
    exported symbols

    - misc cleanups

    * tag 'kbuild-v5.4' of git://git.kernel.org/pub/scm/linux/kernel/git/masahiroy/linux-kbuild: (63 commits)
    genksyms: convert to SPDX License Identifier for lex.l and parse.y
    modpost: use __section in the output to *.mod.c
    modpost: use MODULE_INFO() for __module_depends
    export.h, genksyms: do not make genksyms calculate CRC of trimmed symbols
    export.h: remove defined(__KERNEL__), which is no longer needed
    kbuild: allow Clang to find unused static inline functions for W=1 build
    kbuild: rename KBUILD_ENABLE_EXTRA_GCC_CHECKS to KBUILD_EXTRA_WARN
    kbuild: refactor scripts/Makefile.extrawarn
    merge_config.sh: ignore unwanted grep errors
    kbuild: change *FLAGS_.o to take the path relative to $(obj)
    modpost: add NOFAIL to strndup
    modpost: add guid_t type definition
    kbuild: add $(BASH) to run scripts with bash-extension
    kbuild: remove ARCH_{CPP,A,C}FLAGS
    kbuild,arc: add CONFIG_CC_OPTIMIZE_FOR_PERFORMANCE_O3 for ARC
    kbuild: Do not enable -Wimplicit-fallthrough for clang for now
    kbuild: clean up subdir-ymn calculation in Makefile.clean
    kbuild: remove unneeded '+' marker from cmd_clean
    kbuild: remove clean-dirs syntax
    kbuild: check clean srctree even earlier
    ...

    Linus Torvalds
     

30 Aug, 2019

3 commits

  • * for-next/atomics: (10 commits)
    Rework LSE instruction selection to use static keys instead of alternatives

    Will Deacon
     
  • …njection', 'for-next/perf', 'for-next/psci-cpuidle', 'for-next/rng', 'for-next/smpboot', 'for-next/tbi' and 'for-next/tlbi' into for-next/core

    * for-next/52-bit-kva: (25 commits)
    Support for 52-bit virtual addressing in kernel space

    * for-next/cpu-topology: (9 commits)
    Move CPU topology parsing into core code and add support for ACPI 6.3

    * for-next/error-injection: (2 commits)
    Support for function error injection via kprobes

    * for-next/perf: (8 commits)
    Support for i.MX8 DDR PMU and proper SMMUv3 group validation

    * for-next/psci-cpuidle: (7 commits)
    Move PSCI idle code into a new CPUidle driver

    * for-next/rng: (4 commits)
    Support for 'rng-seed' property being passed in the devicetree

    * for-next/smpboot: (3 commits)
    Reduce fragility of secondary CPU bringup in debug configurations

    * for-next/tbi: (10 commits)
    Introduce new syscall ABI with relaxed requirements for pointer tags

    * for-next/tlbi: (6 commits)
    Handle spurious page faults arising from kernel space

    Will Deacon
     
  • The 'K' constraint is a documented AArch64 machine constraint supported
    by GCC for matching integer constants that can be used with a 32-bit
    logical instruction. Unfortunately, some released compilers erroneously
    accept the immediate '4294967295' for this constraint, which is later
    refused by GAS at assembly time. This had led us to avoid the use of
    the 'K' constraint altogether.

    Instead, detect whether the compiler is up to the job when building the
    kernel and pass the 'K' constraint to our 32-bit atomic macros when it
    appears to be supported.

    Signed-off-by: Will Deacon

    Will Deacon