15 May, 2019

1 commit


10 May, 2019

1 commit

  • …morris/linux-security

    Pull intgrity updates from James Morris:
    "This contains just three patches, the remainder were either included
    in other pull requests (eg. audit, lockdown) or will be upstreamed via
    other subsystems (eg. kselftests, Power).

    Included here is one bug fix, one documentation update, and extending
    the x86 IMA arch policy rules to coordinate the different kernel
    module signature verification methods"

    * 'next-integrity' of git://git.kernel.org/pub/scm/linux/kernel/git/jmorris/linux-security:
    doc/kernel-parameters.txt: Deprecate ima_appraise_tcb
    x86/ima: add missing include
    x86/ima: require signed kernel modules

    Linus Torvalds
     

30 Apr, 2019

2 commits

  • Use new flag for handling freeing of special permissioned memory in vmalloc
    and remove places where memory was set RW before freeing which is no longer
    needed.

    Since freeing of VM_FLUSH_RESET_PERMS memory is not supported in an
    interrupt by vmalloc, the freeing of init sections is moved to a work
    queue. Instead of call_rcu it now uses synchronize_rcu() in the work
    queue.

    Lastly, there is now a WARN_ON in module_memfree since it should not be
    called in an interrupt with special memory as is required for
    VM_FLUSH_RESET_PERMS.

    Signed-off-by: Rick Edgecombe
    Signed-off-by: Peter Zijlstra (Intel)
    Cc:
    Cc:
    Cc:
    Cc:
    Cc:
    Cc:
    Cc:
    Cc: Andy Lutomirski
    Cc: Borislav Petkov
    Cc: Dave Hansen
    Cc: H. Peter Anvin
    Cc: Jessica Yu
    Cc: Linus Torvalds
    Cc: Nadav Amit
    Cc: Rik van Riel
    Cc: Steven Rostedt
    Cc: Thomas Gleixner
    Link: https://lkml.kernel.org/r/20190426001143.4983-18-namit@vmware.com
    Signed-off-by: Ingo Molnar

    Rick Edgecombe
     
  • When modules and BPF filters are loaded, there is a time window in
    which some memory is both writable and executable. An attacker that has
    already found another vulnerability (e.g., a dangling pointer) might be
    able to exploit this behavior to overwrite kernel code. Prevent having
    writable executable PTEs in this stage.

    In addition, avoiding having W+X mappings can also slightly simplify the
    patching of modules code on initialization (e.g., by alternatives and
    static-key), as would be done in the next patch. This was actually the
    main motivation for this patch.

    To avoid having W+X mappings, set them initially as RW (NX) and after
    they are set as RO set them as X as well. Setting them as executable is
    done as a separate step to avoid one core in which the old PTE is cached
    (hence writable), and another which sees the updated PTE (executable),
    which would break the W^X protection.

    Suggested-by: Thomas Gleixner
    Suggested-by: Andy Lutomirski
    Signed-off-by: Nadav Amit
    Signed-off-by: Rick Edgecombe
    Signed-off-by: Peter Zijlstra (Intel)
    Cc:
    Cc:
    Cc:
    Cc:
    Cc:
    Cc:
    Cc:
    Cc: Andy Lutomirski
    Cc: Borislav Petkov
    Cc: Dave Hansen
    Cc: H. Peter Anvin
    Cc: Jessica Yu
    Cc: Kees Cook
    Cc: Linus Torvalds
    Cc: Masami Hiramatsu
    Cc: Rik van Riel
    Link: https://lkml.kernel.org/r/20190426001143.4983-12-namit@vmware.com
    Signed-off-by: Ingo Molnar

    Nadav Amit
     

28 Mar, 2019

