24 Feb, 2020

3 commits

  • [ Upstream commit 708e0ada1916be765b7faa58854062f2bc620bbf ]

    In setup_load_info(), info->name (which contains the name of the module,
    mostly used for early logging purposes before the module gets set up)
    gets unconditionally assigned if .modinfo is missing despite the fact
    that there is an if (!info->name) check near the end of the function.
    Avoid assigning a placeholder string to info->name if .modinfo doesn't
    exist, so that we can fall back to info->mod->name later on.

    Fixes: 5fdc7db6448a ("module: setup load info before module_sig_check()")
    Reviewed-by: Miroslav Benes
    Signed-off-by: Jessica Yu
    Signed-off-by: Sasha Levin

    Jessica Yu
     
  • [ Upstream commit bf08949cc8b98b7d1e20cfbba169a5938d42dae8 ]

    While running kprobe module test, find_module_all() caused
    a suspicious RCU usage warning.

    -----
    =============================
    WARNING: suspicious RCU usage
    5.4.0-next-20191202+ #63 Not tainted
    -----------------------------
    kernel/module.c:619 RCU-list traversed in non-reader section!!

    other info that might help us debug this:

    rcu_scheduler_active = 2, debug_locks = 1
    1 lock held by rmmod/642:
    #0: ffffffff8227da80 (module_mutex){+.+.}, at: __x64_sys_delete_module+0x9a/0x230

    stack backtrace:
    CPU: 0 PID: 642 Comm: rmmod Not tainted 5.4.0-next-20191202+ #63
    Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS rel-1.12.1-0-ga5cab58e9a3f-prebuilt.qemu.org 04/01/2014
    Call Trace:
    dump_stack+0x71/0xa0
    find_module_all+0xc1/0xd0
    __x64_sys_delete_module+0xac/0x230
    ? do_syscall_64+0x12/0x1f0
    do_syscall_64+0x50/0x1f0
    entry_SYSCALL_64_after_hwframe+0x49/0xbe
    RIP: 0033:0x4b6d49
    -----

    This is because list_for_each_entry_rcu(modules) is called
    without rcu_read_lock(). This is safe because the module_mutex
    is locked.

    Pass lockdep_is_held(&module_mutex) to the list_for_each_entry_rcu()
    to suppress this warning, This also fixes similar issue in
    mod_find() and each_symbol_section().

    Signed-off-by: Masami Hiramatsu
    Signed-off-by: Jessica Yu
    Signed-off-by: Sasha Levin

    Masami Hiramatsu
     
  • [ Upstream commit f6d061d617124abbd55396a3bc37b9bf7d33233c ]

    In module_add_modinfo_attrs() if sysfs_create_file() fails
    on the first iteration of the loop (so i = 0), we forget to
    free the modinfo_attrs.

    Fixes: bc6f2a757d52 ("kernel/module: Fix mem leak in module_add_modinfo_attrs")
    Reviewed-by: Miroslav Benes
    Signed-off-by: YueHaibing
    Signed-off-by: Jessica Yu
    Signed-off-by: Sasha Levin

    YueHaibing
     

09 Jan, 2020

1 commit

  • commit 5d603311615f612320bb77bd2a82553ef1ced5b7 upstream.

    Fix the race between load and unload a kernel module.

    sys_delete_module()
    try_stop_module()
    mod->state = _GOING
    add_unformed_module()
    old = find_module_all()
    (old->state == _GOING =>
    wait_event_interruptible())

    During pre-condition
    finished_loading() rets 0
    schedule()
    (never gets waken up later)
    free_module()
    mod->state = _UNFORMED
    list_del_rcu(&mod->list)
    (dels mod from "modules" list)

    return

    The race above leads to modprobe hanging forever on loading
    a module.

    Error paths on loading module call wake_up_all(&module_wq) after
    freeing module, so let's do the same on straight module unload.

    Fixes: 6e6de3dee51a ("kernel/module.c: Only return -EEXIST for modules that have finished loading")
    Reviewed-by: Prarit Bhargava
    Signed-off-by: Konstantin Khorenko
    Signed-off-by: Jessica Yu
    Signed-off-by: Greg Kroah-Hartman

    Konstantin Khorenko
     

28 Sep, 2019