1 commit

  • When a module is loaded, its symbols' Elf_Sym information is stored
    in a symtab. Further, type information is also captured. Since
    Elf_Sym has no type field, historically the st_info field has been
    hijacked for storing type: st_info was overwritten.

    commit 5439c985c5a83a8419f762115afdf560ab72a452 ("module: Overwrite
    st_size instead of st_info") changes that practice, as its one-liner
    indicates. Unfortunately, this change overwrites symbol size,
    information that a tool like DTrace expects to find.

    Allocate a typetab array to store type information so that no Elf_Sym
    field needs to be overwritten.

    Fixes: 5439c985c5a8 ("module: Overwrite st_size instead of st_info")
    Signed-off-by: Eugene Loh
    Reviewed-by: Nick Alcock
    [jeyu: renamed typeoff -> typeoffs ]
    Signed-off-by: Jessica Yu

    Eugene Loh
     

27 Mar, 2019

1 commit

  • Have the IMA architecture specific policy require signed kernel modules
    on systems with secure boot mode enabled; and coordinate the different
    signature verification methods, so only one signature is required.

    Requiring appended kernel module signatures may be configured, enabled
    on the boot command line, or with this patch enabled in secure boot
    mode. This patch defines set_module_sig_enforced().

    To coordinate between appended kernel module signatures and IMA
    signatures, only define an IMA MODULE_CHECK policy rule if
    CONFIG_MODULE_SIG is not enabled. A custom IMA policy may still define
    and require an IMA signature.

    Signed-off-by: Mimi Zohar
    Reviewed-by: Luis Chamberlain
    Acked-by: Jessica Yu

    Mimi Zohar
     

08 Mar, 2019

2 commits

  • For symmetry with ddebug_remove_module, and to avoid a bit of ifdeffery
    in module.c, move the declaration of ddebug_add_module inside #if
    defined(CONFIG_DYNAMIC_DEBUG) and add a corresponding no-op stub in the
    #else branch.

    Link: http://lkml.kernel.org/r/20190212214150.4807-10-linux@rasmusvillemoes.dk
    Signed-off-by: Rasmus Villemoes
    Acked-by: Jason Baron
    Cc: David Sterba
    Cc: Greg Kroah-Hartman
    Cc: Ingo Molnar
    Cc: Petr Mladek
    Cc: "Rafael J . Wysocki"
    Cc: Steven Rostedt
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Rasmus Villemoes
     
  • This serves two purposes: First, we get a diagnostic if (though
    extremely unlikely), any of the calls of ddebug_add_module for built-in
    code fails, effectively disabling dynamic_debug. Second, I want to make
    struct _ddebug opaque, and avoid accessing any of its members outside
    dynamic_debug.[ch].

    Link: http://lkml.kernel.org/r/20190212214150.4807-9-linux@rasmusvillemoes.dk
    Signed-off-by: Rasmus Villemoes
    Acked-by: Jason Baron
    Cc: David Sterba
    Cc: Greg Kroah-Hartman
    Cc: Ingo Molnar
    Cc: Petr Mladek
    Cc: "Rafael J . Wysocki"
    Cc: Steven Rostedt
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Rasmus Villemoes
     

06 Jan, 2019

1 commit

  • Currently, CONFIG_JUMP_LABEL just means "I _want_ to use jump label".

    The jump label is controlled by HAVE_JUMP_LABEL, which is defined
    like this:

    #if defined(CC_HAVE_ASM_GOTO) && defined(CONFIG_JUMP_LABEL)
    # define HAVE_JUMP_LABEL
    #endif

    We can improve this by testing 'asm goto' support in Kconfig, then
    make JUMP_LABEL depend on CC_HAS_ASM_GOTO.

    Ugly #ifdef HAVE_JUMP_LABEL will go away, and CONFIG_JUMP_LABEL will
    match to the real kernel capability.

    Signed-off-by: Masahiro Yamada
    Acked-by: Michael Ellerman (powerpc)
    Tested-by: Sedat Dilek

    Masahiro Yamada
     

29 Dec, 2018

1 commit

  • Pull driver core updates from Greg KH:
    "Here is the "big" set of driver core patches for 4.21-rc1.

    It's not really big, just a number of small changes for some reported
    issues, some documentation updates to hopefully make it harder for
    people to abuse the driver model, and some other minor cleanups.

    All of these have been in linux-next for a while with no reported
    issues"

    * tag 'driver-core-4.21-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/driver-core:
    mm, memory_hotplug: update a comment in unregister_memory()
    component: convert to DEFINE_SHOW_ATTRIBUTE
    sysfs: Disable lockdep for driver bind/unbind files
    driver core: Add missing dev->bus->need_parent_lock checks
    kobject: return error code if writing /sys/.../uevent fails
    driver core: Move async_synchronize_full call
    driver core: platform: Respect return code of platform_device_register_full()
    kref/kobject: Improve documentation
    drivers/base/memory.c: Use DEVICE_ATTR_RO and friends
    driver core: Replace simple_strto{l,ul} by kstrtou{l,ul}
    kernfs: Improve kernfs_notify() poll notification latency
    kobject: Fix warnings in lib/kobject_uevent.c
    kobject: drop unnecessary cast "%llu" for u64
    driver core: fix comments for device_block_probing()
    driver core: Replace simple_strtol by kstrtoint

    Linus Torvalds
     

28 Dec, 2018

2 commits

  • Pull networking updates from David Miller:

    1) New ipset extensions for matching on destination MAC addresses, from
    Stefano Brivio.

    2) Add ipv4 ttl and tos, plus ipv6 flow label and hop limit offloads to
    nfp driver. From Stefano Brivio.

    3) Implement GRO for plain UDP sockets, from Paolo Abeni.

    4) Lots of work from Michał Mirosław to eliminate the VLAN_TAG_PRESENT
    bit so that we could support the entire vlan_tci value.

    5) Rework the IPSEC policy lookups to better optimize more usecases,
    from Florian Westphal.

    6) Infrastructure changes eliminating direct manipulation of SKB lists
    wherever possible, and to always use the appropriate SKB list
    helpers. This work is still ongoing...

    7) Lots of PHY driver and state machine improvements and
    simplifications, from Heiner Kallweit.

    8) Various TSO deferral refinements, from Eric Dumazet.

    9) Add ntuple filter support to aquantia driver, from Dmitry Bogdanov.

    10) Batch dropping of XDP packets in tuntap, from Jason Wang.

    11) Lots of cleanups and improvements to the r8169 driver from Heiner
    Kallweit, including support for ->xmit_more. This driver has been
    getting some much needed love since he started working on it.

    12) Lots of new forwarding selftests from Petr Machata.

    13) Enable VXLAN learning in mlxsw driver, from Ido Schimmel.

    14) Packed ring support for virtio, from Tiwei Bie.

    15) Add new Aquantia AQtion USB driver, from Dmitry Bezrukov.

    16) Add XDP support to dpaa2-eth driver, from Ioana Ciocoi Radulescu.

    17) Implement coalescing on TCP backlog queue, from Eric Dumazet.

    18) Implement carrier change in tun driver, from Nicolas Dichtel.

    19) Support msg_zerocopy in UDP, from Willem de Bruijn.

    20) Significantly improve garbage collection of neighbor objects when
    the table has many PERMANENT entries, from David Ahern.

    21) Remove egdev usage from nfp and mlx5, and remove the facility
    completely from the tree as it no longer has any users. From Oz
    Shlomo and others.

    22) Add a NETDEV_PRE_CHANGEADDR so that drivers can veto the change and
    therefore abort the operation before the commit phase (which is the
    NETDEV_CHANGEADDR event). From Petr Machata.

    23) Add indirect call wrappers to avoid retpoline overhead, and use them
    in the GRO code paths. From Paolo Abeni.

    24) Add support for netlink FDB get operations, from Roopa Prabhu.

    25) Support bloom filter in mlxsw driver, from Nir Dotan.

    26) Add SKB extension infrastructure. This consolidates the handling of
    the auxiliary SKB data used by IPSEC and bridge netfilter, and is
    designed to support the needs to MPTCP which could be integrated in
    the future.

    27) Lots of XDP TX optimizations in mlx5 from Tariq Toukan.

    * git://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next: (1845 commits)
    net: dccp: fix kernel crash on module load
    drivers/net: appletalk/cops: remove redundant if statement and mask
    bnx2x: Fix NULL pointer dereference in bnx2x_del_all_vlans() on some hw
    net/net_namespace: Check the return value of register_pernet_subsys()
    net/netlink_compat: Fix a missing check of nla_parse_nested
    ieee802154: lowpan_header_create check must check daddr
    net/mlx4_core: drop useless LIST_HEAD
    mlxsw: spectrum: drop useless LIST_HEAD
    net/mlx5e: drop useless LIST_HEAD
    iptunnel: Set tun_flags in the iptunnel_metadata_reply from src
    net/mlx5e: fix semicolon.cocci warnings
    staging: octeon: fix build failure with XFRM enabled
    net: Revert recent Spectre-v1 patches.
    can: af_can: Fix Spectre v1 vulnerability
    packet: validate address length if non-zero
    nfc: af_nfc: Fix Spectre v1 vulnerability
    phonet: af_phonet: Fix Spectre v1 vulnerability
    net: core: Fix Spectre v1 vulnerability
    net: minor cleanup in skb_ext_add()
    net: drop the unused helper skb_ext_get()
    ...

    Linus Torvalds
     
  • Pull modules updates from Jessica Yu:

    - Some modules-related kallsyms cleanups and a kallsyms fix for ARM.

    - Include keys from the secondary keyring in module signature
    verification.

    * tag 'modules-for-v4.21' of git://git.kernel.org/pub/scm/linux/kernel/git/jeyu/linux:
    ARM: module: Fix function kallsyms on Thumb-2
    module: Overwrite st_size instead of st_info
    module: make it clearer when we're handling kallsyms symbols vs exported symbols
    modsign: use all trusted keys to verify module signature

    Linus Torvalds
     