2 commits

  • Pull kernel lockdown mode from James Morris:
    "This is the latest iteration of the kernel lockdown patchset, from
    Matthew Garrett, David Howells and others.

    From the original description:

    This patchset introduces an optional kernel lockdown feature,
    intended to strengthen the boundary between UID 0 and the kernel.
    When enabled, various pieces of kernel functionality are restricted.
    Applications that rely on low-level access to either hardware or the
    kernel may cease working as a result - therefore this should not be
    enabled without appropriate evaluation beforehand.

    The majority of mainstream distributions have been carrying variants
    of this patchset for many years now, so there's value in providing a
    doesn't meet every distribution requirement, but gets us much closer
    to not requiring external patches.

    There are two major changes since this was last proposed for mainline:

    - Separating lockdown from EFI secure boot. Background discussion is
    covered here: https://lwn.net/Articles/751061/

    - Implementation as an LSM, with a default stackable lockdown LSM
    module. This allows the lockdown feature to be policy-driven,
    rather than encoding an implicit policy within the mechanism.

    The new locked_down LSM hook is provided to allow LSMs to make a
    policy decision around whether kernel functionality that would allow
    tampering with or examining the runtime state of the kernel should be
    permitted.

    The included lockdown LSM provides an implementation with a simple
    policy intended for general purpose use. This policy provides a coarse
    level of granularity, controllable via the kernel command line:

    lockdown={integrity|confidentiality}

    Enable the kernel lockdown feature. If set to integrity, kernel features
    that allow userland to modify the running kernel are disabled. If set to
    confidentiality, kernel features that allow userland to extract
    confidential information from the kernel are also disabled.

    This may also be controlled via /sys/kernel/security/lockdown and
    overriden by kernel configuration.

    New or existing LSMs may implement finer-grained controls of the
    lockdown features. Refer to the lockdown_reason documentation in
    include/linux/security.h for details.

    The lockdown feature has had signficant design feedback and review
    across many subsystems. This code has been in linux-next for some
    weeks, with a few fixes applied along the way.

    Stephen Rothwell noted that commit 9d1f8be5cf42 ("bpf: Restrict bpf
    when kernel lockdown is in confidentiality mode") is missing a
    Signed-off-by from its author. Matthew responded that he is providing
    this under category (c) of the DCO"

    * 'next-lockdown' of git://git.kernel.org/pub/scm/linux/kernel/git/jmorris/linux-security: (31 commits)
    kexec: Fix file verification on S390
    security: constify some arrays in lockdown LSM
    lockdown: Print current->comm in restriction messages
    efi: Restrict efivar_ssdt_load when the kernel is locked down
    tracefs: Restrict tracefs when the kernel is locked down
    debugfs: Restrict debugfs when the kernel is locked down
    kexec: Allow kexec_file() with appropriate IMA policy when locked down
    lockdown: Lock down perf when in confidentiality mode
    bpf: Restrict bpf when kernel lockdown is in confidentiality mode
    lockdown: Lock down tracing and perf kprobes when in confidentiality mode
    lockdown: Lock down /proc/kcore
    x86/mmiotrace: Lock down the testmmiotrace module
    lockdown: Lock down module params that specify hardware parameters (eg. ioport)
    lockdown: Lock down TIOCSSERIAL
    lockdown: Prohibit PCMCIA CIS storage when the kernel is locked down
    acpi: Disable ACPI table override if the kernel is locked down
    acpi: Ignore acpi_rsdp kernel param when the kernel has been locked down
    ACPI: Limit access to custom_method when the kernel is locked down
    x86/msr: Restrict MSR access when the kernel is locked down
    x86: Lock down IO port access when the kernel is locked down
    ...

    Linus Torvalds
     
  • Pull integrity updates from Mimi Zohar:
    "The major feature in this time is IMA support for measuring and
    appraising appended file signatures. In addition are a couple of bug
    fixes and code cleanup to use struct_size().

    In addition to the PE/COFF and IMA xattr signatures, the kexec kernel
    image may be signed with an appended signature, using the same
    scripts/sign-file tool that is used to sign kernel modules.

    Similarly, the initramfs may contain an appended signature.

    This contained a lot of refactoring of the existing appended signature
    verification code, so that IMA could retain the existing framework of
    calculating the file hash once, storing it in the IMA measurement list
    and extending the TPM, verifying the file's integrity based on a file
    hash or signature (eg. xattrs), and adding an audit record containing
    the file hash, all based on policy. (The IMA support for appended
    signatures patch set was posted and reviewed 11 times.)

    The support for appended signature paves the way for adding other
    signature verification methods, such as fs-verity, based on a single
    system-wide policy. The file hash used for verifying the signature and
    the signature, itself, can be included in the IMA measurement list"

    * 'next-integrity' of git://git.kernel.org/pub/scm/linux/kernel/git/zohar/linux-integrity:
    ima: ima_api: Use struct_size() in kzalloc()
    ima: use struct_size() in kzalloc()
    sefltest/ima: support appended signatures (modsig)
    ima: Fix use after free in ima_read_modsig()
    MODSIGN: make new include file self contained
    ima: fix freeing ongoing ahash_request
    ima: always return negative code for error
    ima: Store the measurement again when appraising a modsig
    ima: Define ima-modsig template
    ima: Collect modsig
    ima: Implement support for module-style appended signatures
    ima: Factor xattr_verify() out of ima_appraise_measurement()
    ima: Add modsig appraise_type option for module-style appended signatures
    integrity: Select CONFIG_KEYS instead of depending on it
    PKCS#7: Introduce pkcs7_get_digest()
    PKCS#7: Refactor verify_pkcs7_signature()
    MODSIGN: Export module signature definitions
    ima: initialize the "template" field with the default template

    Linus Torvalds
     

12 Sep, 2019

2 commits

  • You can pass opaque pointers directly.

    I also renamed 'va' and 'vb' into more meaningful arguments.

    Signed-off-by: Masahiro Yamada
    Signed-off-by: Jessica Yu

    Masahiro Yamada
     
  • Commit 8651ec01daed ("module: add support for symbol namespaces.")
    broke linking for arm64 defconfig:

    | lib/crypto/arc4.o: In function `__ksymtab_arc4_setkey':
    | arc4.c:(___ksymtab+arc4_setkey+0x8): undefined reference to `no symbol'
    | lib/crypto/arc4.o: In function `__ksymtab_arc4_crypt':
    | arc4.c:(___ksymtab+arc4_crypt+0x8): undefined reference to `no symbol'

    This is because the dummy initialisation of the 'namespace_offset' field
    in 'struct kernel_symbol' when using EXPORT_SYMBOL on architectures with
    support for PREL32 locations uses an offset from an absolute address (0)
    in an effort to trick 'offset_to_pointer' into behaving as a NOP,
    allowing non-namespaced symbols to be treated in the same way as those
    belonging to a namespace.

    Unfortunately, place-relative relocations require a symbol reference
    rather than an absolute value and, although x86 appears to get away with
    this due to placing the kernel text at the top of the address space, it
    almost certainly results in a runtime failure if the kernel is relocated
    dynamically as a result of KASLR.

    Rework 'namespace_offset' so that a value of 0, which cannot occur for a
    valid namespaced symbol, indicates that the corresponding symbol does
    not belong to a namespace.

    Cc: Matthias Maennich
    Cc: Jessica Yu
    Cc: Ard Biesheuvel
    Cc: Catalin Marinas
    Fixes: 8651ec01daed ("module: add support for symbol namespaces.")
    Reported-by: kbuild test robot
    Tested-by: Matthias Maennich
    Tested-by: Ard Biesheuvel
    Reviewed-by: Matthias Maennich
    Acked-by: Ard Biesheuvel
    Signed-off-by: Will Deacon
    Signed-off-by: Jessica Yu

    Will Deacon
     

10 Sep, 2019

3 commits

  • If MODULE_ALLOW_MISSING_NAMESPACE_IMPORTS is enabled (default=n), the
    requirement for modules to import all namespaces that are used by
    the module is relaxed.

    Enabling this option effectively allows (invalid) modules to be loaded
    while only a warning is emitted.

    Disabling this option keeps the enforcement at module loading time and
    loading is denied if the module's imports are not satisfactory.

    Reviewed-by: Martijn Coenen
    Reviewed-by: Greg Kroah-Hartman
    Signed-off-by: Matthias Maennich
    Signed-off-by: Jessica Yu

    Matthias Maennich
     
  • The EXPORT_SYMBOL_NS() and EXPORT_SYMBOL_NS_GPL() macros can be used to
    export a symbol to a specific namespace. There are no _GPL_FUTURE and
    _UNUSED variants because these are currently unused, and I'm not sure
    they are necessary.

    I didn't add EXPORT_SYMBOL_NS() for ASM exports; this patch sets the
    namespace of ASM exports to NULL by default. In case of relative
    references, it will be relocatable to NULL. If there's a need, this
    should be pretty easy to add.

    A module that wants to use a symbol exported to a namespace must add a
    MODULE_IMPORT_NS() statement to their module code; otherwise, modpost
    will complain when building the module, and the kernel module loader
    will emit an error and fail when loading the module.

    MODULE_IMPORT_NS() adds a modinfo tag 'import_ns' to the module. That
    tag can be observed by the modinfo command, modpost and kernel/module.c
    at the time of loading the module.

    The ELF symbols are renamed to include the namespace with an asm label;
    for example, symbol 'usb_stor_suspend' in namespace USB_STORAGE becomes
    'usb_stor_suspend.USB_STORAGE'. This allows modpost to do namespace
    checking, without having to go through all the effort of parsing ELF and
    relocation records just to get to the struct kernel_symbols.

    On x86_64 I saw no difference in binary size (compression), but at
    runtime this will require a word of memory per export to hold the
    namespace. An alternative could be to store namespaced symbols in their
    own section and use a separate 'struct namespaced_kernel_symbol' for
    that section, at the cost of making the module loader more complex.

    Co-developed-by: Martijn Coenen
    Signed-off-by: Martijn Coenen
    Reviewed-by: Greg Kroah-Hartman
    Signed-off-by: Matthias Maennich
    Signed-off-by: Jessica Yu

    Matthias Maennich
     
  • Similar to modpost's get_next_modinfo(), introduce get_next_modinfo() in
    kernel/module.c to acquire any further values associated with the same
    modinfo tag name. That is useful for any tags that have multiple
    occurrences (such as 'alias'), but is in particular introduced here as
    part of the symbol namespaces patch series to read the (potentially)
    multiple namespaces a module is importing.

    Reviewed-by: Joel Fernandes (Google)
    Reviewed-by: Martijn Coenen
    Reviewed-by: Greg Kroah-Hartman
    Signed-off-by: Matthias Maennich
    Signed-off-by: Jessica Yu

    Matthias Maennich
     

21 Aug, 2019

1 commit

  • We should keep the case of "#define debug_align(X) (X)" for all arches
    without CONFIG_HAS_STRICT_MODULE_RWX ability, which would save people, who
    are sensitive to system size, a lot of memory when using modules,
    especially for embedded systems. This is also the intention of the
    original #ifdef... statement and still valid for now.

    Note that this still keeps the effect of the fix of the following commit,
    38f054d549a8 ("modules: always page-align module section allocations"),
    since when CONFIG_ARCH_HAS_STRICT_MODULE_RWX is enabled, module pages are
    aligned.

    Signed-off-by: He Zhe
    Signed-off-by: Jessica Yu

    He Zhe
     

20 Aug, 2019

1 commit

  • If the kernel is locked down, require that all modules have valid
    signatures that we can verify.

    I have adjusted the errors generated:

    (1) If there's no signature (ENODATA) or we can't check it (ENOPKG,
    ENOKEY), then:

    (a) If signatures are enforced then EKEYREJECTED is returned.

    (b) If there's no signature or we can't check it, but the kernel is
    locked down then EPERM is returned (this is then consistent with
    other lockdown cases).

    (2) If the signature is unparseable (EBADMSG, EINVAL), the signature fails
    the check (EKEYREJECTED) or a system error occurs (eg. ENOMEM), we
    return the error we got.

    Note that the X.509 code doesn't check for key expiry as the RTC might not
    be valid or might not have been transferred to the kernel's clock yet.

    [Modified by Matthew Garrett to remove the IMA integration. This will
    be replaced with integration with the IMA architecture policy
    patchset.]

    Signed-off-by: David Howells
    Signed-off-by: Matthew Garrett
    Reviewed-by: Kees Cook
    Cc: Jessica Yu
    Signed-off-by: James Morris

    David Howells
     

06 Aug, 2019

1 commit

  • IMA will use the module_signature format for append signatures, so export
    the relevant definitions and factor out the code which verifies that the
    appended signature trailer is valid.

    Also, create a CONFIG_MODULE_SIG_FORMAT option so that IMA can select it
    and be able to use mod_check_sig() without having to depend on either
    CONFIG_MODULE_SIG or CONFIG_MODULES.

    s390 duplicated the definition of struct module_signature so now they can
    use the new header instead.

    Signed-off-by: Thiago Jung Bauermann
    Acked-by: Jessica Yu
    Reviewed-by: Philipp Rudo
    Cc: Heiko Carstens
    Signed-off-by: Mimi Zohar

    Thiago Jung Bauermann
     

30 Jul, 2019

1 commit

  • Some arches (e.g., arm64, x86) have moved towards non-executable
    module_alloc() allocations for security hardening reasons. That means
    that the module loader will need to set the text section of a module to
    executable, regardless of whether or not CONFIG_STRICT_MODULE_RWX is set.

    When CONFIG_STRICT_MODULE_RWX=y, module section allocations are always
    page-aligned to handle memory rwx permissions. On some arches with
    CONFIG_STRICT_MODULE_RWX=n however, when setting the module text to
    executable, the BUG_ON() in frob_text() gets triggered since module
    section allocations are not page-aligned when CONFIG_STRICT_MODULE_RWX=n.
    Since the set_memory_* API works with pages, and since we need to call
    set_memory_x() regardless of whether CONFIG_STRICT_MODULE_RWX is set, we
    might as well page-align all module section allocations for ease of
    managing rwx permissions of module sections (text, rodata, etc).

    Fixes: 2eef1399a866 ("modules: fix BUG when load module with rodata=n")
    Reported-by: Martin Kaiser
    Reported-by: Bartosz Golaszewski
    Tested-by: David Lechner
    Tested-by: Martin Kaiser
    Tested-by: Bartosz Golaszewski
    Signed-off-by: Jessica Yu

    Jessica Yu
     

19 Jul, 2019

1 commit

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

    - Code fixes and cleanups

    - Fix bug where set_memory_x() wasn't being called when rodata=n

    - Fix bug where -EEXIST was being returned for going modules

    - Allow arches to override module_exit_section()"

    * tag 'modules-for-v5.3' of git://git.kernel.org/pub/scm/linux/kernel/git/jeyu/linux:
    modules: fix compile error if don't have strict module rwx
    ARM: module: recognize unwind exit sections
    module: allow arch overrides for .exit section names
    modules: fix BUG when load module with rodata=n
    kernel/module: Fix mem leak in module_add_modinfo_attrs
    kernel: module: Use struct_size() helper
    kernel/module.c: Only return -EEXIST for modules that have finished loading

    Linus Torvalds
     

29 Jun, 2019

1 commit

  • …k/linux-rcu into core/rcu

    Pull rcu/next + tools/memory-model changes from Paul E. McKenney:

    - RCU flavor consolidation cleanups and optmizations
    - Documentation updates
    - Miscellaneous fixes
    - SRCU updates
    - RCU-sync flavor consolidation
    - Torture-test updates
    - Linux-kernel memory-consistency-model updates, most notably the addition of plain C-language accesses

    Signed-off-by: Ingo Molnar <mingo@kernel.org>

    Ingo Molnar
     

27 Jun, 2019

1 commit

  • If CONFIG_ARCH_HAS_STRICT_MODULE_RWX is not defined,
    we need stub for module_enable_nx() and module_enable_x().

    If CONFIG_ARCH_HAS_STRICT_MODULE_RWX is defined, but
    CONFIG_STRICT_MODULE_RWX is disabled, we need stub for
    module_enable_nx.

    Move frob_text() outside of the CONFIG_STRICT_MODULE_RWX,
    because it is needed anyway.

    Fixes: 2eef1399a866 ("modules: fix BUG when load module with rodata=n")
    Signed-off-by: Yang Yingliang
    Signed-off-by: Jessica Yu

    Yang Yingliang
     

24 Jun, 2019

2 commits

  • Some archs like ARM store unwind information for .exit.text in sections
    with unusual names. As this unwind information refers to .exit.text, it
    must not be loaded when .exit.text is not loaded (when CONFIG_MODULE_UNLOAD
    is unset); otherwise, loading a module can fail due to relocation failures.

    Signed-off-by: Matthias Schiffer
    Signed-off-by: Jessica Yu

    Matthias Schiffer
     
  • When loading a module with rodata=n, it causes an executing
    NX-protected page BUG.

    [ 32.379191] kernel tried to execute NX-protected page - exploit attempt? (uid: 0)
    [ 32.382917] BUG: unable to handle page fault for address: ffffffffc0005000
    [ 32.385947] #PF: supervisor instruction fetch in kernel mode
    [ 32.387662] #PF: error_code(0x0011) - permissions violation
    [ 32.389352] PGD 240c067 P4D 240c067 PUD 240e067 PMD 421a52067 PTE 8000000421a53063
    [ 32.391396] Oops: 0011 [#1] SMP PTI
    [ 32.392478] CPU: 7 PID: 2697 Comm: insmod Tainted: G O 5.2.0-rc5+ #202
    [ 32.394588] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS rel-1.12.1-0-ga5cab58e9a3f-prebuilt.qemu.org 04/01/2014
    [ 32.398157] RIP: 0010:ko_test_init+0x0/0x1000 [ko_test]
    [ 32.399662] Code: Bad RIP value.
    [ 32.400621] RSP: 0018:ffffc900029f3ca8 EFLAGS: 00010246
    [ 32.402171] RAX: 0000000000000000 RBX: 0000000000000000 RCX: 0000000000000000
    [ 32.404332] RDX: 00000000000004c7 RSI: 0000000000000cc0 RDI: ffffffffc0005000
    [ 32.406347] RBP: ffffffffc0005000 R08: ffff88842fbebc40 R09: ffffffff810ede4a
    [ 32.408392] R10: ffffea00108e3480 R11: 0000000000000000 R12: ffff88842bee21a0
    [ 32.410472] R13: 0000000000000001 R14: 0000000000000001 R15: ffffc900029f3e78
    [ 32.412609] FS: 00007fb4f0c0a700(0000) GS:ffff88842fbc0000(0000) knlGS:0000000000000000
    [ 32.414722] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
    [ 32.416290] CR2: ffffffffc0004fd6 CR3: 0000000421a90004 CR4: 0000000000020ee0
    [ 32.418471] Call Trace:
    [ 32.419136] do_one_initcall+0x41/0x1df
    [ 32.420199] ? _cond_resched+0x10/0x40
    [ 32.421433] ? kmem_cache_alloc_trace+0x36/0x160
    [ 32.422827] do_init_module+0x56/0x1f7
    [ 32.423946] load_module+0x1e67/0x2580
    [ 32.424947] ? __alloc_pages_nodemask+0x150/0x2c0
    [ 32.426413] ? map_vm_area+0x2d/0x40
    [ 32.427530] ? __vmalloc_node_range+0x1ef/0x260
    [ 32.428850] ? __do_sys_init_module+0x135/0x170
    [ 32.430060] ? _cond_resched+0x10/0x40
    [ 32.431249] __do_sys_init_module+0x135/0x170
    [ 32.432547] do_syscall_64+0x43/0x120
    [ 32.433853] entry_SYSCALL_64_after_hwframe+0x44/0xa9

    Because if rodata=n, set_memory_x() can't be called, fix this by
    calling set_memory_x in complete_formation();

    Fixes: f2c65fb3221a ("x86/modules: Avoid breaking W^X while loading modules")
    Suggested-by: Jian Cheng
    Reviewed-by: Nadav Amit
    Signed-off-by: Yang Yingliang
    Signed-off-by: Jessica Yu

    Yang Yingliang
     

14 Jun, 2019

1 commit


07 Jun, 2019

1 commit

  • 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 module_sect_attrs {
    ...
    struct module_sect_attr attrs[0];
    };

    Make use of the struct_size() helper instead of an open-coded version
    in order to avoid any potential type mistakes.

    So, replace the following form:

    sizeof(*sect_attrs) + nloaded * sizeof(sect_attrs->attrs[0]

    with:

    struct_size(sect_attrs, attrs, nloaded)

    This code was detected with the help of Coccinelle.

    Signed-off-by: Gustavo A. R. Silva
    Signed-off-by: Jessica Yu

    Gustavo A. R. Silva
     

05 Jun, 2019

1 commit

  • Microsoft HyperV disables the X86_FEATURE_SMCA bit on AMD systems, and
    linux guests boot with repeated errors:

    amd64_edac_mod: Unknown symbol amd_unregister_ecc_decoder (err -2)
    amd64_edac_mod: Unknown symbol amd_register_ecc_decoder (err -2)
    amd64_edac_mod: Unknown symbol amd_report_gart_errors (err -2)
    amd64_edac_mod: Unknown symbol amd_unregister_ecc_decoder (err -2)
    amd64_edac_mod: Unknown symbol amd_register_ecc_decoder (err -2)
    amd64_edac_mod: Unknown symbol amd_report_gart_errors (err -2)

    The warnings occur because the module code erroneously returns -EEXIST
    for modules that have failed to load and are in the process of being
    removed from the module list.

    module amd64_edac_mod has a dependency on module edac_mce_amd. Using
    modules.dep, systemd will load edac_mce_amd for every request of
    amd64_edac_mod. When the edac_mce_amd module loads, the module has
    state MODULE_STATE_UNFORMED and once the module load fails and the state
    becomes MODULE_STATE_GOING. Another request for edac_mce_amd module
    executes and add_unformed_module() will erroneously return -EEXIST even
    though the previous instance of edac_mce_amd has MODULE_STATE_GOING.
    Upon receiving -EEXIST, systemd attempts to load amd64_edac_mod, which
    fails because of unknown symbols from edac_mce_amd.

    add_unformed_module() must wait to return for any case other than
    MODULE_STATE_LIVE to prevent a race between multiple loads of
    dependent modules.

    Signed-off-by: Prarit Bhargava
    Signed-off-by: Barret Rhoden
    Cc: David Arcari
    Cc: Jessica Yu
    Cc: Heiko Carstens
    Signed-off-by: Jessica Yu

    Prarit Bhargava
     

31 May, 2019

1 commit

  • Based on 1 normalized pattern(s):

    this program is free software you can redistribute it and or modify
    it under the terms of the gnu general public license as published by
    the free software foundation either version 2 of the license or at
    your option any later version this program is distributed in the
    hope that it will be useful but without any warranty without even
    the implied warranty of merchantability or fitness for a particular
    purpose see the gnu general public license for more details you
    should have received a copy of the gnu general public license along
    with this program if not write to the free software foundation inc
    59 temple place suite 330 boston ma 02111 1307 usa

    extracted by the scancode license scanner the SPDX license identifier

    GPL-2.0-or-later

    has been chosen to replace the boilerplate/reference in 1334 file(s).

    Signed-off-by: Thomas Gleixner
    Reviewed-by: Allison Randal
    Reviewed-by: Richard Fontana
    Cc: linux-spdx@vger.kernel.org
    Link: https://lkml.kernel.org/r/20190527070033.113240726@linutronix.de
    Signed-off-by: Greg Kroah-Hartman

    Thomas Gleixner
     

29 May, 2019

1 commit

  • Adding DEFINE_SRCU() or DEFINE_STATIC_SRCU() to a loadable module requires
    that the size of the reserved region be increased, which is not something
    we want to be doing all that often. One approach would be to require
    that loadable modules define an srcu_struct and invoke init_srcu_struct()
    from their module_init function and cleanup_srcu_struct() from their
    module_exit function. However, this is more than a bit user unfriendly.

    This commit therefore creates an ___srcu_struct_ptrs linker section,
    and pointers to srcu_struct structures created by DEFINE_SRCU() and
    DEFINE_STATIC_SRCU() within a module are placed into that module's
    ___srcu_struct_ptrs section. The required init_srcu_struct() and
    cleanup_srcu_struct() functions are then automatically invoked as needed
    when that module is loaded and unloaded, thus allowing modules to continue
    to use DEFINE_SRCU() and DEFINE_STATIC_SRCU() while avoiding the need
    to increase the size of the reserved region.

    Many of the algorithms and some of the code was cheerfully cherry-picked
    from other code making use of linker sections, perhaps most notably from
    tracepoints. All bugs are nevertheless the sole property of the author.

    Suggested-by: Mathieu Desnoyers
    [ paulmck: Use __section() and use "default" in srcu_module_notify()'s
    "switch" statement as suggested by Joel Fernandes. ]
    Signed-off-by: Paul E. McKenney
    Tested-by: Joel Fernandes (Google)

    Paul E. McKenney
     

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