19 Dec, 2018

1 commit

  • Distributions build drivers as modules, including network and filesystem
    drivers which export numerous tracepoints. This enables
    bpf(BPF_RAW_TRACEPOINT_OPEN) to attach to those tracepoints.

    Signed-off-by: Matt Mullins
    Acked-by: Martin KaFai Lau
    Signed-off-by: Alexei Starovoitov

    Matt Mullins
     

15 Dec, 2018

2 commits

  • Thumb-2 functions have the lowest bit set in the symbol value in the
    symtab. When kallsyms are generated for the vmlinux, the kallsyms are
    generated from the output of nm, and nm clears the lowest bit.

    $ arm-linux-gnueabihf-readelf -a vmlinux | grep show_interrupts
    95947: 8015dc89 686 FUNC GLOBAL DEFAULT 2 show_interrupts
    $ arm-linux-gnueabihf-nm vmlinux | grep show_interrupts
    8015dc88 T show_interrupts
    $ cat /proc/kallsyms | grep show_interrupts
    8015dc88 T show_interrupts

    However, for modules, the kallsyms uses the values in the symbol table
    without modification, so for functions in modules, the lowest bit is set
    in kallsyms.

    $ arm-linux-gnueabihf-readelf -a drivers/net/tun.ko | grep tun_get_socket
    333: 00002d4d 36 FUNC GLOBAL DEFAULT 1 tun_get_socket
    $ arm-linux-gnueabihf-nm drivers/net/tun.ko | grep tun_get_socket
    00002d4c T tun_get_socket
    $ cat /proc/kallsyms | grep tun_get_socket
    7f802d4d t tun_get_socket [tun]

    Because of this, the symbol+offset of the crashing instruction shown in
    oopses is incorrect when the crash is in a module. For example, given a
    tun_get_socket which starts like this,

    00002d4c :
    2d4c: 6943 ldr r3, [r0, #20]
    2d4e: 4a07 ldr r2, [pc, #28]
    2d50: 4293 cmp r3, r2

    a crash when tun_get_socket is called with NULL results in:

    PC is at tun_xdp+0xa3/0xa4 [tun]
    pc : []

    As can be seen, the "PC is at" line reports the wrong symbol name, and
    the symbol+offset will point to the wrong source line if it is passed to
    gdb.

    To solve this, add a way for archs to fixup the reading of these module
    kallsyms values, and use that to clear the lowest bit for function
    symbols on Thumb-2.

    After the fix:

    # cat /proc/kallsyms | grep tun_get_socket
    7f802d4c t tun_get_socket [tun]

    PC is at tun_get_socket+0x0/0x24 [tun]
    pc : []

    Signed-off-by: Vincent Whitchurch
    Signed-off-by: Jessica Yu

    Vincent Whitchurch
     
  • st_info is currently overwritten after relocation and used to store the
    elf_type(). However, we're going to need it fix kallsyms on ARM's
    Thumb-2 kernels, so preserve st_info and overwrite the st_size field
    instead. st_size is neither used by the module core nor by any
    architecture.

    Reviewed-by: Miroslav Benes
    Reviewed-by: Dave Martin
    Signed-off-by: Vincent Whitchurch
    Signed-off-by: Jessica Yu

    Vincent Whitchurch
     

06 Dec, 2018

1 commit

  • Propagate error code back to userspace if writing the /sys/.../uevent
    file fails. Before, the write operation always returned with success,
    even if we failed to recognize the input string or if we failed to
    generate the uevent itself.

    With the error codes properly propagated back to userspace, we are
    able to react in userspace accordingly by not assuming and awaiting
    a uevent that is not delivered.

    Signed-off-by: Peter Rajnoha
    Signed-off-by: Greg Kroah-Hartman

    Peter Rajnoha
     

29 Nov, 2018

1 commit

  • The module loader internally works with both exported symbols
    represented as struct kernel_symbol, as well as Elf symbols from a
    module's symbol table. It's hard to distinguish sometimes which type of
    symbol we're handling given that some helper function names are not
    consistent or helpful. Take get_ksymbol() for instance - are we
    looking for an exported symbol or a kallsyms symbol here? Or symname()
    and kernel_symbol_name() - which function handles an exported symbol and
    which one an Elf symbol?

    Clean up and unify the function naming scheme a bit to make it clear
    which kind of symbol we're handling. This change only affects static
    functions internal to the module loader.

    Reviewed-by: Miroslav Benes
    Signed-off-by: Jessica Yu

    Jessica Yu
     

28 Nov, 2018

1 commit


27 Sep, 2018

1 commit

  • The __jump_table sections emitted into the core kernel and into
    each module consist of statically initialized references into
    other parts of the code, and with the exception of entries that
    point into init code, which are defused at post-init time, these
    data structures are never modified.

    So let's move them into the ro_after_init section, to prevent them
    from being corrupted inadvertently by buggy code, or deliberately
    by an attacker.

    Signed-off-by: Ard Biesheuvel
    Signed-off-by: Thomas Gleixner
    Reviewed-by: Kees Cook
    Acked-by: Jessica Yu
    Acked-by: Peter Zijlstra (Intel)
    Cc: linux-arm-kernel@lists.infradead.org
    Cc: linux-s390@vger.kernel.org
    Cc: Arnd Bergmann
    Cc: Heiko Carstens
    Cc: Will Deacon
    Cc: Catalin Marinas
    Cc: Steven Rostedt
    Cc: Martin Schwidefsky
    Link: https://lkml.kernel.org/r/20180919065144.25010-9-ard.biesheuvel@linaro.org

    Ard Biesheuvel
     

23 Aug, 2018

1 commit

  • An ordinary arm64 defconfig build has ~64 KB worth of __ksymtab entries,
    each consisting of two 64-bit fields containing absolute references, to
    the symbol itself and to a char array containing its name, respectively.

    When we build the same configuration with KASLR enabled, we end up with an
    additional ~192 KB of relocations in the .init section, i.e., one 24 byte
    entry for each absolute reference, which all need to be processed at boot
    time.

    Given how the struct kernel_symbol that describes each entry is completely
    local to module.c (except for the references emitted by EXPORT_SYMBOL()
    itself), we can easily modify it to contain two 32-bit relative references
    instead. This reduces the size of the __ksymtab section by 50% for all
    64-bit architectures, and gets rid of the runtime relocations entirely for
    architectures implementing KASLR, either via standard PIE linking (arm64)
    or using custom host tools (x86).

    Note that the binary search involving __ksymtab contents relies on each
    section being sorted by symbol name. This is implemented based on the
    input section names, not the names in the ksymtab entries, so this patch
    does not interfere with that.

    Given that the use of place-relative relocations requires support both in
    the toolchain and in the module loader, we cannot enable this feature for
    all architectures. So make it dependent on whether
    CONFIG_HAVE_ARCH_PREL32_RELOCATIONS is defined.

    Link: http://lkml.kernel.org/r/20180704083651.24360-4-ard.biesheuvel@linaro.org
    Signed-off-by: Ard Biesheuvel
    Acked-by: Jessica Yu
    Acked-by: Michael Ellerman
    Reviewed-by: Will Deacon
    Acked-by: Ingo Molnar
    Cc: Arnd Bergmann
    Cc: Benjamin Herrenschmidt
    Cc: Bjorn Helgaas
    Cc: Catalin Marinas
    Cc: James Morris
    Cc: James Morris
    Cc: Josh Poimboeuf
    Cc: Kees Cook
    Cc: Nicolas Pitre
    Cc: Paul Mackerras
    Cc: Petr Mladek
    Cc: Russell King
    Cc: "Serge E. Hallyn"
    Cc: Sergey Senozhatsky
    Cc: Steven Rostedt
    Cc: Thomas Garnier
    Cc: Thomas Gleixner
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Ard Biesheuvel
     

18 Aug, 2018

1 commit

  • Pull modules updates from Jessica Yu:
    "Summary of modules changes for the 4.19 merge window:

    - Fix modules kallsyms for livepatch. Livepatch modules can have
    SHN_UNDEF symbols in their module symbol tables for later symbol
    resolution, but kallsyms shouldn't be returning these symbols

    - Some code cleanups and minor reshuffling in load_module() were done
    to log the module name when module signature verification fails"

    * tag 'modules-for-v4.19' of git://git.kernel.org/pub/scm/linux/kernel/git/jeyu/linux:
    kernel/module: Use kmemdup to replace kmalloc+memcpy
    ARM: module: fix modsign build error
    modsign: log module name in the event of an error
    module: replace VMLINUX_SYMBOL_STR() with __stringify() or string literal
    module: print sensible error code
    module: setup load info before module_sig_check()
    module: make it clear when we're handling the module copy in info->hdr
    module: exclude SHN_UNDEF symbols from kallsyms api

    Linus Torvalds
     

03 Aug, 2018

1 commit


17 Jul, 2018

1 commit

  • Both the init_module and finit_module syscalls call either directly
    or indirectly the security_kernel_read_file LSM hook. This patch
    replaces the direct call in init_module with a call to the new
    security_kernel_load_data hook and makes the corresponding changes
    in SELinux, LoadPin, and IMA.

    Signed-off-by: Mimi Zohar
    Cc: Jeff Vander Stoep
    Cc: Casey Schaufler
    Cc: Kees Cook
    Acked-by: Jessica Yu
    Acked-by: Paul Moore
    Acked-by: Kees Cook
    Signed-off-by: James Morris

    Mimi Zohar
     

02 Jul, 2018

1 commit

  • Now that we have the load_info struct all initialized (including
    info->name, which contains the name of the module) before
    module_sig_check(), make the load_info struct and hence module name
    available to mod_verify_sig() so that we can log the module name in the
    event of an error.

    Signed-off-by: Jessica Yu

    Jessica Yu
     

25 Jun, 2018

2 commits


22 Jun, 2018

2 commits

  • We want to be able to log the module name in early error messages, such as
    when module signature verification fails. Previously, the module name is
    set in layout_and_allocate(), meaning that any error messages that happen
    before (such as those in module_sig_check()) won't be logged with a module
    name, which isn't terribly helpful.

    In order to do this, reshuffle the order in load_module() and set up
    load info earlier so that we can log the module name along with these
    error messages. This requires splitting rewrite_section_headers() out of
    setup_load_info().

    While we're at it, clean up and split up the operations done in
    layout_and_allocate(), setup_load_info(), and rewrite_section_headers()
    more cleanly so these functions only perform what their names suggest.

    Signed-off-by: Jessica Yu

    Jessica Yu
     
  • In load_module(), it's not always clear whether we're handling the
    temporary module copy in info->hdr (which is freed at the end of
    load_module()) or if we're handling the module already allocated and
    copied to it's final place. Adding an info->mod field and using it
    whenever we're handling the temporary copy makes that explicitly clear.

    Signed-off-by: Jessica Yu

    Jessica Yu
     

18 Jun, 2018

1 commit

  • Livepatch modules are special in that we preserve their entire symbol
    tables in order to be able to apply relocations after module load. The
    unwanted side effect of this is that undefined (SHN_UNDEF) symbols of
    livepatch modules are accessible via the kallsyms api and this can
    confuse symbol resolution in livepatch (klp_find_object_symbol()) and
    cause subtle bugs in livepatch.

    Have the module kallsyms api skip over SHN_UNDEF symbols. These symbols
    are usually not available for normal modules anyway as we cut down their
    symbol tables to just the core (non-undefined) symbols, so this should
    really just affect livepatch modules. Note that this patch doesn't
    affect the display of undefined symbols in /proc/kallsyms.

    Reported-by: Josh Poimboeuf
    Tested-by: Josh Poimboeuf
    Reviewed-by: Josh Poimboeuf
    Signed-off-by: Jessica Yu

    Jessica Yu
     

16 Jun, 2018

1 commit


07 Jun, 2018

2 commits

  • Pull overflow updates from Kees Cook:
    "This adds the new overflow checking helpers and adds them to the
    2-factor argument allocators. And this adds the saturating size
    helpers and does a treewide replacement for the struct_size() usage.
    Additionally this adds the overflow testing modules to make sure
    everything works.

    I'm still working on the treewide replacements for allocators with
    "simple" multiplied arguments:

    *alloc(a * b, ...) -> *alloc_array(a, b, ...)

    and

    *zalloc(a * b, ...) -> *calloc(a, b, ...)

    as well as the more complex cases, but that's separable from this
    portion of the series. I expect to have the rest sent before -rc1
    closes; there are a lot of messy cases to clean up.

    Summary:

    - Introduce arithmetic overflow test helper functions (Rasmus)

    - Use overflow helpers in 2-factor allocators (Kees, Rasmus)

    - Introduce overflow test module (Rasmus, Kees)

    - Introduce saturating size helper functions (Matthew, Kees)

    - Treewide use of struct_size() for allocators (Kees)"

    * tag 'overflow-v4.18-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/kees/linux:
    treewide: Use struct_size() for devm_kmalloc() and friends
    treewide: Use struct_size() for vmalloc()-family
    treewide: Use struct_size() for kmalloc()-family
    device: Use overflow helpers for devm_kmalloc()
    mm: Use overflow helpers in kvmalloc()
    mm: Use overflow helpers in kmalloc_array*()
    test_overflow: Add memory allocation overflow tests
    overflow.h: Add allocation size calculation helpers
    test_overflow: Report test failures
    test_overflow: macrofy some more, do more tests for free
    lib: add runtime test of check_*_overflow functions
    compiler.h: enable builtin overflow checkers and add fallback code

    Linus Torvalds
     
  • One of the more common cases of allocation size calculations is finding
    the size of a structure that has a zero-sized array at the end, along
    with memory for some number of elements for that array. For example:

    struct foo {
    int stuff;
    void *entry[];
    };

    instance = kmalloc(sizeof(struct foo) + sizeof(void *) * count, GFP_KERNEL);

    Instead of leaving these open-coded and prone to type mistakes, we can
    now use the new struct_size() helper:

    instance = kmalloc(struct_size(instance, entry, count), GFP_KERNEL);

    This patch makes the changes for kmalloc()-family (and kvmalloc()-family)
    uses. It was done via automatic conversion with manual review for the
    "CHECKME" non-standard cases noted below, using the following Coccinelle
    script:

    // pkey_cache = kmalloc(sizeof *pkey_cache + tprops->pkey_tbl_len *
    // sizeof *pkey_cache->table, GFP_KERNEL);
    @@
    identifier alloc =~ "kmalloc|kzalloc|kvmalloc|kvzalloc";
    expression GFP;
    identifier VAR, ELEMENT;
    expression COUNT;
    @@

    - alloc(sizeof(*VAR) + COUNT * sizeof(*VAR->ELEMENT), GFP)
    + alloc(struct_size(VAR, ELEMENT, COUNT), GFP)

    // mr = kzalloc(sizeof(*mr) + m * sizeof(mr->map[0]), GFP_KERNEL);
    @@
    identifier alloc =~ "kmalloc|kzalloc|kvmalloc|kvzalloc";
    expression GFP;
    identifier VAR, ELEMENT;
    expression COUNT;
    @@

    - alloc(sizeof(*VAR) + COUNT * sizeof(VAR->ELEMENT[0]), GFP)
    + alloc(struct_size(VAR, ELEMENT, COUNT), GFP)

    // Same pattern, but can't trivially locate the trailing element name,
    // or variable name.
    @@
    identifier alloc =~ "kmalloc|kzalloc|kvmalloc|kvzalloc";
    expression GFP;
    expression SOMETHING, COUNT, ELEMENT;
    @@

    - alloc(sizeof(SOMETHING) + COUNT * sizeof(ELEMENT), GFP)
    + alloc(CHECKME_struct_size(&SOMETHING, ELEMENT, COUNT), GFP)

    Signed-off-by: Kees Cook

    Kees Cook
     

12 May, 2018

1 commit

  • load_module() creates W+X mappings via __vmalloc_node_range() (from
    layout_and_allocate()->move_module()->module_alloc()) by using
    PAGE_KERNEL_EXEC. These mappings are later cleaned up via
    "call_rcu_sched(&freeinit->rcu, do_free_init)" from do_init_module().

    This is a problem because call_rcu_sched() queues work, which can be run
    after debug_checkwx() is run, resulting in a race condition. If hit,
    the race results in a nasty splat about insecure W+X mappings, which
    results in a poor user experience as these are not the mappings that
    debug_checkwx() is intended to catch.

    This issue is observed on multiple arm64 platforms, and has been
    artificially triggered on an x86 platform.

    Address the race by flushing the queued work before running the
    arch-defined mark_rodata_ro() which then calls debug_checkwx().

    Link: http://lkml.kernel.org/r/1525103946-29526-1-git-send-email-jhugo@codeaurora.org
    Fixes: e1a58320a38d ("x86/mm: Warn on W^X mappings")
    Signed-off-by: Jeffrey Hugo
    Reported-by: Timur Tabi
    Reported-by: Jan Glauber
    Acked-by: Kees Cook
    Acked-by: Ingo Molnar
    Acked-by: Will Deacon
    Acked-by: Laura Abbott
    Cc: Mark Rutland
    Cc: Ard Biesheuvel
    Cc: Catalin Marinas
    Cc: Stephen Smalley
    Cc: Thomas Gleixner
    Cc: Peter Zijlstra
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Jeffrey Hugo
     

19 Apr, 2018

1 commit

  • Reading file /proc/modules shows the correct address:
    [root@s35lp76 ~]# cat /proc/modules | egrep '^qeth_l2'
    qeth_l2 94208 1 - Live 0x000003ff80401000

    and reading file /sys/module/qeth_l2/sections/.text
    [root@s35lp76 ~]# cat /sys/module/qeth_l2/sections/.text
    0x0000000018ea8363
    displays a random address.

    This breaks the perf tool which uses this address on s390
    to calculate start of .text section in memory.

    Fix this by printing the correct (unhashed) address.

    Thanks to Jessica Yu for helping on this.

    Fixes: ef0010a30935 ("vsprintf: don't use 'restricted_pointer()' when not restricting")
    Cc: # v4.15+
    Suggested-by: Linus Torvalds
    Signed-off-by: Thomas Richter
    Cc: Jessica Yu
    Signed-off-by: Jessica Yu

    Thomas Richter
     

17 Apr, 2018

2 commits


03 Apr, 2018

1 commit

  • Pul removal of obsolete architecture ports from Arnd Bergmann:
    "This removes the entire architecture code for blackfin, cris, frv,
    m32r, metag, mn10300, score, and tile, including the associated device
    drivers.

    I have been working with the (former) maintainers for each one to
    ensure that my interpretation was right and the code is definitely
    unused in mainline kernels. Many had fond memories of working on the
    respective ports to start with and getting them included in upstream,
    but also saw no point in keeping the port alive without any users.

    In the end, it seems that while the eight architectures are extremely
    different, they all suffered the same fate: There was one company in
    charge of an SoC line, a CPU microarchitecture and a software
    ecosystem, which was more costly than licensing newer off-the-shelf
    CPU cores from a third party (typically ARM, MIPS, or RISC-V). It
    seems that all the SoC product lines are still around, but have not
    used the custom CPU architectures for several years at this point. In
    contrast, CPU instruction sets that remain popular and have actively
    maintained kernel ports tend to all be used across multiple licensees.

    [ See the new nds32 port merged in the previous commit for the next
    generation of "one company in charge of an SoC line, a CPU
    microarchitecture and a software ecosystem" - Linus ]

    The removal came out of a discussion that is now documented at
    https://lwn.net/Articles/748074/. Unlike the original plans, I'm not
    marking any ports as deprecated but remove them all at once after I
    made sure that they are all unused. Some architectures (notably tile,
    mn10300, and blackfin) are still being shipped in products with old
    kernels, but those products will never be updated to newer kernel
    releases.

    After this series, we still have a few architectures without mainline
    gcc support:

    - unicore32 and hexagon both have very outdated gcc releases, but the
    maintainers promised to work on providing something newer. At least
    in case of hexagon, this will only be llvm, not gcc.

    - openrisc, risc-v and nds32 are still in the process of finishing
    their support or getting it added to mainline gcc in the first
    place. They all have patched gcc-7.3 ports that work to some
    degree, but complete upstream support won't happen before gcc-8.1.
    Csky posted their first kernel patch set last week, their situation
    will be similar

    [ Palmer Dabbelt points out that RISC-V support is in mainline gcc
    since gcc-7, although gcc-7.3.0 is the recommended minimum - Linus ]"

    This really says it all:

    2498 files changed, 95 insertions(+), 467668 deletions(-)

    * tag 'arch-removal' of git://git.kernel.org/pub/scm/linux/kernel/git/arnd/asm-generic: (74 commits)
    MAINTAINERS: UNICORE32: Change email account
    staging: iio: remove iio-trig-bfin-timer driver
    tty: hvc: remove tile driver
    tty: remove bfin_jtag_comm and hvc_bfin_jtag drivers
    serial: remove tile uart driver
    serial: remove m32r_sio driver
    serial: remove blackfin drivers
    serial: remove cris/etrax uart drivers
    usb: Remove Blackfin references in USB support
    usb: isp1362: remove blackfin arch glue
    usb: musb: remove blackfin port
    usb: host: remove tilegx platform glue
    pwm: remove pwm-bfin driver
    i2c: remove bfin-twi driver
    spi: remove blackfin related host drivers
    watchdog: remove bfin_wdt driver
    can: remove bfin_can driver
    mmc: remove bfin_sdh driver
    input: misc: remove blackfin rotary driver
    input: keyboard: remove bf54x driver
    ...

    Linus Torvalds
     

16 Mar, 2018

1 commit

  • The CONFIG_MPU option was only defined on blackfin, and that architecture
    is now being removed, so the respective code can be simplified.

    A lot of other microcontrollers have an MPU, but I suspect that if we
    want to bring that support back, we'd do it differently anyway.

    Signed-off-by: Arnd Bergmann

    Arnd Bergmann
     

09 Mar, 2018

1 commit

  • otherwise kernel can oops later in seq_release() due to dereferencing null
    file->private_data which is only set if seq_open() succeeds.

    BUG: unable to handle kernel NULL pointer dereference at 0000000000000000
    IP: seq_release+0xc/0x30
    Call Trace:
    close_pdeo+0x37/0xd0
    proc_reg_release+0x5d/0x60
    __fput+0x9d/0x1d0
    ____fput+0x9/0x10
    task_work_run+0x75/0x90
    do_exit+0x252/0xa00
    do_group_exit+0x36/0xb0
    SyS_exit_group+0xf/0x10

    Fixes: 516fb7f2e73d ("/proc/module: use the same logic as /proc/kallsyms for address exposure")
    Cc: Jessica Yu
    Cc: Linus Torvalds
    Cc: stable@vger.kernel.org # 4.15+
    Signed-off-by: Leon Yu
    Signed-off-by: Jessica Yu

    Leon Yu
     

08 Feb, 2018

1 commit